I am working to improve the reponse time and i found that scipy.misc is taking around 1sec to load huge image files (1mb or more). Whereas cv2 performs best with 200ms or so,
Is it something that can be changed ? Just my 2 cents.
https://www.kaggle.com/zfturbo/test-speed-cv2-vs-scipy-vs-tensorflow
The reason I don't want to include cv2 is because it's a huge dependency that is hard to compile for a lot of people. That's a lot to require be installed just to load images. Also, cv2 stores images in a different pixel format, so you have to know to convert from BGR to RGB. It's a big pain for new users.
But if you know how to use cv2, you can just use it to load images instead in your programs. As long as you apply BGR->RGB conversion like in the examples, it should work fine. The only reason face_recognition even has a load_image_file() function is just to make it easy for new users to learn.
As far as a speed test, it's kind of weird to compare scipy vs. cv2 because scipy's imread() function is really just a wrapper around PIL or Pillow (depending on your version of Python). So you could get different results depending on how you have scipy installed and what version of PIL it is using.
When I have a minute, I will remove the scipy dependency and just use PIL/Pillow directly to read the images instead.
Thanks @ageitgey. Yes, you are right. its huge dependency just to read images. I haven't tried PIL though. i will try it. I have one doubt,
is the color conversion step necessary to in detect face / generating face landmarks? I tried without converting and it detected face. Isnt rgb/ bgr images work the same ? Please clear me on this point.
For newbies like me, please add below steps to read through cv2 and convert to rgb
img = cv2.imread(filename)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
Thank you
Just a update, when i use cv2 library, even after converting images to rgb, sometimes, face_locations are not identified with model=hog. However, they are identified with model="cnn" after long time to process the request
Even with PIL, sometimes, the faces are not identified.
It coud be the case that i am scaling images before finding the face_locations to 300x300 for faster processing times.
My image files sometimes have small faces and sometime big faces. For faster responses, i am scaling them to 300x300. But, sometimes faces go too small with this scale factor.
How to comeup with right scale factor without faces going unrecognized ?
If i identify faces without scaling, it is taking lot of time.
Any ideas ?
try train a filter to exclude no-face regions, then it helps.....
Hi Heermosi, Could you please elaborate ? I didnot get the idea. Isnt this same as identifiying face regions ? Any references/links ?
PIL is better than cv2. Load, scale times for both of them are more or less same.
PIL has thumbnail function which comes with the aspect ratio for perfect scaling and maintains default quality of 75. This will find faces accurately even for 300x300 shrinked images.
I tried to find a thumbnail function for cv2. But didnot find any.Because of manual scaling, sometimes, faces in pictures are not identified.
Dont know how PIL thumbnail is any different than me specifying the height, width in resize function while maintaining aspect ratio.
For far captures better to use high resolution camera.
Most helpful comment
The reason I don't want to include cv2 is because it's a huge dependency that is hard to compile for a lot of people. That's a lot to require be installed just to load images. Also, cv2 stores images in a different pixel format, so you have to know to convert from BGR to RGB. It's a big pain for new users.
But if you know how to use cv2, you can just use it to load images instead in your programs. As long as you apply BGR->RGB conversion like in the examples, it should work fine. The only reason face_recognition even has a load_image_file() function is just to make it easy for new users to learn.
As far as a speed test, it's kind of weird to compare scipy vs. cv2 because scipy's
imread()function is really just a wrapper around PIL or Pillow (depending on your version of Python). So you could get different results depending on how you have scipy installed and what version of PIL it is using.When I have a minute, I will remove the scipy dependency and just use PIL/Pillow directly to read the images instead.