Dlib face detection doesn't work with grayscale images - c++

Do you know why dlib face detection doesn't work with grayscale images (python works pretty well with grayscale images)?
My code:
mFaceDetector = dlib::get_frontal_face_detector();
// image is opencv grayscale mat
dlib::array2d<unsigned char> img;
dlib::assign_image(img, dlib::cv_image<unsigned char>(image));
std::vector<dlib::rectangle> mRets = mFaceDetector(img);
How to make it work?

Your code is nothing wrong in my perspective. Mine is the same. You should check
The image is loaded correctly by using imshow() function
If it works with non-gray image and other image
If you are setting any scan_fhog_pyramid value to the detector
the mRets.size()

Related

OpenCV create YUV420 or grayscale Mat object from YUYV pixelformat video frame

I am trying to process video frames from a Qt application. The input from the QML Camera is of format YUYV and I could not set it to something else like YUV420 by default. I need to capture the frame and create a Mat object of YUV420 or grayscale format.
I have tried cvtColor with the following codes and they all crashed during runtime -
COLOR_YUV2GRAY_YVY
COLOR_YUV2RGB_YUYV
COLOR_YUV2GRAY_YUYV
Any idea how I can do this?
So after playing around with the color conversion codes a bit this is the solution I found to be working for me.
cv::Mat img = cv::Mat(m_videoHeight, m_videoWidth, CV_8UC2, input->bits());
cv::Mat gray;
cv::cvtColor(img, gray, cv::COLOR_YUV2GRAY_YVYU);
This converts the given YUYV Mat object - img to a grayscale Mat object - gray. input->bits() refers to the first bit of the video frame buffer.

Is there a SURF_CUDA implementation for colored images?

Recently started playing around with OpenCV, trying that SURF algorithm, that is really slow on CPU, and does not work with color images on GPU (has an assertion that checks for type==CV_8UC1), and converting images to grayscale gives some pretty bad results.
I'm wondering if there is a colored implementation on gpu in OpenCV, somewhere else, or if there is some kinda tricky workaround like doing the algorithm on all 3 channels and then magically merging them?
Thanks.
There's no special handling of color images in OpenCV's non-GPU version of SURF; the code shows that it just calls cvtColor(img, img, COLOR_BGR2GRAY) if it gets an image with more than one channel.
You might try converting the image to HSV and using one or more of the H, S, and/or V channels. More discussion at this question.

saving grayscale images as video in C++

In my code, there are created cv::Mat images whose format is CV_16UC1. I have a cv::VideoWriter object and insert created grayscale images into it. However, I have completely black video as a result. If I change the cv::Mat format to CV_8UC1 everything works as expected. Is there anything that I am missing?

using opencv in iOS

I want to firstly choose a picture from my the local library, it shows on the UIImageView
and then I can use the opencv fuction UIImageToMat() to convert the UIImage to Mat and then I convert Mat to IPlImage to implement image processing algorithms(why I have to convert Mat to IplImage? Because most of my opencv image processing codes are based on IplImage).
So the choosen image shows on the UIImageView, if I want to do some image processing things, I'll first convert the UIImage to IplImage, process it and then convert IplImage to UIImage again. That's the way I use opencv to do image processing things.
But the problem is when I want to process the chosen picture from the local library, something strange happens:
the original picture is:
and then I want to use opencv to let some columns of this picture to be blue and some rows to be red, but the result is:
the implementation code is:
I don't know why this happens, the picture obviously lost many important features during the opencv image processing process.(I just want some columns to be blue and some rows to be red.).Why this happened?

Bitmap to Iplimage conversion produce wrong color

i am trying to convert a bitmap to opencv image i am using pinvoke by sending the Bitmap.Scan0 and in the unmanaged side i am creating iplimage by using the byte array the solution is seems to work but not always ! only if i created the image on my pc using my grahpic device but it fails on another the image colors seems to be not right and the image is shifted i am suspecting that i should transfer the bitmap to DIB how can this done ?
IplImage* image= cvCreateImage(cvSize(width,height),depth,3)
memcpy(image->imageData,(uchar*)(bitmap),width*height*3);
IplImage stores pixels in the BGR order while HBITMAP expects them to be RGB.
Luckely, for you, the whole IplImage can be converted from BGR to RGB with:
cvCvtColor(image, image, CV_BGR2RGB);