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

标签 c++ opencv3.2

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

相关文章:

c++ - 如何用音频数据填充 AVFrame

c++ - 将单字母密码解密为新的文本文件

c++ - 在 Boost.Python 中公开一个指针

c++ - 如何找到具有两个帧的 delta theta,每个帧有两个点?

python - 如何检测身份证上的全息图覆盖层?

c++ - 生成真正的随机数

Python OpenCV 3.2 imshow() 没有带有 waitKey(0) 的图像内容!

c++ - 计算特征值错误

c++ - 特殊标牌标注字符