Reputation: 659
I am using opencv 2.4.2 and c++. I have a face image. From left of the picture, I want, with the least complexity, to determine the coordinate of one corner of the eye. My program will be as follows:
Face image input
Scan image from top until it encounters a kind of difference between the skin color and the first white pixel at the corner of the eye
Draw a kind of red dot at this corner
Does not continue scanning image
Displays the (x,y) coordinate at that point
What I have until now:
int main() {
Mat img = imread("MVC-003F.jpg");
for(int i = 0; i < img.rows; i++) {
for(int j = 0; j < img.cols; j++) {
Vec3b color = img.at<Vec3b>(Point(i,j));
if(color.val[0] == 255 && color.val[1] == 255 && color.val[2] == 255)
cout << (Point(i,j)) << endl;
}
}
imshow("out", img);
waitKey(0);
return 0;
}
Obviously,this does not solve my problem, but instead returns an error. After scanning the image, I am not able to determine whether I need to cvtColor
to HSV and threshold or continue with RGB.
Here is a picture of what I want to achieve (Red dot at corner of one eye):
Upvotes: 1
Views: 456
Reputation: 4525
I appreciate your aim at simplicity. White object color does not always result in white pixel and non-white color can turn into a white pixel due to specular reflections or overexposure. Your eye corner, by the way, has gray intensity 209, not 255. And very close to this intensity (at the value 200) there are some other pixels as shown in the image below. This means that relying on pixel intensities probably doesn't take you too far.
You mentioned a "kind of difference between the skin color and the first white pixel at the corner of the eye" but you did not measure the difference - you checked just one of the values. In fact you can check as many differences as you want, as in the filter below. Comparing differences may be a good approach that you can improve but looking at the differences in specific locations.
Just convolve your image with some pattern filter using matchTemplate() to find good areas for further analysis. For example, after convolution of your gray blurred image with the filter below (consists of 3 horizontal stripes: white, dark, white), I got this result where you can locate a vertical position of the eyes and even the mouth easily. To get more filters configurations look at this paper early Ada boost paper for face detection.
Upvotes: 1