Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用opencv C+确定面方向+;_C++_Opencv_Face Detection - Fatal编程技术网

C++ 使用opencv C+确定面方向+;

C++ 使用opencv C+确定面方向+;,c++,opencv,face-detection,C++,Opencv,Face Detection,我目前正在进行人脸检测,然后是眼睛、嘴巴、鼻子和其他面部特征。对于上述检测,我使用了haarcascade(正面人脸、眼睛、右耳、左耳和嘴巴)。现在,如果人脸是正面的和笔直的,那么一切都能正常工作。但是如果我的脸是在侧视图中或者是旋转的,我并没有得到好的结果。对于侧视图,我使用了lbscade_profile.xml(它只适用于面部右侧)。但对于旋转的脸,我无法检测到脸。有人能在上面的上下文中帮助我吗?我在这里添加代码以便更好地理解。 注:提前谢谢,请原谅我的幼稚问题(可能是因为我对编程非常陌生

我目前正在进行人脸检测,然后是眼睛、嘴巴、鼻子和其他面部特征。对于上述检测,我使用了haarcascade(正面人脸、眼睛、右耳、左耳和嘴巴)。现在,如果人脸是正面的和笔直的,那么一切都能正常工作。但是如果我的脸是在侧视图中或者是旋转的,我并没有得到好的结果。对于侧视图,我使用了lbscade_profile.xml(它只适用于面部右侧)。但对于旋转的脸,我无法检测到脸。有人能在上面的上下文中帮助我吗?我在这里添加代码以便更好地理解。 注:提前谢谢,请原谅我的幼稚问题(可能是因为我对编程非常陌生)

void检测和显示(垫架)
{
//创建向量数组以存储找到的面
向量面;
垫子框架为灰色;
bool mirror_image=false;
//将帧图像转换为灰度图像文件
CVT颜色(框架、框架灰、CV灰);
//均衡灰度图像文件
均衡器历史(帧灰,帧灰);
//找到正面并将其存储在矢量阵列中
面_级联1.检测多尺度(帧_灰度,
面孔,
1.1, 2,
0 | CV | HAAR |缩放|图像| CV | HAAR |查找|最大|对象,
尺寸(40,40),
大小(200200);
//找到右侧面并将其存储在面向量中
如果(!(faces.size()))
{
轮廓面层叠。检测多尺度(帧灰,
面孔,
1.2, 3,
0 | CV | HAAR |缩放|图像| CV | HAAR |查找|最大|对象,
尺寸(40,40),
大小(200200);
}
//通过翻转帧并检查lbsprofile来查找左侧面是否存在
如果(!faces.size())
{
cv::翻转(帧灰,帧灰,1);
轮廓面层叠。检测多尺度(帧灰,
面孔,
1.2, 3,
0 | CV | HAAR |缩放|图像| CV | HAAR |查找|最大|对象,
尺寸(40,40),
大小(200200);
镜像=真;
}
//如果框架未翻转,则可以直接将其绘制到框架中
if(镜像图像和面.size())
{
//翻转框架
cv::翻转(帧灰,帧灰,1);
}
if(faces.size())
{
//为检测到的面绘制矩形
矩形(框,面[0],标量(0,255,0,0),1,8,0);
}
//检查框架中是否存在任何面
其他的
未找到图像++;
imshow(“人脸检测”,帧);
}

将是你的朋友,那么!我最近经常使用它,结果证明它在头部姿势估计方面是一个成功的工具,特别是在检测“旋转”的脸方面。它的角度范围相当合理:倾斜(围绕平行于图像宽度的轴旋转)从-30度到+30度,平移(围绕平行于图像高度的轴旋转)从-45度到+45度。它也是一个健壮的解决方案

在我看来,这太宽泛了。你表现得毫不努力,似乎在问代码。目前,您似乎希望有人为您编写一段通用代码。也许你可以用一个简单具体的例子来描述你的问题。显然,弗兰德马克已经被克兰德马克取代了。看起来确实如此,但快速谷歌搜索给了我这似乎是一些资源,虽然我还没有详细检查。
void detectAndDisplay( Mat frame)
{


// create a vector array to store the face found
std::vector<Rect> faces;

Mat frame_gray;
bool mirror_image = false;    
// convert the frame image into gray image file 
cvtColor( frame, frame_gray, CV_BGR2GRAY);
//equalize the gray image file
equalizeHist( frame_gray, frame_gray);

//find the frontal faces and store them in vector array 
face_cascade1.detectMultiScale(frame_gray,
                               faces,
                               1.1, 2,
                               0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT,
                               Size(40, 40),
                               Size(200, 200));

// find the right side face and store that in the face vector 
if(!(faces.size()))
{
    profileface_cascade.detectMultiScale( frame_gray,
                                          faces,
                                          1.2, 3,
                                          0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT,
                                          Size(40, 40),
                                          Size(200, 200));
}

// find whether left face exist or not by flipping the frame and checking through lbsprofile 
if(!faces.size())
{
    cv::flip(frame_gray, frame_gray, 1);
    profileface_cascade.detectMultiScale( frame_gray,
                                          faces,
                                          1.2, 3,
                                          0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT,
                                          Size(40, 40),
                                          Size(200, 200));
    mirror_image = true;
}

// if the frame is not flipped then the it could be directly drawn into frame
if(mirror_image and faces.size())
{
    // flip the frame
    cv::flip(frame_gray, frame_gray, 1);
}

if(faces.size())
{
    //draw rectangle for the faces detected 
    rectangle(frame, faces[0], cvScalar(0, 255, 0, 0), 1, 8, 0);

}

// check whether any face is present in frame or not 
else
    image_not_found++;

imshow("Face Detection", frame);
}