1 | initial version |
You are using 'haarcascades_eye_tree_eyeglasses.xml' which returns information of individual eyes. SInce, images cannot be round, you cannot save the individual eyes in circular form. But, you can extract the individual eyes as you did for extracting face. For this you can use eyes[j].x , eyes[j].y, eyes[j].width and eyes[j].height to extract rectangular part of eyes. Once you have the extracted part of eyes, you can use imwrite() to save it using the name you would like to assign.
char filename[120];
while(1) {
capture>>capimg;
cvtColor(capimg, greyimg, CV_BGR2GRAY);
cv::equalizeHist(greyimg,greyimg);
face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
for(int i=0; i < faces.size(); i++)
{
Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
Point pt2(faces[i].x,faces[i].y);
Mat faceroi=greyimg(faces[i]);
imshow("faceRegion",faceroi);
waitKey(10000);
eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
cout<<eyes.size()<<endl;
for(size_t j=0; j<eyes.size(); j++)
{
Mat eyeRoi=faceroi(eyes[j]);
sprintf(filename,"eye_%d.jpg",j);
bool write_success = imwrite(filename, eyeRoi);
}
rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
}
imshow("Result",capimg);
waitKey(1000);
return 0;}
Alternatively, you can also use haarcascade_mcs_eyepair_big_xml to extract information about both eyes together.
2 | No.2 Revision |
You are using 'haarcascades_eye_tree_eyeglasses.xml' which returns information of individual eyes. SInce, images cannot be round, you cannot save the individual eyes in circular form. But, you can extract the individual eyes as you did for extracting face. For this you can use eyes[j].x , eyes[j].y, eyes[j].width and eyes[j].height to extract rectangular part of eyes. Once you have the extracted part of eyes, you can use imwrite() to save it using the name you would like to assign.assign as shown below
char filename[120];
while(1)
{
{
capture>>capimg;
cvtColor(capimg, greyimg, CV_BGR2GRAY);
cv::equalizeHist(greyimg,greyimg);
face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
for(int i=0; i < faces.size(); i++)
{
Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
Point pt2(faces[i].x,faces[i].y);
Mat faceroi=greyimg(faces[i]);
imshow("faceRegion",faceroi);
waitKey(10000);
eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
cout<<eyes.size()<<endl;
for(size_t j=0; j<eyes.size(); j++)
{
Mat eyeRoi=faceroi(eyes[j]);
sprintf(filename,"eye_%d.jpg",j);
bool write_success = imwrite(filename, eyeRoi);
}
rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
}
imshow("Result",capimg);
waitKey(1000);
return 0;}
Alternatively, you can also use haarcascade_mcs_eyepair_big_xml to extract information about both eyes together.
3 | No.3 Revision |
You are using 'haarcascades_eye_tree_eyeglasses.xml' which returns information of individual eyes. SInce, images cannot be round, you cannot save the individual eyes in circular form. But, you can extract the individual eyes as you did for extracting face. For this you can use eyes[j].x , eyes[j].y, eyes[j].width and eyes[j].height to extract rectangular part of eyes. Once you have the extracted part of eyes, you can use imwrite() to save it using the name you would like to assign as shown below
char filename[120]; while(1) { capture>>capimg; cvtColor(capimg, greyimg, CV_BGR2GRAY); cv::equalizeHist(greyimg,greyimg); face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300)); for(int i=0; i < faces.size(); i++) { Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height); Point pt2(faces[i].x,faces[i].y); Mat faceroi=greyimg(faces[i]); imshow("faceRegion",faceroi); waitKey(10000); eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30)); cout<<eyes.size()<<endl; for(size_t j=0; j<eyes.size(); j++) { Mat eyeRoi=faceroi(eyes[j]); sprintf(filename,"eye_%d.jpg",j); bool write_success = imwrite(filename, eyeRoi); } rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0); } imshow("Result",capimg); waitKey(1000); return 0;}
Alternatively, you can also use haarcascade_mcs_eyepair_big_xml to extract information about both eyes together.