我是 Computer Vison 的中级水平并且相当精通 opencv python 但是来到 c++ 我在从视频提要中选择 ROI 并显示裁剪提要时遇到问题。我的代码如下所示。
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/tracking.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main() {
Mat frame1;
VideoCapture cap;
cap.open(0);
cap.read(frame1);
Rect2d roi = selectROI(frame1, true);
Mat Crop = frame1(roi);
while (1) {
cap.read(frame1);
Crop = frame1(roi);
if (Crop.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
imshow("roi", Crop);
int key=waitkey(0);
}
}
代码正在编译,并且可以看到裁剪的窗口,但是我总是需要单击 enter、空格键或 esc 来获取视频源。奇怪吗?
最佳答案
所以修正后的代码的正确版本看起来有点像这样。感谢您的帮助。
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/tracking.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main() {
Mat frame1;
VideoCapture cap;
cap.open(0);
cap.read(frame1);
Rect2d roi = selectROI(frame1, true);
Mat Crop = frame1(roi);
while (1) {
cap.read(frame1);
Crop = frame1(roi);
if (Crop.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
imshow("roi", Crop);
*int key=waitkey(1)*;
}
关于c++ - 仅当按下 esc、空格键或回车键时才会出现 VideoFrames OpenCV c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44547450/