Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor difference of opencv wrapper from the original detector? #11

Open
grigorisg9gr opened this issue Dec 2, 2016 · 1 comment
Open

Comments

@grigorisg9gr
Copy link
Member

I noticed that there is a very minor difference in the number of detections if executing the wrapper and the original code.
The wrapper code seems to just call the opencv frontal detector xml files and call the respective code. One idea might be because of the opencv swapped channels, however I did not manage to make the number of detections match.

This is quite minor though, since it shows up in images with multiple people with quite adjusted hyperparams for the cascade, however I am not sure whether this entails any real change we need to do in the wrapper.

Example:

import cv2
from menpo.io import import_image
from menpodetect.opencv import load_opencv_frontal_face_detector
from menpodetect.opencv.conversion import opencv_frontal_face_path
from functools import partial 

p1 = ''

img = cv2.imread(p1 + 'test.jpg')
im = import_image(p1 + 'test.jpg')

# settings for the cascade (opencv multiscale one)
sc_f = 1.45
min_sz = (15, 15)
min_n = 2

sc_f = 1.02
min_sz = (15, 15)
min_n = 2

detector = partial(load_opencv_frontal_face_detector(), min_size=min_sz, 
                   min_neighbours=min_n , scale_factor=sc_f)
# ensure there are no prior landmarks.
for gr in im.landmarks.group_labels:
    del im.landmarks[gr]
detector(im)
print(len(im.landmarks.group_labels))


# Opencv code

faceCascade = cv2.CascadeClassifier(str(opencv_frontal_face_path))
faces = faceCascade.detectMultiScale(
    img,
    scaleFactor=sc_f,
    minNeighbors=min_n,
    minSize=min_sz,
    flags = cv2.CASCADE_SCALE_IMAGE
)

print("Found {0} faces!".format(len(faces)))

# grey version
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
    grey,
    scaleFactor=sc_f,
    minNeighbors=min_n,
    minSize=min_sz,
    flags = cv2.CASCADE_SCALE_IMAGE
)

print("Found {0} faces (grey)!".format(len(faces)))

In my pc and with either one of the settings above this results to a printing of 23 face detections from the wrapper and 21 from the original code.
The input image was:
test

@grigorisg9gr grigorisg9gr changed the title Difference of opencv wrapper from the original detector? Minor difference of opencv wrapper from the original detector? Dec 2, 2016
@patricksnape
Copy link
Contributor

Did you try flipping the channels to BGR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants