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(); must be called before the loop. The method process video, not a single image.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.