简体   繁体   English

为什么我不能让运动显着性在 OpenCV C++ 中工作?

[英]Why can't I get motion saliency to work in OpenCV C++?

I'm trying to adapt code from this page: https://www.pyimagesearch.com/2018/07/16/opencv-saliency-detection/ , however that is written in Python and I'm trying to do it in C++. I'm trying to adapt code from this page: https://www.pyimagesearch.com/2018/07/16/opencv-saliency-detection/ , however that is written in Python and I'm trying to do it in C++ . When I run my code it compiles, but all I see is a white screen and not any type of saliency detection going on.当我运行我的代码时,它会编译,但我看到的只是一个白屏,而不是任何类型的显着性检测。 What's wrong?怎么了?

cap.open(pathToVideo);
int frame_width = cap.get(CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CAP_PROP_FRAME_HEIGHT);

while (true) {

    Mat frame;
    Mat salientFrame;
    cap >> frame;

    if (frame.empty()) {
        break;
    }

    Ptr<MotionSaliencyBinWangApr2014> MS = MotionSaliencyBinWangApr2014::create();
    cvtColor(frame, frame, COLOR_BGR2GRAY);
    MS->setImagesize(frame.cols, frame.rows);
    MS->init();
    MS->computeSaliency(frame, salientFrame);
    salientFrame.convertTo(salientFrame, CV_8U, 255);
    imshow("Motion Saliency", salientFrame);
    char c = (char)waitKey(25);
    if (c == 27)
        break;
}

cap.release();

The command Ptr MS = MotionSaliencyBinWangApr2014::create();命令 Ptr MS = MotionSaliencyBinWangApr2014::create(); must be called before the loop.必须在循环之前调用。 The method process video, not a single image.该方法处理视频,而不是单个图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM