我正在使用opencv人臉檢測器在圖像中查找人臉。我試圖在矢量中存儲多個不同的面。看起來我多次存儲相同的內容。 這裏是我的代碼:將圖像存儲在mat矢量中
face_cascade.detectMultiScale(gray_image, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE);
Rect faceRect, eyeRect, temp;
//draw a rectangle for all found faces in the vector array on the original
image
cout<< faces.size()<<endl;
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);
rectangle(image, pt1, pt2, cvScalar(0, 255, 0, 0), 3, 8, 0);
//Create the cropped image
if(!faces.empty()){
faceRect = cvRect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
croppedFaceImage = gray_image(faceRect).clone();
resize(croppedFaceImage,resizedcroppedFaceImage,Size(60,60),0,0,INTER_LINEAR);
char k;
imshow("new", resizedcroppedFaceImage);
k = waitKey(0);
if (k== 'ESC') {destroyAllWindows();}
diFaces.push_back(resizedcroppedFaceImage);
}
else if(faces.empty())
{resize(gray_image,resizedcroppedFaceImage,Size(60,60),0,0,INTER_LINEAR); break;}
}
當我imshow resizedcroppedFaceImage一切正常,但是當我試圖imshow diFaces它讓我看到相同的圖像。有沒有關於push_back和存儲相同的圖像的任何解釋?
你怎麼知道'diFaces'存儲相同的圖像? – herohuyongtao
當我imshow(diFaces.at(0))和imshow(diFaces.at(1))時,我得到相同的圖像。我應該看到兩個不同的圖像。 –