0

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.

Gerry
  • 1,938
  • 3
  • 18
  • 25
  • 2
    Mask out the upper bits, so you're left only with the 7 least significant ones and see if it makes any more sense. | Just curious -- what platform, what OpenCV version, and where did that build come from? – Dan Mašek Apr 18 '18 at 21:27
  • 1
    Correct. That solved it. Thank you. FYI: ubuntu, opencv 3.1, and I don't know what that means. – Gerry Apr 18 '18 at 21:48

0 Answers0