Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
OpenCV如何从图像中获取人脸的宽度和高度_Opencv_Face Recognition - Fatal编程技术网

OpenCV如何从图像中获取人脸的宽度和高度

OpenCV如何从图像中获取人脸的宽度和高度,opencv,face-recognition,Opencv,Face Recognition,嗨,我有一大组从视频中提取的人脸图像。我想简单地测量图像中每个人脸的宽度和高度。当我使用HAAR分类器时,它返回检测到的方形人脸,无论人脸有多胖或多瘦 虽然我对第一步很满意,但还是有一些改进是理想的 作为最低要求,我正在寻找一些例子来测量图像中检测到的人脸的宽度和高度。 理想情况下,首先将这些面向前旋转,以测量实际人脸的宽度和高度,而不是潜在旋转人脸的像素宽度 非常感谢示例代码。下面是人脸检测。下面两行将打印检测到的人脸的宽度和高度 在“detectAndDisplay”的第一个for循环中添加

嗨,我有一大组从视频中提取的人脸图像。我想简单地测量图像中每个人脸的宽度和高度。当我使用HAAR分类器时,它返回检测到的方形人脸,无论人脸有多胖或多瘦

虽然我对第一步很满意,但还是有一些改进是理想的

作为最低要求,我正在寻找一些例子来测量图像中检测到的人脸的宽度和高度。 理想情况下,首先将这些面向前旋转,以测量实际人脸的宽度和高度,而不是潜在旋转人脸的像素宽度


非常感谢示例代码。

下面是人脸检测。下面两行将打印检测到的人脸的宽度和高度

“detectAndDisplay”
的第一个for循环中添加两行

cout << "face width = " << faces[i].width << endl;
cout << "face Height = " << faces[i].height << endl;

这难道不是总能给你带来一个平易近人的结果吗?我需要从脸的边到边,从上到下巴。您可以修改此代码以满足您的要求。不要指望别人用勺子喂你
#include "opencv2/objdetect/objdetect.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/imgproc/imgproc.hpp"

 #include <iostream>
 #include <stdio.h>

 using namespace std;
 using namespace cv;

 /** Function Headers */
 void detectAndDisplay( Mat frame );

 /** Global variables */
 String face_cascade_name = "haarcascade_frontalface_alt.xml";
 CascadeClassifier face_cascade;
 string window_name = "Capture - Face detection";
 RNG rng(12345);

 /** @function main */
 int main( int argc, const char** argv )
 {
   CvCapture* capture;
   Mat frame = imread ( "C:\\Desktop\\1.jpg" );

   //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };


   //-- 3. Apply the classifier to the frame
       if( !frame.empty() )
       { detectAndDisplay( frame ); }
       else
       { printf(" --(!) No captured frame -- Break!"); }

   return 0;    

   }



/** @function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
  std::vector<Rect> faces;
  Mat frame_gray;

  cvtColor( frame, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );

  //-- Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

  for( int i = 0; i < faces.size(); i++ )
  {
    cv :: rectangle ( frame, faces[i], Scalar( 255, 0, 255 ), 4 );
    cout << "face width = " << faces[i].width << endl;
    cout << "face Height = " << faces[i].height << endl;

  }
  //-- Show what you got
  imshow( window_name, frame );

  waitKey( 0 );
 }