[英]Extract detected faces from image in opencv c++ for further processing
I am working on image processing in opencv to detect faces in an image and perform further processing on them.I am stuck at a point where i am trying to anlyze the detected faces in the image.I want to pass he detected area of the face to a new function and display only that part of the image but i am getting following error: Invalid argument:"Path Location Typeno match for 'operator=' (operand types are 'cv::Mat' and 'cv::Rect_')" aa.cpp /aa/src line 65 C/C++ Problem 我正在opencv中进行图像处理,以检测图像中的面部并对其进行进一步处理。我被困在试图分析图像中检测到的面部的位置。我想让他通过检测到的面部区域到新功能并仅显示图像的该部分,但出现以下错误:无效的参数:“路径位置类型与'operator ='不匹配(操作数类型为'cv :: Mat'和'cv :: Rect_') “ aa.cpp / aa / src第65行C / C ++问题
if possible please suggest me some solution. 如果可能的话,请建议我一些解决方案。 Thankyou 谢谢
#include "iostream"
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
void detectAndDisplay( Mat frame );
String face_cascade_name = "cascade.xml";
CascadeClassifier face_cascade;
int main( int argc, const char** argv )
{
Mat frame;
frame=imread("Images/img20140226195004.jpg");
if( !face_cascade.load( face_cascade_name ) )
{
printf("--(!)Error loading\n");
return -1;
}
if( !frame.empty() )
{
detectAndDisplay( frame );
}
return 0;
}
void totest(Mat img)
{
imshow("detected",img);
cvtColor(img,img,CV_RGB2GRAY);
cvCanny(img,img,20,100,3);
imshow("edged",img);
}
void detectAndDisplay( Mat frame )
{
std::vector<Rect> faces;
Mat frame_gray;
std::vector<Rect> fff;
cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 3, 0, Size(115,115) );
int x;
for( size_t i = 0; i < faces.size(); i++ )
{
x++;
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
Mat img;
img=faces[i];
totest(img);
}
imshow( "faces", frame );
waitKey();
}
The problem comes from this line: 问题来自此行:
img = faces[i];
^^^ ^^^^^^^^
| |
'Mat' 'Rect'
where you are trying to assign a cv::Rect
to a cv::Mat
. 您尝试将cv::Rect
分配给cv::Mat
。
To get the ROI region of the image, you should change it to something like: 要获取图像的ROI区域,应将其更改为以下内容:
img = frame(faces[i]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.