Answer the question
In order to leave comments, you need to log in
How to deal with false positive results in OpenCV?
Guys, I'm trying to set up OpenCV so that I can find the right product in the photo. But I ran into the problem of false positives (supposedly shows the borders of the product in the place where it does not exist).
For example, there is such a photo of a mouse:
Based on it, I make my own haar cascade.
Then, using this code, I try to find the mouse in the photo:
import cv2
import sys
imagePath = sys.argv[1]
cascMouse = 'logitech_cascade.xml'
mouseCascade = cv2.CascadeClassifier(cascMouse)
# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
mouses = mouseCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(100, 100),
)
for (x, y, w, h) in mouses:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 255), 2)
cv2.imshow("Electronic items detector", image)
mouses = mouseCascade.detectMultiScale(
gray,
scaleFactor=1.5,
minNeighbors=10,
minSize=(100, 100),
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question