Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C OpenCV
i want to detect an Eye, i have some code where i can detect blue color object, so if i made changes(how i can?) then it would be possible for me to detect an eye. as below color has its own specific range value so, if i specify the eye color HSV value then can i detect EYE with this method.
 
In this below code i am going to detect BLUE Color Object, please tell me that where i do changes in my code so that i could get EYE using Open CV.
     IplImage* GetThresholdedImage(IplImage* img)
    {
	// Convert the image into an HSV image
	IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
	cvCvtColor(img, imgHSV, CV_BGR2HSV);
 
	IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
      //For detecting BLUE color i have this HSV value, 
	 cvInRangeS(imgHSV, cvScalar(112, 100, 100), cvScalar(124, 255, 255), imgThreshed);//this will not recognize the yellow color
     cvReleaseImage(&imgHSV);
	  return imgThreshed;
}
Posted 20-Jan-13 1:13am
Edited 20-Jan-13 1:21am
v2
Comments
nv3 at 20-Jan-13 10:30am
   
Checking for a specific color value is not going to be very successful for eye detection. Remember, there are people with brown eyes, too!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Detecting Eye is moreover a template matching problem which can be done through cross correlation of a template image and main image.
 
Here is a simple method in OpenCV C for detecting eye.
 
locate_eye(IplImage* img, IplImage* tpl, CvRect* window, CvRect* eye)
{
	IplImage*	tm;
	CvRect		win;
	CvPoint		minloc, maxloc, point;
	double		minval, maxval;
	int			w, h;
 
	/* get the centroid of eye */
	point = cvPoint(
		(*eye).x + (*eye).width / 2, 
		(*eye).y + (*eye).height / 2
	);
 
	/* setup search window 
	   replace the predefined WIN_WIDTH and WIN_HEIGHT above 
	   for your convenient */
	win = cvRect(
		point.x - WIN_WIDTH / 2,
		point.y - WIN_HEIGHT / 2,
		WIN_WIDTH,
		WIN_HEIGHT
	);
 
	/* make sure that the search window is still within the frame */
	if (win.x < 0)
		win.x = 0;
	if (win.y < 0)
		win.y = 0;
	if (win.x + win.width > img->width)
		win.x = img->width - win.width;
	if (win.y + win.height > img->height)
		win.y = img->height - win.height;
 
	/* create new image for template matching result where: 
	   width  = W - w + 1, and
	   height = H - h + 1 */
	w  = win.width  - tpl->width  + 1;
	h  = win.height - tpl->height + 1;
	tm = cvCreateImage(cvSize(w, h), IPL_DEPTH_32F, 1);
 
	/* apply the search window */
	cvSetImageROI(img, win);
 
	/* template matching */
	cvMatchTemplate(img, tpl, tm, CV_TM_SQDIFF_NORMED);
	cvMinMaxLoc(tm, &minval, &maxval, &minloc, &maxloc, 0);
 
	/* release things */
	cvResetImageROI(img);
	cvReleaseImage(&tm);
 
	/* only good matches */
	if (minval > TM_THRESHOLD)
		return 0;
 
	/* return the search window */
	*window = win;
 
	/* return eye location */
	*eye = cvRect(
		win.x + minloc.x,
		win.y + minloc.y,
		TPL_WIDTH,
		TPL_HEIGHT
	);
 
	return 1;
}
 
where img is the main frame image, tpl is the template image whose size must be very small in comparison to the main frame, eye is rectangle defining eye template, window is the rectangle defining main frame. You can modify the method and parameters as par your requirements.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100