让多个线程听键盘最简单的技巧是什么?
我希望简单的r-key
一次记录多个凸轮。
这是我的简化单线程代码(实际是多线程)。
#include <iostream>
#include <thread>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void videoWindow0(){
VideoCapture capture(0); // use webcam
//VideoCapture capture("input.mpg"); // use input file
Mat frame;
if(capture.isOpened()) {
// if using webcam:
int fps = 30;
// if using input file:
//int fps = capture.get(CV_CAP_PROP_FPS);
int width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
int height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
cout << "FPS: " << fps << ", width: " << width << ", height: " << height << endl;
VideoWriter writer("output0.mpg",
CV_FOURCC('P','I','M','1'),
fps, cvSize(width, height), 0); // 0 means gray, 1 means color
if(writer.isOpened()) {
while(true) {
capture >> frame;
if(!frame.empty()) {
imshow("Video0", frame);
}
Mat frame_gray = frame.clone();
cvtColor(frame, frame_gray, CV_RGB2GRAY);
writer << frame_gray;
int key = waitKey(10);
if((char)key == 'q') { break; }
}
}
}
}
int main(){
std::thread t0(videoWindow0)
t0.join();
return 0;
}
问题:
如何让我的线程听取r-key
键盘按钮?