焦南河 2022-11-12 20:09 采纳率: 0%
浏览 16
已结题

关于opencv中配置contrib环境并复现eigenfaces实验遇到的问题!(语言-c++)

vs2019配置opencv3.4.16+contrib后,运行代码出现提示框提示

Project1.exe -无法找到入口
×
无法定位程序输入点
?predict@FaceRecognizer@face@cv@@QEBAHAEBV_InputArray@debug_build_guard@3@@Z于动态链接库
C:lUsersVAdministratorlsourcelrepos\Project1x64\Debug\Project1.exe 上。

请问是我的代码问题吗?想知道怎么解决

我的解答思路和尝试过的方法

//源代码

#include<opencv2\opencv.hpp>
#include<opencv2\face.hpp>
using namespace cv;
using namespace face;
using namespace std;
char win_title[40] = {};

int main(int arc, char** argv) {
    namedWindow("input", CV_WINDOW_AUTOSIZE);



    //读入模型需要输入的数据,用来训练的图像vector<Mat>images和标签vector<int>labels
    string filename = string("at.txt");
    ifstream file(filename);
    if (!file) { printf("could not load file"); }
    vector<Mat>images;
    vector<int>labels;
    char separator = ';';
    string line, path, classlabel;
    while (getline(file, line)) {
        stringstream lines(line);
        getline(lines, path, separator);
        getline(lines, classlabel);
        //printf("%d\n", atoi(classlabel.c_str()));
        images.push_back(imread(path, 0));
        labels.push_back(atoi(classlabel.c_str()));//atoi(ASCLL to int)将字符串转换为整数型
    }
    int height = images[0].rows;
    int width = images[0].cols;
    printf("height:%d,width:%d\n", height, width);
    //将最后一个样本作为测试样本
    Mat testSample = images[images.size() - 1];
    int testLabel = labels[labels.size() - 1];
    //删除列表末尾的元素
    images.pop_back();
    labels.pop_back();

    //调用训练模块
    Ptr<BasicFaceRecognizer> model = EigenFaceRecognizer::create();
    model->train(images, labels);
    int predictedLabel = model->predict(testSample);
    printf("actual label:%d,predict label :%d\n", testLabel, predictedLabel);

    //计算特征值特征向量及平均值
    Mat vals = model->getEigenValues();//89*1
    printf("%d,%d\n", vals.rows, vals.cols);
    Mat vecs = model->getEigenVectors();//10324*89
    printf("%d,%d\n", vecs.rows, vecs.cols);
    Mat mean = model->getMean();//1*10304
    printf("%d,%d\n", mean.rows, mean.cols);

    //显示平均脸
    Mat meanFace = mean.reshape(1, height);//第一个参数为通道数,第二个参数为多少行
    normalize(meanFace, meanFace, 0, 255, NORM_MINMAX, CV_8UC1);
    imshow("Mean Face", meanFace);

    //重建人脸
    for (int i = min(10, vals.rows); i < min(61, vals.rows); i += 10) {
        Mat vecs_space = Mat(vecs, Range::all(), Range(0, i));
        Mat projection = LDA::subspaceProject(vecs_space, mean, images[0].reshape(1, 1));
        Mat reconstruction = LDA::subspaceReconstruct(vecs_space, mean, projection);
        Mat result = reconstruction.reshape(1, height);
        normalize(result, result, 0, 255, NORM_MINMAX, CV_8UC1);
        //char wintitle[40] = {};
        sprintf_s(win_title, "recon face %d", i);
        imshow(win_title, result);
    }

    waitKey(0);
    return 0;
}
  • 写回答

1条回答 默认 最新

  • 「已注销」 2022-11-14 16:50
    关注

    你把具体要求发给我,我可以为你试试

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月4日
  • 创建了问题 11月12日

悬赏问题

  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程