I'm trying to stop webcam playback on pressing escape.
cv::VideoCapture cap(0);
while(true){
cv::Mat cameraFrame;
cap.read(cameraFrame);
cv::imshow("cam", cameraFrame);
std::cerr<<cv::waitKey(1);
if (cv::waitKey(1) == 27){
if( cap.isOpened() )
cap.release();
}
}
Code is from here. The webcam is never closing and the output of this thing is:
-1-1-1-1-11048603-1-1-1-11048603-1-11048603-1-110486031048603-110486031048603-1-11048689-1104868910486891048689-1-1-111140831310819-1-1-1-1-1-1-1-11114089-1-1-1
Where -1 is the code for pressing nothing, 1048603 is escape and 1114089 is the letter q. What on earth is happening? I was expecting ascii key codes. How do I make my program react to pressing escape or q in a correct way? This does not occur if
Thank you.