为什么我无法在Open CV中正确显示矩形?

地亚哥

我正在使用Open CV测试已经很经典的人脸检测代码,将人放在的vectorRect所以我想让获得Rects的图像显示在图像上。

while (true) {

    camera >> cameraFrame;
    if (cameraFrame.empty ()) {

        cerr << "Error: Could grab any frame!" << endl;
        exit(2);
    }

    imshow("Hola mundo", cameraFrame);
    cameraFrame = shrinkImage(turn2Gray(cameraFrame));
    imshow("Hola mundo gris", cameraFrame);
    equalizeHist(cameraFrame, equalizedImage);
    imshow("Hola mundo surreal y perturbador", equalizedImage);

    int flags = CASCADE_SCALE_IMAGE;
    Size minFeatureSize(20,20);
    float searchScaleFactor = 1.1f;
    int minNeighbors = 4;

    std::vector<Rect> faces;

    faceDetector.detectMultiScale(equalizedImage, faces, searchScaleFactor, minNeighbors, flags, minFeatureSize);
    cout << "Caras: " << faces.size() << endl;

    for (i=0; i< (int) faces.size(); i++) {

        rectangle( equalizedImage, faces[i], CV_RGB(0,255,0), 2, 8, 0 );

    }

    if (waitKey(20) == 27) {

    }

}

我从来没有显示任何矩形。我的rectangle()功能出了什么问题

我进行了建议的编辑,这就是现在的检测周期:

while (true) {

        camera >> cameraFrame;
        if (cameraFrame.empty ()) {

            cerr << "Error: Could grab any frame!" << endl;
            exit(2);
        }

        imshow("Hola mundo", cameraFrame);
        greyFrame = shrinkImage(turn2Gray(cameraFrame));
        imshow("Hola mundo gris", greyFrame);
        equalizeHist(greyFrame, equalizedImage);
        imshow("Hola mundo surreal y perturbador", equalizedImage);



        faceDetector.detectMultiScale(equalizedImage, faces, searchScaleFactor, minNeighbors, flags, minFeatureSize);
        cout << "Caras: " << faces.size() << endl;

        for (i=0; i < faces.size(); i++) {

            rectangle( cameraFrame, faces[i], CV_RGB(0,255,0), 2, 8, 0 );

        }
        imshow("Hola Diego", cameraFrame);

        if (waitKey(20) == 27) {
            break;
        }

    }

您正在尝试将rgb颜色绘制到灰度img上,也需要在矩形绘制之后执行imshow(),然后再执行waitKey()来更新窗口

尝试:

Mat greyFrame = shrinkImage(turn2Gray(cameraFrame)); // make a new grey mat, keep the original for drawing later
imshow("Hola mundo gris", greyFrame);
equalizeHist(greyFrame, equalizedImage);
imshow("Hola mundo surreal y perturbador", equalizedImage);

// ...

for (i=0; i< (int) faces.size(); i++) {
    rectangle( cameraFrame, faces[i], CV_RGB(0,255,0), 2, 8, 0 );
}

imshow("Hola diego", cameraFrame);
if (waitKey(20) == 27) {
    break;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么Firebase数据无法在我的Ember CLI生成的输出中正确显示?

来自分类Dev

为什么关闭按钮(X)无法在我的模态中正确显示?

来自分类Dev

为什么我的评估不能在 C 中正确显示?

来自分类Dev

AVFoundation-为什么我无法正确显示视频方向

来自分类Dev

为什么我的Mapbox GL无法正确显示图块?

来自分类Dev

为什么我在Android中的RecyclerView无法正确显示视图?

来自分类Dev

为什么我的合成信号无法正确显示?的MATLAB

来自分类Dev

为什么我的JButton图标无法正确显示?

来自分类Dev

为什么我无法正确显示这些值?

来自分类Dev

为什么我的char *无法正确通过?

来自分类Dev

为什么我的json无法正确返回?

来自分类Dev

为什么我的htaccess无法正确重写

来自分类Dev

为什么我的代码无法正确加载?

来自分类Dev

jQuery为什么我无法显示对象?

来自分类Dev

jQuery为什么我无法显示对象?

来自分类Dev

为什么我的图形无法显示?

来自分类Dev

为什么我的矩形不显示?

来自分类Dev

iOS:图像无法在UIImageView中正确显示

来自分类Dev

无法在反应中正确显示路线

来自分类Dev

括号无法在hexo博客中正确显示

来自分类Dev

TinyMCE数据无法在JSP中正确显示

来自分类Dev

网址无法在Laravel中正确显示

来自分类Dev

标头无法在Firefox中正确显示

来自分类Dev

Webpy:变量无法在html中正确显示

来自分类Dev

文字无法在HTML中正确显示

来自分类Dev

颜色无法在Chrome中正确显示?

来自分类Dev

css 无法在 chrome 中正确显示

来自分类Dev

tableview 数据无法在 swift 中正确显示

来自分类Dev

无法让数组在 php 中正确显示

Related 相关文章

热门标签

归档