1

我正在使用 opencv 库编写代码,该库跟踪用户的面部和面部特征。我已经设法通过网络摄像头实时检测面部和眼睛、嘴唇等特征。我现在想从检测到的特征中提取情感。我想知道是否有任何可用的数据集可用于比较情绪以及如何完成情绪。

这是人脸检测的代码

    CvRect detectFaceInImage(const IplImage *inputImg, const CvHaarClassifierCascade* cascade )
{
    const CvSize minFeatureSize = cvSize(20, 20);
    const int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH;    // Only search for 1 face.
    const float search_scale_factor = 1.1f;
    IplImage *detectImg;
    IplImage *greyImg = 0;
    CvMemStorage* storage;
    CvRect rc;
    double t;
    CvSeq* rects;
    int i;

    storage = cvCreateMemStorage(0);
    cvClearMemStorage( storage );

    // If the image is color, use a greyscale copy of the image.
    detectImg = (IplImage*)inputImg;    // Assume the input image is to be used.
    if (inputImg->nChannels > 1) 
    {
        greyImg = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_8U, 1 );
        cvCvtColor( inputImg, greyImg, CV_BGR2GRAY );
        detectImg = greyImg;    // Use the greyscale version as the input.
    }

    // Detect all the faces.
    t = (double)cvGetTickCount();
    rects = cvHaarDetectObjects( detectImg, (CvHaarClassifierCascade*)cascade, storage,
                search_scale_factor, 3, flags, minFeatureSize );
    t = (double)cvGetTickCount() - t;
    printf("[Face Detection took %d ms and found %d objects]\n", cvRound( t/((double)cvGetTickFrequency()*1000.0) ), rects->total );

    // Get the first detected face (the biggest).
    if (rects->total > 0) {
        rc = *(CvRect*)cvGetSeqElem( rects, 0 );
    }
    else
        rc = cvRect(-1,-1,-1,-1);   // Couldn't find the face.

    //cvReleaseHaarClassifierCascade( &cascade );
    //cvReleaseImage( &detectImg );
    if (greyImg)
        cvReleaseImage( &greyImg );
    cvReleaseMemStorage( &storage );

    return rc;  // Return the biggest face found, or (-1,-1,-1,-1).
}
4

1 回答 1

6

我正在使用卡罗林斯卡定向情绪面孔 (KDEF) 照片进行教育研究项目。有关数据集的信息可在http://www.emotionlab.se/resources/kdef获得。

请注意,您可能需要对图像进行裁剪、调整大小、居中、拉直和规范化,以便将它们与 OpenCV 一起使用。一旦准备好,图像就可以很好地与所有 OpenCV2 FaceRecognizer 类函数配合使用。

至于如何进行面部表情识别:不存在标准方法。首先阅读 FaceRecognizer 文档并完成教程。对于它的价值:我发现使用局部二进制模式直方图可以产生最准确的结果。

于 2013-05-17T18:33:51.540 回答