基于opencv的人脸描述,用语言来描述输入脸的特征。建了对象,数据显示都是0。跪求大神急急急!!!

我写了一个类Facedescribe,在main函数里建了一个这个类的对象a,运行后得到的数据都是0;如果直接把Eye1_Eye2()和Faceheight( )放在main函数里,得到的输出数据eye1_eye2和faceheight正常。跪求大神建的这个类不对吗,类Facedescribe和main函数如下:
class Facedescribe{
private:
double eye1_eye2; //两眼瞳孔之间的距离
double facewidth; //脸宽
double faceheight; //脸长
double nosewidth; //鼻子宽度
double mouthwidth; //嘴巴宽度

public:
Facedescribe() :eye1_eye2(0), facewidth(0), faceheight(0), nosewidth(0), mouthwidth(0){ }
//定位瞳孔,求出两眼瞳孔之间的距离
double Eye1_Eye2()
{
eye1_eye2 = sqrt(pow(cvRound(landmarks[38 * 2 + 1]) - cvRound(landmarks[39 * 2 + 1]), 2) + pow(cvRound(landmarks[38 * 2]) - cvRound(landmarks[39 * 2]), 2));
cout << "eye1_eye2 = " << eye1_eye2 << endl;
return eye1_eye2;
}
double faceheightb = eye1_eye2 * 8;//脸长与眼宽的黄金比例

double Faceheight( )
{
double faceheight = sqrt(pow(cvRound(landmarks[6 * 2 + 1]) - cvRound(landmarks[14 * 2 + 1]), 2) + pow(cvRound(landmarks[6 * 2]) - cvRound(landmarks[14 * 2]), 2));
cout << "faceheight = " << faceheight << endl;
return faceheight;
}
bool Facemodel()
{
if (faceheight > faceheightb)
{
cout << "长脸" << endl;
return true;
}
else
{
cout << "不是长脸" << endl;
return false;
}
}
};

int main()
{
//const char* const path = "../data";

cv::Mat_<unsigned char> img(cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE));

if (!img.data)
{
    printf("Cannot load %s\n", path);
    exit(1);
}

int foundface;
float landmarks[2 * stasm_NLANDMARKS]; // x,y coords (note the 2)

if (!stasm_search_single(&foundface, landmarks,
    (const char*)img.data, img.cols, img.rows, path, "../data"))
{
    printf("Error in stasm_search_single: %s\n", stasm_lasterr());
    exit(1);
}

if (!foundface)
    printf("No face found in %s\n", path);
else
{
    // draw the landmarks on the image as white dots圆点 (image is monochrom单色的,黑白的)
    stasm_force_points_into_image(landmarks, img.cols, img.rows);
    for (int i = 0; i <stasm_NLANDMARKS; i++)
        img(cvRound(landmarks[i * 2 + 1]), cvRound(landmarks[i * 2])) = 255;    

}
cv::imwrite("minimal.bmp", img);
cv::imshow("stasm minimal", img);
cv::waitKey();
Facedescribe a;
a.Eye1_Eye2();
a.Faceheight();
a.Facemodel();
system("pause");
}

1个回答

建对象那儿是不是不对?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!