只有当按下esc、空格键或enter键时,视频帧才会出现+; 我是一个计算机视觉中介,精通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); } } #包括“opencv2/highgui.hpp” #包括“opencv2/imgproc.hpp” #包括“opencv2/objdetect/objdetect.hpp” #包括“opencv2/tracking.hpp” #包括“iostream” 使用名称空间cv; 使用名称空间std; int main(){ 垫架1; 视频捕捉帽; 上限开放(0); 第二章(第1章); Rect2d roi=selectROI(frame1,true); Mat裁剪=帧1(roi); 而(1){ 第二章(第1章); 裁剪=帧1(roi); if(Crop.empty()){ cerr

只有当按下esc、空格键或enter键时,视频帧才会出现+; 我是一个计算机视觉中介,精通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); } } #包括“opencv2/highgui.hpp” #包括“opencv2/imgproc.hpp” #包括“opencv2/objdetect/objdetect.hpp” #包括“opencv2/tracking.hpp” #包括“iostream” 使用名称空间cv; 使用名称空间std; int main(){ 垫架1; 视频捕捉帽; 上限开放(0); 第二章(第1章); Rect2d roi=selectROI(frame1,true); Mat裁剪=帧1(roi); 而(1){ 第二章(第1章); 裁剪=帧1(roi); if(Crop.empty()){ cerr,c++,opencv3.2,C++,Opencv3.2,因此,更正代码的正确版本看起来有点像这样。感谢您的帮助 #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

因此,更正代码的正确版本看起来有点像这样。感谢您的帮助

#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)*;
#包括“opencv2/highgui.hpp”
#包括“opencv2/imgproc.hpp”
#包括“opencv2/objdetect/objdetect.hpp”
#包括“opencv2/tracking.hpp”
#包括“iostream”
使用名称空间cv;
使用名称空间std;
int main(){
垫架1;
视频捕捉帽;
上限开放(0);
第二章(第1章);
Rect2d roi=selectROI(frame1,true);
Mat裁剪=帧1(roi);
而(1){
第二章(第1章);
裁剪=帧1(roi);
if(Crop.empty()){

cerr我忘了在duh结尾添加waitkey!!您可以编辑问题来更正代码,但这很可能是您的问题-使用
waitkey(1)
而不是
waitkey(0)
嘿,谢谢你,这确实奏效了……我没有注意到我的键盘正在等待无限次的按键……我认为逻辑有问题……非常愚蠢,谢谢!!!请突出显示所做的更改,以便在有人遇到类似问题时更容易注意并接受你自己的答案