gpt4 book ai didi

c++ - 仅当按下 esc、空格键或回车键时才会出现 VideoFrames OpenCV c++

转载 作者:行者123 更新时间:2023-11-28 05:06:47 27 4
gpt4 key购买 nike

我是 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com