From a5f19f7dd6ae5bc93f73e0417a9e0bfd34c01672 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Fri, 12 Aug 2016 15:11:30 +0200 Subject: [PATCH] adding waitChar key to remove issues with waitKey char comparisons done for cpp/markdown/python filters on search function also added wrapped functionality for Python then checked all python samples, removed ord() and 0xFF anding - no longer needed - --- apps/createsamples/utility.cpp | 10 ++++---- .../interactive-calibration/calibPipeline.cpp | 2 +- .../imgproc/imgtrans/remap/remap.markdown | 4 ++-- .../imgproc/pyramids/pyramids.markdown | 1 + modules/highgui/include/opencv2/highgui.hpp | 22 ++++++++++++++++- modules/highgui/src/window.cpp | 9 +++++++ modules/python/src2/cv2.cpp | 6 +++++ modules/python/test/tst_scene_render.py | 4 ++-- samples/cpp/3calibration.cpp | 2 +- samples/cpp/autofocus.cpp | 2 +- samples/cpp/bgfg_segm.cpp | 2 +- samples/cpp/calibration.cpp | 8 +++---- samples/cpp/camshiftdemo.cpp | 2 +- samples/cpp/cloning_gui.cpp | 2 +- samples/cpp/convexhull.cpp | 3 +-- samples/cpp/detect_mser.cpp | 4 ++-- samples/cpp/distrans.cpp | 2 +- samples/cpp/facedetect.cpp | 12 +++++----- samples/cpp/ffilldemo.cpp | 6 ++--- samples/cpp/grabcut.cpp | 4 ++-- samples/cpp/image_sequence.cpp | 2 +- samples/cpp/inpaint.cpp | 2 +- samples/cpp/kalman.cpp | 4 ++-- samples/cpp/kmeans.cpp | 2 +- samples/cpp/laplace.cpp | 4 ++-- samples/cpp/lkdemo.cpp | 2 +- samples/cpp/minarea.cpp | 2 +- samples/cpp/morphology2.cpp | 14 +++++------ samples/cpp/pca.cpp | 4 ++-- samples/cpp/phase_corr.cpp | 6 ++--- samples/cpp/points_classifier.cpp | 2 +- samples/cpp/segment_objects.cpp | 2 +- samples/cpp/select3dobj.cpp | 6 ++--- samples/cpp/smiledetect.cpp | 2 +- samples/cpp/squares.cpp | 4 ++-- samples/cpp/starter_video.cpp | 2 +- samples/cpp/stereo_calib.cpp | 4 ++-- samples/cpp/train_HOG.cpp | 2 +- .../cpp/tutorial_code/ImgProc/Pyramids.cpp | 24 ++++++++----------- .../cpp/tutorial_code/ImgProc/Smoothing.cpp | 4 ++-- .../cpp/tutorial_code/ImgProc/Threshold.cpp | 5 ++-- .../ImgProc/Threshold_inRange.cpp | 2 +- .../ImgTrans/HoughCircle_Demo.cpp | 4 ++-- .../cpp/tutorial_code/ImgTrans/Remap_Demo.cpp | 4 ++-- .../ImgTrans/copyMakeBorder_demo.cpp | 12 ++++------ .../tutorial_code/ImgTrans/filter2D_demo.cpp | 6 ++--- .../camera_calibration/camera_calibration.cpp | 4 ++-- .../src/main_detection.cpp | 2 +- .../AKAZE_tracking/planar_tracking.cpp | 2 +- .../objectDetection/objectDetection.cpp | 4 ++-- .../objectDetection/objectDetection2.cpp | 4 ++-- .../photo/seamless_cloning/cloning_gui.cpp | 2 +- samples/cpp/tutorial_code/video/bg_sub.cpp | 12 ++++++---- .../video-input-psnr-ssim.cpp | 3 +-- samples/cpp/videostab.cpp | 2 +- samples/cpp/watershed.cpp | 8 +++---- samples/gpu/alpha_comp.cpp | 2 +- samples/gpu/bgfg_segm.cpp | 2 +- samples/gpu/cascadeclassifier.cpp | 2 +- samples/gpu/cascadeclassifier_nvidia_api.cpp | 2 +- samples/gpu/farneback_optical_flow.cpp | 2 +- samples/gpu/morphology.cpp | 2 +- samples/gpu/opengl.cpp | 4 ++-- samples/python/camshift.py | 4 ++-- samples/python/coherence.py | 4 ++-- samples/python/color_histogram.py | 2 +- samples/python/contours.py | 2 +- samples/python/deconvolution.py | 4 ++-- samples/python/digits_video.py | 2 +- samples/python/distrans.py | 4 ++-- samples/python/edge.py | 2 +- samples/python/facedetect.py | 2 +- samples/python/feature_homography.py | 4 ++-- samples/python/fitline.py | 4 ++-- samples/python/floodfill.py | 6 ++--- samples/python/gaussian_mix.py | 2 +- samples/python/grabcut.py | 16 ++++++------- samples/python/hist.py | 12 +++++----- samples/python/inpaint.py | 6 ++--- samples/python/kalman.py | 4 ++-- samples/python/kmeans.py | 2 +- samples/python/lappyr.py | 2 +- samples/python/lk_homography.py | 6 ++--- samples/python/lk_track.py | 2 +- samples/python/morphology.py | 6 ++--- samples/python/mosse.py | 6 ++--- samples/python/mouse_and_match.py | 2 +- samples/python/mser.py | 2 +- samples/python/opt_flow.py | 6 ++--- samples/python/peopledetect.py | 2 +- samples/python/plane_ar.py | 6 ++--- samples/python/plane_tracker.py | 6 ++--- samples/python/squares.py | 2 +- samples/python/tst_scene_render.py | 4 ++-- samples/python/turing.py | 2 +- samples/python/video.py | 4 ++-- samples/python/video_threaded.py | 4 ++-- samples/python/video_v4l2.py | 4 ++-- samples/python/watershed.py | 12 +++++----- samples/tapi/bgfg_segm.cpp | 2 +- samples/tapi/camshift.cpp | 2 +- samples/tapi/clahe.cpp | 2 +- samples/tapi/hog.cpp | 2 +- samples/tapi/pyrlk_optical_flow.cpp | 2 +- samples/tapi/tvl1_optical_flow.cpp | 2 +- samples/tapi/ufacedetect.cpp | 12 +++++----- 106 files changed, 250 insertions(+), 227 deletions(-) diff --git a/apps/createsamples/utility.cpp b/apps/createsamples/utility.cpp index cf2bdebbf9..2226cd8c92 100644 --- a/apps/createsamples/utility.cpp +++ b/apps/createsamples/utility.cpp @@ -1270,7 +1270,7 @@ void cvCreateTrainingSamples( const char* filename, if( showsamples ) { cvShowImage( "Sample", &sample ); - if( cvWaitKey( 0 ) == 27 ) + if( (cvWaitKey( 0 ) & 0xFF) == 27 ) { showsamples = 0; } @@ -1402,7 +1402,7 @@ void cvCreateTestSamples( const char* infoname, if( showsamples ) { cvShowImage( "Image", &cvbgreader->src ); - if( cvWaitKey( 0 ) == 27 ) + if( (cvWaitKey( 0 ) & 0xFF) == 27 ) { showsamples = 0; } @@ -1525,7 +1525,7 @@ int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilena if( showsamples ) { cvShowImage( "Sample", sample ); - if( cvWaitKey( 0 ) == 27 ) + if( (cvWaitKey( 0 ) & 0xFF) == 27 ) { showsamples = 0; } @@ -1672,7 +1672,7 @@ void cvShowVecSamples( const char* filename, int winwidth, int winheight, icvGetTraininDataFromVec( sample, &file ); if( scale != 1.0 ) cvResize( sample, scaled_sample, CV_INTER_LINEAR); cvShowImage( "Sample", scaled_sample ); - if( cvWaitKey( 0 ) == 27 ) break; + if( (cvWaitKey( 0 ) & 0xFF) == 27 ) break; } if( scaled_sample && scaled_sample != sample ) cvReleaseMat( &scaled_sample ); cvReleaseMat( &sample ); @@ -1680,4 +1680,4 @@ void cvShowVecSamples( const char* filename, int winwidth, int winheight, } fclose( file.input ); } -} \ No newline at end of file +} diff --git a/apps/interactive-calibration/calibPipeline.cpp b/apps/interactive-calibration/calibPipeline.cpp index 4575a7024a..7115794467 100644 --- a/apps/interactive-calibration/calibPipeline.cpp +++ b/apps/interactive-calibration/calibPipeline.cpp @@ -62,7 +62,7 @@ PipelineExitStatus CalibPipeline::start(std::vector > pr for (std::vector >::iterator it = processors.begin(); it != processors.end(); ++it) processedFrame = (*it)->processFrame(processedFrame); cv::imshow(mainWindowName, processedFrame); - int key = cv::waitKey(CAP_DELAY); + char key = cv::waitChar(CAP_DELAY); if(key == 27) // esc return Finished; diff --git a/doc/tutorials/imgproc/imgtrans/remap/remap.markdown b/doc/tutorials/imgproc/imgtrans/remap/remap.markdown index 849157f077..b6eff9151d 100644 --- a/doc/tutorials/imgproc/imgtrans/remap/remap.markdown +++ b/doc/tutorials/imgproc/imgtrans/remap/remap.markdown @@ -85,9 +85,9 @@ Explanation while( true ) { /// Each 1 sec. Press ESC to exit the program - int c = waitKey( 1000 ); + char c = waitChar( 1000 ); - if( (char)c == 27 ) + if( c == 27 ) { break; } /// Update map_x & map_y. Then apply remap diff --git a/doc/tutorials/imgproc/pyramids/pyramids.markdown b/doc/tutorials/imgproc/pyramids/pyramids.markdown index 69df1cda63..5210ec007d 100644 --- a/doc/tutorials/imgproc/pyramids/pyramids.markdown +++ b/doc/tutorials/imgproc/pyramids/pyramids.markdown @@ -93,6 +93,7 @@ Let's check the general structure of the program: - Perform an infinite loop waiting for user input. @snippet cpp/tutorial_code/ImgProc/Pyramids.cpp infinite_loop + Our program exits if the user presses *ESC*. Besides, it has two options: - **Perform upsampling (after pressing 'u')** diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index b5c22a19ee..a24ce20c4b 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -109,7 +109,7 @@ It provides easy interface to: Mat img2,img3; - while( waitKey(33) != 27 ) + while( waitChar(33) != 27 ) { img1.convertTo(img2,-1,1,value); video >> img3; @@ -338,6 +338,26 @@ If there are several HighGUI windows, any of them can be active. */ CV_EXPORTS_W int waitKey(int delay = 0); +/** @brief Waits for a pressed key and returns the corresponding char value (ASCII) assigned. + +The function waitChar waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay +milliseconds, when it is positive. It returns the ASCII code of the pressed key as a char value. If no key was pressed before +the specified time has elapsed, -1 (most systems) or 255 (if char == unsigned char) is returned depending on the system available. + +@note + +There is a minor issue for `char == unsigned char systems`. Return value or timeout could be mixed up with value of valid `'\0xFF'` symbol. +However this is an extremely rare usecase, and is thus ignored for the moment. + +@note + +The function only works if there is at least one HighGUI window created and the window is active. +If there are several HighGUI windows, any of them can be active. + +@param delay Delay in milliseconds. 0 is the special value that means "forever". + */ +CV_EXPORTS_W char waitChar(int delay = 0); + /** @brief Displays an image in the specified window. The function imshow displays an image in the specified window. If the window was created with the diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index c879c41305..32d4699690 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -198,6 +198,15 @@ int cv::waitKey(int delay) return cvWaitKey(delay); } +char cv::waitChar(int delay){ +#if CHAR_MIN==SCHAR_MIN + int intKey = cv::waitKey(delay) & 0xFF; + return (char)(intKey & 0x80 ? intKey - 0x100 : intKey); +#else + return (char)(cv::waitKey(delay) & 0xff); +#endif +} + int cv::createTrackbar(const String& trackbarName, const String& winName, int* value, int count, TrackbarCallback callback, void* userdata) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 1c189e7b67..bc683dca13 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -542,6 +542,12 @@ bool pyopencv_to(PyObject* obj, double& value, const char* name) return !PyErr_Occurred(); } +template<> +PyObject* pyopencv_from(const char& value) +{ + return PyInt_FromLong(value); +} + template<> PyObject* pyopencv_from(const float& value) { diff --git a/modules/python/test/tst_scene_render.py b/modules/python/test/tst_scene_render.py index 49cde80d25..68821a2df6 100644 --- a/modules/python/test/tst_scene_render.py +++ b/modules/python/test/tst_scene_render.py @@ -113,7 +113,7 @@ if __name__ == '__main__': img = render.getNextFrame() cv2.imshow('img', img) - ch = 0xFF & cv2.waitKey(3) + ch = cv2.waitChar(3) if ch == 27: break - cv2.destroyAllWindows() \ No newline at end of file + cv2.destroyAllWindows() diff --git a/samples/cpp/3calibration.cpp b/samples/cpp/3calibration.cpp index 7079b6d062..17b5cc979d 100644 --- a/samples/cpp/3calibration.cpp +++ b/samples/cpp/3calibration.cpp @@ -351,7 +351,7 @@ int main( int argc, char** argv ) for( k = 0; k < small_canvas.rows; k += 16 ) line(small_canvas, Point(0, k), Point(small_canvas.cols, k), Scalar(0,255,0), 1); imshow("rectified", small_canvas); - int c = waitKey(0); + char c = waitChar(0); if( c == 27 || c == 'q' || c == 'Q' ) break; } diff --git a/samples/cpp/autofocus.cpp b/samples/cpp/autofocus.cpp index cef279d6f2..cebdc57c27 100644 --- a/samples/cpp/autofocus.cpp +++ b/samples/cpp/autofocus.cpp @@ -400,7 +400,7 @@ int main(int argc, char ** argv) } imshow(windowOriginal, frame); - switch (key = static_cast(waitKey(30))) + switch (key = waitChar(30)) { case 'k': // focus out cap.set(CAP_PROP_ZOOM, 100); diff --git a/samples/cpp/bgfg_segm.cpp b/samples/cpp/bgfg_segm.cpp index c02185a655..5f5dab9c20 100644 --- a/samples/cpp/bgfg_segm.cpp +++ b/samples/cpp/bgfg_segm.cpp @@ -95,7 +95,7 @@ int main(int argc, const char** argv) if(!bgimg.empty()) imshow("mean background image", bgimg ); - char k = (char)waitKey(30); + char k = waitChar(30); if( k == 27 ) break; if( k == ' ' ) { diff --git a/samples/cpp/calibration.cpp b/samples/cpp/calibration.cpp index 415d8bb837..f375736fe0 100644 --- a/samples/cpp/calibration.cpp +++ b/samples/cpp/calibration.cpp @@ -493,9 +493,9 @@ int main( int argc, char** argv ) } imshow("Image View", view); - int key = 0xff & waitKey(capture.isOpened() ? 50 : 500); + char key = waitChar(capture.isOpened() ? 50 : 500); - if( (key & 255) == 27 ) + if( key == 27 ) break; if( key == 'u' && mode == CALIBRATED ) @@ -536,8 +536,8 @@ int main( int argc, char** argv ) //undistort( view, rview, cameraMatrix, distCoeffs, cameraMatrix ); remap(view, rview, map1, map2, INTER_LINEAR); imshow("Image View", rview); - int c = 0xff & waitKey(); - if( (c & 255) == 27 || c == 'q' || c == 'Q' ) + char c = waitChar(); + if( c == 27 || c == 'q' || c == 'Q' ) break; } } diff --git a/samples/cpp/camshiftdemo.cpp b/samples/cpp/camshiftdemo.cpp index 22ce7f8488..e439542105 100644 --- a/samples/cpp/camshiftdemo.cpp +++ b/samples/cpp/camshiftdemo.cpp @@ -188,7 +188,7 @@ int main( int argc, const char** argv ) imshow( "CamShift Demo", image ); imshow( "Histogram", histimg ); - char c = (char)waitKey(10); + char c = waitChar(10); if( c == 27 ) break; switch(c) diff --git a/samples/cpp/cloning_gui.cpp b/samples/cpp/cloning_gui.cpp index 289eae8de0..73878de5dd 100644 --- a/samples/cpp/cloning_gui.cpp +++ b/samples/cpp/cloning_gui.cpp @@ -453,7 +453,7 @@ int main() for(;;) { - char key = (char) waitKey(0); + char key = waitChar(0); if(key == 'd' && flag3 == 0) { diff --git a/samples/cpp/convexhull.cpp b/samples/cpp/convexhull.cpp index fd2275645d..4b45396ff9 100644 --- a/samples/cpp/convexhull.cpp +++ b/samples/cpp/convexhull.cpp @@ -25,7 +25,6 @@ int main( int argc, char** argv ) for(;;) { - char key; int i, count = (unsigned)rng%100 + 1; vector points; @@ -58,7 +57,7 @@ int main( int argc, char** argv ) imshow("hull", img); - key = (char)waitKey(); + char key = waitChar(); if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC' break; } diff --git a/samples/cpp/detect_mser.cpp b/samples/cpp/detect_mser.cpp index 8d16ec657a..8914edae1f 100644 --- a/samples/cpp/detect_mser.cpp +++ b/samples/cpp/detect_mser.cpp @@ -277,8 +277,8 @@ static void DrawOpenGLMSER(Mat img, Mat result) for (;;) { updateWindow("OpenGL"); - int key = waitKey(40); - if ((key & 0xff) == 27) + char key = waitChar(40); + if (key == 27) break; if (key == 0x20) rotateEnable = !rotateEnable; diff --git a/samples/cpp/distrans.cpp b/samples/cpp/distrans.cpp index 4bf4707ba6..c160204a04 100644 --- a/samples/cpp/distrans.cpp +++ b/samples/cpp/distrans.cpp @@ -133,7 +133,7 @@ int main( int argc, const char** argv ) // Call to update the view onTrackbar(0, 0); - int c = waitKey(0) & 255; + char c = waitChar(0); if( c == 27 ) break; diff --git a/samples/cpp/facedetect.cpp b/samples/cpp/facedetect.cpp index 8f6a45666f..2bed2acf84 100644 --- a/samples/cpp/facedetect.cpp +++ b/samples/cpp/facedetect.cpp @@ -72,9 +72,9 @@ int main( int argc, const char** argv ) } if( inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1) ) { - int c = inputName.empty() ? 0 : inputName[0] - '0'; - if(!capture.open(c)) - cout << "Capture from camera #" << c << " didn't work" << endl; + int camera = inputName.empty() ? 0 : inputName[0] - '0'; + if(!capture.open(camera)) + cout << "Capture from camera #" << camera << " didn't work" << endl; } else if( inputName.size() ) { @@ -104,7 +104,7 @@ int main( int argc, const char** argv ) Mat frame1 = frame.clone(); detectAndDraw( frame1, cascade, nestedCascade, scale, tryflip ); - int c = waitKey(10); + char c = waitChar(10); if( c == 27 || c == 'q' || c == 'Q' ) break; } @@ -127,7 +127,7 @@ int main( int argc, const char** argv ) char buf[1000+1]; while( fgets( buf, 1000, f ) ) { - int len = (int)strlen(buf), c; + int len = (int)strlen(buf); while( len > 0 && isspace(buf[len-1]) ) len--; buf[len] = '\0'; @@ -136,7 +136,7 @@ int main( int argc, const char** argv ) if( !image.empty() ) { detectAndDraw( image, cascade, nestedCascade, scale, tryflip ); - c = waitKey(0); + char c = waitChar(0); if( c == 27 || c == 'q' || c == 'Q' ) break; } diff --git a/samples/cpp/ffilldemo.cpp b/samples/cpp/ffilldemo.cpp index d10d72e0eb..914c9b913a 100644 --- a/samples/cpp/ffilldemo.cpp +++ b/samples/cpp/ffilldemo.cpp @@ -105,13 +105,13 @@ int main( int argc, char** argv ) { imshow("image", isColor ? image : gray); - int c = waitKey(0); - if( (c & 255) == 27 ) + char c = waitChar(0); + if( c == 27 ) { cout << "Exiting ...\n"; break; } - switch( (char)c ) + switch( c ) { case 'c': if( isColor ) diff --git a/samples/cpp/grabcut.cpp b/samples/cpp/grabcut.cpp index 726906c6ff..a10ef2bbfd 100644 --- a/samples/cpp/grabcut.cpp +++ b/samples/cpp/grabcut.cpp @@ -306,8 +306,8 @@ int main( int argc, char** argv ) for(;;) { - int c = waitKey(0); - switch( (char) c ) + char c = waitChar(0); + switch( c ) { case '\x1b': cout << "Exiting ..." << endl; diff --git a/samples/cpp/image_sequence.cpp b/samples/cpp/image_sequence.cpp index 6a84fab4bd..644a409a55 100644 --- a/samples/cpp/image_sequence.cpp +++ b/samples/cpp/image_sequence.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv) imshow("Image sequence | press ESC to close", image); - if(waitKey(500) == 27) + if( waitChar(500) == 27) break; } diff --git a/samples/cpp/inpaint.cpp b/samples/cpp/inpaint.cpp index 86e6e37416..e8085353e4 100644 --- a/samples/cpp/inpaint.cpp +++ b/samples/cpp/inpaint.cpp @@ -71,7 +71,7 @@ int main( int argc, char** argv ) for(;;) { - char c = (char)waitKey(); + char c = waitChar(); if( c == 27 ) break; diff --git a/samples/cpp/kalman.cpp b/samples/cpp/kalman.cpp index 501a749124..10db1d3b7a 100644 --- a/samples/cpp/kalman.cpp +++ b/samples/cpp/kalman.cpp @@ -35,7 +35,7 @@ int main(int, char**) Mat state(2, 1, CV_32F); /* (phi, delta_phi) */ Mat processNoise(2, 1, CV_32F); Mat measurement = Mat::zeros(1, 1, CV_32F); - char code = (char)-1; + char code = 0; for(;;) { @@ -89,7 +89,7 @@ int main(int, char**) state = KF.transitionMatrix*state + processNoise; imshow( "Kalman", img ); - code = (char)waitKey(100); + code = waitChar(100); if( code > 0 ) break; diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index e90ec2c108..84cc9620cc 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -68,7 +68,7 @@ int main( int /*argc*/, char** /*argv*/ ) imshow("clusters", img); - char key = (char)waitKey(); + char key = waitChar(); if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC' break; } diff --git a/samples/cpp/laplace.cpp b/samples/cpp/laplace.cpp index 462f62804e..7395c41801 100644 --- a/samples/cpp/laplace.cpp +++ b/samples/cpp/laplace.cpp @@ -83,10 +83,10 @@ int main( int argc, char** argv ) convertScaleAbs(laplace, result, (sigma+1)*0.25); imshow("Laplacian", result); - int c = waitKey(30); + char c = waitChar(30); if( c == ' ' ) smoothType = smoothType == GAUSSIAN ? BLUR : smoothType == BLUR ? MEDIAN : GAUSSIAN; - if( c == 'q' || c == 'Q' || (c & 255) == 27 ) + if( c == 'q' || c == 'Q' || c == 27 ) break; } diff --git a/samples/cpp/lkdemo.cpp b/samples/cpp/lkdemo.cpp index 5e57aa84a4..31b7accf87 100644 --- a/samples/cpp/lkdemo.cpp +++ b/samples/cpp/lkdemo.cpp @@ -131,7 +131,7 @@ int main( int argc, char** argv ) needToInit = false; imshow("LK Demo", image); - char c = (char)waitKey(10); + char c = waitChar(10); if( c == 27 ) break; switch( c ) diff --git a/samples/cpp/minarea.cpp b/samples/cpp/minarea.cpp index ac79db5e5a..d3d5b8d048 100644 --- a/samples/cpp/minarea.cpp +++ b/samples/cpp/minarea.cpp @@ -72,7 +72,7 @@ int main( int /*argc*/, char** /*argv*/ ) imshow( "Rectangle, triangle & circle", img ); - char key = (char)waitKey(); + char key = waitChar(); if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC' break; } diff --git a/samples/cpp/morphology2.cpp b/samples/cpp/morphology2.cpp index 8439080b2b..f6202a7fb8 100644 --- a/samples/cpp/morphology2.cpp +++ b/samples/cpp/morphology2.cpp @@ -82,21 +82,19 @@ int main( int argc, char** argv ) for(;;) { - int c; - OpenClose(open_close_pos, 0); ErodeDilate(erode_dilate_pos, 0); - c = waitKey(0); + char c = waitChar(0); - if( (char)c == 27 ) + if( c == 27 ) break; - if( (char)c == 'e' ) + if( c == 'e' ) element_shape = MORPH_ELLIPSE; - else if( (char)c == 'r' ) + else if( c == 'r' ) element_shape = MORPH_RECT; - else if( (char)c == 'c' ) + else if( c == 'c' ) element_shape = MORPH_CROSS; - else if( (char)c == ' ' ) + else if( c == ' ' ) element_shape = (element_shape + 1) % 3; } diff --git a/samples/cpp/pca.cpp b/samples/cpp/pca.cpp index b33a463211..e25f38d032 100644 --- a/samples/cpp/pca.cpp +++ b/samples/cpp/pca.cpp @@ -183,9 +183,9 @@ int main(int argc, char** argv) // display until user presses q imshow(winName, reconstruction); - int key = 0; + char key = 0; while(key != 'q') - key = waitKey(); + key = waitChar(); return 0; } diff --git a/samples/cpp/phase_corr.cpp b/samples/cpp/phase_corr.cpp index c3120fe084..d0edba0aa0 100644 --- a/samples/cpp/phase_corr.cpp +++ b/samples/cpp/phase_corr.cpp @@ -9,7 +9,7 @@ int main(int, char* []) { VideoCapture video(0); Mat frame, curr, prev, curr64f, prev64f, hann; - int key = 0; + char key; do { @@ -37,10 +37,10 @@ int main(int, char* []) } imshow("phase shift", frame); - key = waitKey(2); + key = waitChar(2); prev = curr.clone(); - } while((char)key != 27); // Esc to exit... + } while(key != 27); // Esc to exit... return 0; } diff --git a/samples/cpp/points_classifier.cpp b/samples/cpp/points_classifier.cpp index c0270d084c..8096178e5a 100644 --- a/samples/cpp/points_classifier.cpp +++ b/samples/cpp/points_classifier.cpp @@ -312,7 +312,7 @@ int main() for(;;) { - uchar key = (uchar)waitKey(); + char key = waitChar(); if( key == 27 ) break; diff --git a/samples/cpp/segment_objects.cpp b/samples/cpp/segment_objects.cpp index 916283124f..85961251b0 100644 --- a/samples/cpp/segment_objects.cpp +++ b/samples/cpp/segment_objects.cpp @@ -105,7 +105,7 @@ int main(int argc, char** argv) refineSegments(tmp_frame, bgmask, out_frame); imshow("video", tmp_frame); imshow("segmented", out_frame); - int keycode = waitKey(30); + char keycode = waitChar(30); if( keycode == 27 ) break; if( keycode == ' ' ) diff --git a/samples/cpp/select3dobj.cpp b/samples/cpp/select3dobj.cpp index b13697fec2..7ebaa70369 100644 --- a/samples/cpp/select3dobj.cpp +++ b/samples/cpp/select3dobj.cpp @@ -285,8 +285,8 @@ static int select3DBox(const string& windowname, const string& selWinName, const imshow(windowname, shownFrame); imshow(selWinName, selectedObjFrame); - int c = waitKey(30); - if( (c & 255) == 27 ) + char c = waitChar(30); + if( c == 27 ) { nobjpt = 0; } @@ -593,7 +593,7 @@ int main(int argc, char** argv) imshow("View", shownFrame); imshow("Selected Object", selectedObjFrame); - int c = waitKey(imageList.empty() && !box.empty() ? 30 : 300); + char c = waitChar(imageList.empty() && !box.empty() ? 30 : 300); if( c == 'q' || c == 'Q' ) break; if( c == '\r' || c == '\n' ) diff --git a/samples/cpp/smiledetect.cpp b/samples/cpp/smiledetect.cpp index f2f0bbf076..e3493d192c 100644 --- a/samples/cpp/smiledetect.cpp +++ b/samples/cpp/smiledetect.cpp @@ -99,7 +99,7 @@ int main( int argc, const char** argv ) Mat frame1 = frame.clone(); detectAndDraw( frame1, cascade, nestedCascade, scale, tryflip ); - int c = waitKey(10); + char c = waitChar(10); if( c == 27 || c == 'q' || c == 'Q' ) break; } diff --git a/samples/cpp/squares.cpp b/samples/cpp/squares.cpp index df8459caa4..4c62178aee 100644 --- a/samples/cpp/squares.cpp +++ b/samples/cpp/squares.cpp @@ -167,8 +167,8 @@ int main(int argc, char** argv) findSquares(image, squares); drawSquares(image, squares); - int c = waitKey(); - if( (char)c == 27 ) + char c = waitChar(); + if( c == 27 ) break; } diff --git a/samples/cpp/starter_video.cpp b/samples/cpp/starter_video.cpp index 2839b03d7e..274067ae63 100644 --- a/samples/cpp/starter_video.cpp +++ b/samples/cpp/starter_video.cpp @@ -50,7 +50,7 @@ namespace { break; imshow(window_name, frame); - char key = (char)waitKey(30); //delay N millis, usually long enough to display and capture input + char key = waitChar(30); //delay N millis, usually long enough to display and capture input switch (key) { case 'q': diff --git a/samples/cpp/stereo_calib.cpp b/samples/cpp/stereo_calib.cpp index 000928c1cf..dddb13aa8f 100644 --- a/samples/cpp/stereo_calib.cpp +++ b/samples/cpp/stereo_calib.cpp @@ -122,7 +122,7 @@ StereoCalib(const vector& imagelist, Size boardSize, float squareSize, b double sf = 640./MAX(img.rows, img.cols); resize(cimg, cimg1, Size(), sf, sf); imshow("corners", cimg1); - char c = (char)waitKey(500); + char c = waitChar(500); if( c == 27 || c == 'q' || c == 'Q' ) //Allow ESC to quit exit(-1); } @@ -320,7 +320,7 @@ StereoCalib(const vector& imagelist, Size boardSize, float squareSize, b for( j = 0; j < canvas.cols; j += 16 ) line(canvas, Point(j, 0), Point(j, canvas.rows), Scalar(0, 255, 0), 1, 8); imshow("rectified", canvas); - char c = (char)waitKey(); + char c = waitChar(); if( c == 27 || c == 'q' || c == 'Q' ) break; } diff --git a/samples/cpp/train_HOG.cpp b/samples/cpp/train_HOG.cpp index 900637b6b3..cf05c492d1 100644 --- a/samples/cpp/train_HOG.cpp +++ b/samples/cpp/train_HOG.cpp @@ -395,7 +395,7 @@ void test_it( const Size & size ) draw_locations( draw, locations, trained ); imshow( "Video", draw ); - key = (char)waitKey( 10 ); + key = waitChar( 10 ); if( 27 == key ) end_of_process = true; } diff --git a/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp b/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp index d8067f9869..797a159609 100644 --- a/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp @@ -45,26 +45,22 @@ int main( void ) //![infinite_loop] for(;;) { - int c; - c = waitKey(0); + char c = waitChar(0); - if( (char)c == 27 ) + if( c == 27 ) { break; } - if( (char)c == 'u' ) - { - //![pyrup] - pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) ); - //![pyrup] + //![pyrup] + if( c == 'u' ) + { pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) ); printf( "** Zoom In: Image x 2 \n" ); } - else if( (char)c == 'd' ) - { - //![pyrdown] - pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) ); - //![pyrdown] + //![pyrup] + //![pyrdown] + else if( c == 'd' ) + { pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) ); printf( "** Zoom Out: Image / 2 \n" ); } - + //![pyrdown] imshow( window_name, dst ); //![update_tmp] diff --git a/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp b/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp index 58aa474c38..d2400af7bd 100644 --- a/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp @@ -95,7 +95,7 @@ int display_caption( const char* caption ) FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255) ); imshow( window_name, dst ); - int c = waitKey( DELAY_CAPTION ); + char c = waitChar( DELAY_CAPTION ); if( c >= 0 ) { return -1; } return 0; } @@ -106,7 +106,7 @@ int display_caption( const char* caption ) int display_dst( int delay ) { imshow( window_name, dst ); - int c = waitKey ( delay ); + char c = waitChar( delay ); if( c >= 0 ) { return -1; } return 0; } diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp index cee1a51c9c..ef549429e1 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp @@ -60,9 +60,8 @@ int main( int, char** argv ) /// Wait until user finishes program for(;;) { - int c; - c = waitKey( 20 ); - if( (char)c == 27 ) + char c = waitChar( 20 ); + if( c == 27 ) { break; } } diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp index 3801b30e7b..065e8afe15 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp @@ -41,7 +41,7 @@ int main() createTrackbar("Low B","Object Detection", &low_b, 255, on_low_b_thresh_trackbar); createTrackbar("High B","Object Detection", &high_b, 255, on_high_b_thresh_trackbar); //! [trackbar] - while(char(waitKey(1))!='q'){ + while(waitChar(1)!='q'){ //! [while] cap>>frame; if(frame.empty()) diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp index 81bb3f8895..87ef072679 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp @@ -90,7 +90,7 @@ int main(int argc, char** argv) // infinite loop to display // and refresh the content of the output image // until the user presses q or Q - int key = 0; + char key = 0; while(key != 'q' && key != 'Q') { // those paramaters cannot be =0 @@ -102,7 +102,7 @@ int main(int argc, char** argv) HoughDetection(src_gray, src, cannyThreshold, accumulatorThreshold); // get user key - key = waitKey(10); + key = waitChar(10); } return 0; diff --git a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp index b5a76faa47..c77c0afaa9 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp @@ -40,9 +40,9 @@ int main( int, char** argv ) for(;;) { /// Each 1 sec. Press ESC to exit the program - int c = waitKey( 1000 ); + char c = waitChar( 1000 ); - if( (char)c == 27 ) + if( c == 27 ) { break; } /// Update map_x & map_y. Then apply remap diff --git a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp index 60a6d9fcb5..92ef2aece4 100644 --- a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp @@ -23,9 +23,6 @@ RNG rng(12345); */ int main( int, char** argv ) { - - int c; - //![load] src = imread( argv[1], IMREAD_COLOR ); // Load an image @@ -59,13 +56,12 @@ int main( int, char** argv ) for(;;) { //![check_keypress] - c = waitKey(500); - - if( (char)c == 27 ) + char c = waitChar(500); + if( c == 27 ) { break; } - else if( (char)c == 'c' ) + else if( c == 'c' ) { borderType = BORDER_CONSTANT; } - else if( (char)c == 'r' ) + else if( c == 'r' ) { borderType = BORDER_REPLICATE; } //![check_keypress] diff --git a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp index e1ceb0bf6d..49fb5eef27 100644 --- a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp @@ -25,8 +25,6 @@ int main ( int, char** argv ) int kernel_size; const char* window_name = "filter2D Demo"; - int c; - //![load] src = imread( argv[1], IMREAD_COLOR ); // Load an image @@ -45,9 +43,9 @@ int main ( int, char** argv ) int ind = 0; for(;;) { - c = waitKey(500); + char c = waitChar(500); /// Press 'ESC' to exit the program - if( (char)c == 27 ) + if( c == 27 ) { break; } //![update_kernel] diff --git a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp index b5647b5ebc..0eee4a701f 100644 --- a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp +++ b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp @@ -393,7 +393,7 @@ int main(int argc, char* argv[]) //------------------------------ Show image and check for input commands ------------------- //! [await_input] imshow("Image View", view); - char key = (char)waitKey(s.inputCapture.isOpened() ? 50 : s.delay); + char key = waitChar(s.inputCapture.isOpened() ? 50 : s.delay); if( key == ESC_KEY ) break; @@ -438,7 +438,7 @@ int main(int argc, char* argv[]) continue; remap(view, rview, map1, map2, INTER_LINEAR); imshow("Image View", rview); - char c = (char)waitKey(); + char c = waitChar(); if( c == ESC_KEY || c == 'q' || c == 'Q' ) break; } diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp index 4808e64135..3add2db1bf 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp @@ -180,7 +180,7 @@ int main(int argc, char *argv[]) Mat frame, frame_vis; - while(cap.read(frame) && waitKey(30) != 27) // capture frame until ESC is pressed + while(cap.read(frame) && waitChar(30) != 27) // capture frame until ESC is pressed { frame_vis = frame.clone(); // refresh visualisation frame diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp index 4920e428cf..f78501a38c 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp @@ -195,7 +195,7 @@ int main(int argc, char **argv) drawStatistics(orb_res, orb_draw_stats); vconcat(akaze_res, orb_res, res_frame); cv::imshow(video_name, res_frame); - if(cv::waitKey(1)==27) break; //quit on ESC button + if(cv::waitChar(1)==27) break; //quit on ESC button } akaze_stats /= i - 1; orb_stats /= i - 1; diff --git a/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp b/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp index fbd76e4f08..4a0feec938 100644 --- a/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp +++ b/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp @@ -44,8 +44,8 @@ int main( void ) //-- 3. Apply the classifier to the frame detectAndDisplay( frame ); - int c = waitKey(10); - if( (char)c == 27 ) { break; } // escape + char c = waitChar(10); + if( c == 27 ) { break; } // escape } return 0; } diff --git a/samples/cpp/tutorial_code/objectDetection/objectDetection2.cpp b/samples/cpp/tutorial_code/objectDetection/objectDetection2.cpp index d28fa2bba6..624af2f5b0 100644 --- a/samples/cpp/tutorial_code/objectDetection/objectDetection2.cpp +++ b/samples/cpp/tutorial_code/objectDetection/objectDetection2.cpp @@ -51,8 +51,8 @@ int main( void ) detectAndDisplay( frame ); //-- bail out if escape was pressed - int c = waitKey(10); - if( (char)c == 27 ) { break; } + char c = waitChar(10); + if( c == 27 ) { break; } } return 0; } diff --git a/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp b/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp index 180cd69ce2..d9973c2ef3 100644 --- a/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp +++ b/samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp @@ -452,7 +452,7 @@ int main() for(;;) { - char key = (char) waitKey(0); + char key = waitChar(0); if(key == 'd' && flag3 == 0) { diff --git a/samples/cpp/tutorial_code/video/bg_sub.cpp b/samples/cpp/tutorial_code/video/bg_sub.cpp index 94799f388b..8e49ed5c3a 100644 --- a/samples/cpp/tutorial_code/video/bg_sub.cpp +++ b/samples/cpp/tutorial_code/video/bg_sub.cpp @@ -23,7 +23,7 @@ using namespace std; Mat frame; //current frame Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method Ptr pMOG2; //MOG2 Background subtractor -int keyboard; //input from keyboard +char keyboard; //input from keyboard /** Function Headers */ void help(); @@ -98,7 +98,8 @@ void processVideo(char* videoFilename) { exit(EXIT_FAILURE); } //read input data. ESC or 'q' for quitting - while( (char)keyboard != 'q' && (char)keyboard != 27 ){ + keyboard = 0; + while( keyboard != 'q' && keyboard != 27 ){ //read the current frame if(!capture.read(frame)) { cerr << "Unable to read next frame." << endl; @@ -119,7 +120,7 @@ void processVideo(char* videoFilename) { imshow("Frame", frame); imshow("FG Mask MOG 2", fgMaskMOG2); //get the input from the keyboard - keyboard = waitKey( 30 ); + keyboard = waitChar( 30 ); } //delete capture object capture.release(); @@ -139,7 +140,8 @@ void processImages(char* fistFrameFilename) { //current image filename string fn(fistFrameFilename); //read input data. ESC or 'q' for quitting - while( (char)keyboard != 'q' && (char)keyboard != 27 ){ + keyboard = 0; + while( keyboard != 'q' && keyboard != 27 ){ //update the background model pMOG2->apply(frame, fgMaskMOG2); //get the frame number and write it on the current frame @@ -162,7 +164,7 @@ void processImages(char* fistFrameFilename) { imshow("Frame", frame); imshow("FG Mask MOG 2", fgMaskMOG2); //get the input from the keyboard - keyboard = waitKey( 30 ); + keyboard = waitChar( 30 ); //search for the next image in the sequence ostringstream oss; oss << (frameNumber + 1); diff --git a/samples/cpp/tutorial_code/videoio/video-input-psnr-ssim/video-input-psnr-ssim.cpp b/samples/cpp/tutorial_code/videoio/video-input-psnr-ssim/video-input-psnr-ssim.cpp index d3f3c21c09..076341f7bc 100644 --- a/samples/cpp/tutorial_code/videoio/video-input-psnr-ssim/video-input-psnr-ssim.cpp +++ b/samples/cpp/tutorial_code/videoio/video-input-psnr-ssim/video-input-psnr-ssim.cpp @@ -44,7 +44,6 @@ int main(int argc, char *argv[]) conv << argv[3] << endl << argv[4]; // put in the strings conv >> psnrTriggerValue >> delay; // take out the numbers - char c; int frameNum = -1; // Frame counter VideoCapture captRefrnc(sourceReference), captUndTst(sourceCompareWith); @@ -126,7 +125,7 @@ int main(int argc, char *argv[]) imshow(WIN_RF, frameReference); imshow(WIN_UT, frameUnderTest); - c = (char)waitKey(delay); + char c = waitChar(delay); if (c == 27) break; } diff --git a/samples/cpp/videostab.cpp b/samples/cpp/videostab.cpp index 3fb7fb40bd..fbed338942 100644 --- a/samples/cpp/videostab.cpp +++ b/samples/cpp/videostab.cpp @@ -58,7 +58,7 @@ void run() if (!quietMode) { imshow("stabilizedFrame", stabilizedFrame); - char key = static_cast(waitKey(3)); + char key = waitChar(3); if (key == 27) { cout << endl; break; } } } diff --git a/samples/cpp/watershed.cpp b/samples/cpp/watershed.cpp index 9f2e69ec6b..cd6c143691 100644 --- a/samples/cpp/watershed.cpp +++ b/samples/cpp/watershed.cpp @@ -74,19 +74,19 @@ int main( int argc, char** argv ) for(;;) { - int c = waitKey(0); + char c = waitChar(0); - if( (char)c == 27 ) + if( c == 27 ) break; - if( (char)c == 'r' ) + if( c == 'r' ) { markerMask = Scalar::all(0); img0.copyTo(img); imshow( "image", img ); } - if( (char)c == 'w' || (char)c == ' ' ) + if( c == 'w' || c == ' ' ) { int i, j, compCount = 0; vector > contours; diff --git a/samples/gpu/alpha_comp.cpp b/samples/gpu/alpha_comp.cpp index 3f7966ded3..3b13a8be28 100644 --- a/samples/gpu/alpha_comp.cpp +++ b/samples/gpu/alpha_comp.cpp @@ -50,7 +50,7 @@ int main() imshow("Result", d_res); - char key = static_cast(waitKey()); + char key = waitChar(); if (key == 27) break; diff --git a/samples/gpu/bgfg_segm.cpp b/samples/gpu/bgfg_segm.cpp index 00bb59e248..ac234017cc 100644 --- a/samples/gpu/bgfg_segm.cpp +++ b/samples/gpu/bgfg_segm.cpp @@ -161,7 +161,7 @@ int main(int argc, const char** argv) if (!bgimg.empty()) imshow("mean background image", bgimg); - int key = waitKey(30); + char key = waitChar(30); if (key == 27) break; } diff --git a/samples/gpu/cascadeclassifier.cpp b/samples/gpu/cascadeclassifier.cpp index f59ff55b19..0b5e8fcc64 100644 --- a/samples/gpu/cascadeclassifier.cpp +++ b/samples/gpu/cascadeclassifier.cpp @@ -279,7 +279,7 @@ int main(int argc, const char *argv[]) displayState(frameDisp, helpScreen, useGPU, findLargestObject, filterRects, fps); imshow("result", frameDisp); - char key = (char)waitKey(5); + char key = waitChar(5); if (key == 27) { break; diff --git a/samples/gpu/cascadeclassifier_nvidia_api.cpp b/samples/gpu/cascadeclassifier_nvidia_api.cpp index f3d58cae5a..23ee05bd22 100644 --- a/samples/gpu/cascadeclassifier_nvidia_api.cpp +++ b/samples/gpu/cascadeclassifier_nvidia_api.cpp @@ -348,7 +348,7 @@ int main(int argc, const char** argv) imshow(wndTitle, frameDisp); //handle input - switch (cv::waitKey(3)) + switch (cv::waitChar(3)) { case ' ': bUseGPU = !bUseGPU; diff --git a/samples/gpu/farneback_optical_flow.cpp b/samples/gpu/farneback_optical_flow.cpp index 798b108a62..720b48a672 100644 --- a/samples/gpu/farneback_optical_flow.cpp +++ b/samples/gpu/farneback_optical_flow.cpp @@ -125,7 +125,7 @@ int main(int argc, char **argv) imshow("flow", image); - char ch = (char)waitKey(3); + char ch = waitChar(3); if (ch == 27) running = false; else if (ch == 'm' || ch == 'M') diff --git a/samples/gpu/morphology.cpp b/samples/gpu/morphology.cpp index b5e50caa3c..af75b22728 100644 --- a/samples/gpu/morphology.cpp +++ b/samples/gpu/morphology.cpp @@ -81,7 +81,7 @@ int App::run() OpenClose(); ErodeDilate(); - char c = (char) waitKey(); + char c = waitChar(); switch (c) { diff --git a/samples/gpu/opengl.cpp b/samples/gpu/opengl.cpp index 9e2c68c432..0ae5cb02c9 100644 --- a/samples/gpu/opengl.cpp +++ b/samples/gpu/opengl.cpp @@ -105,8 +105,8 @@ int main(int argc, char* argv[]) for (;;) { updateWindow("OpenGL"); - int key = waitKey(40); - if ((key & 0xff) == 27) + char key = waitChar(40); + if (key == 27) break; } diff --git a/samples/python/camshift.py b/samples/python/camshift.py index d1298b9c27..e1dc51262d 100755 --- a/samples/python/camshift.py +++ b/samples/python/camshift.py @@ -110,10 +110,10 @@ class App(object): cv2.imshow('camshift', vis) - ch = 0xFF & cv2.waitKey(5) + ch = cv2.waitChar(5) if ch == 27: break - if ch == ord('b'): + if ch == 'b': self.show_backproj = not self.show_backproj cv2.destroyAllWindows() diff --git a/samples/python/coherence.py b/samples/python/coherence.py index 8ca61fcb21..42e0a4df80 100755 --- a/samples/python/coherence.py +++ b/samples/python/coherence.py @@ -77,8 +77,8 @@ if __name__ == '__main__': cv2.imshow('src', src) update() while True: - ch = 0xFF & cv2.waitKey() - if ch == ord(' '): + ch = cv2.waitChar() + if ch == ' ': update() if ch == 27: break diff --git a/samples/python/color_histogram.py b/samples/python/color_histogram.py index 9e691b7efe..f98606f1fe 100755 --- a/samples/python/color_histogram.py +++ b/samples/python/color_histogram.py @@ -56,7 +56,7 @@ if __name__ == '__main__': vis = hsv_map*h[:,:,np.newaxis] / 255.0 cv2.imshow('hist', vis) - ch = 0xFF & cv2.waitKey(1) + ch = cv2.waitChar(1) if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python/contours.py b/samples/python/contours.py index 619108b245..73b9f2f821 100755 --- a/samples/python/contours.py +++ b/samples/python/contours.py @@ -66,5 +66,5 @@ if __name__ == '__main__': update(3) cv2.createTrackbar( "levels+3", "contours", 3, 7, update ) cv2.imshow('image', img) - 0xFF & cv2.waitKey() + cv2.waitKey() cv2.destroyAllWindows() diff --git a/samples/python/deconvolution.py b/samples/python/deconvolution.py index ce798538b8..bfcaa93423 100755 --- a/samples/python/deconvolution.py +++ b/samples/python/deconvolution.py @@ -122,9 +122,9 @@ if __name__ == '__main__': update(None) while True: - ch = cv2.waitKey() & 0xFF + ch = cv2.waitChar() if ch == 27: break - if ch == ord(' '): + if ch == ' ': defocus = not defocus update(None) diff --git a/samples/python/digits_video.py b/samples/python/digits_video.py index 74b9d6993b..05c1ffa638 100755 --- a/samples/python/digits_video.py +++ b/samples/python/digits_video.py @@ -92,7 +92,7 @@ def main(): cv2.imshow('frame', frame) cv2.imshow('bin', bin) - ch = cv2.waitKey(1) & 0xFF + ch = cv2.waitChar(1) if ch == 27: break diff --git a/samples/python/distrans.py b/samples/python/distrans.py index 00e173d523..a92b88eac4 100755 --- a/samples/python/distrans.py +++ b/samples/python/distrans.py @@ -59,10 +59,10 @@ if __name__ == '__main__': while True: - ch = 0xFF & cv2.waitKey(50) + ch = cv2.waitChar(50) if ch == 27: break - if ch == ord('v'): + if ch == 'v': voronoi = not voronoi print('showing', ['distance', 'voronoi'][voronoi]) update() diff --git a/samples/python/edge.py b/samples/python/edge.py index c096fb46a7..b61ad4a2e4 100755 --- a/samples/python/edge.py +++ b/samples/python/edge.py @@ -49,7 +49,7 @@ if __name__ == '__main__': vis = np.uint8(vis/2.) vis[edge != 0] = (0, 255, 0) cv2.imshow('edge', vis) - ch = cv2.waitKey(5) & 0xFF + ch = cv2.waitChar(5) if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python/facedetect.py b/samples/python/facedetect.py index 15187c62f4..ea98086b9f 100755 --- a/samples/python/facedetect.py +++ b/samples/python/facedetect.py @@ -68,6 +68,6 @@ if __name__ == '__main__': draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000)) cv2.imshow('facedetect', vis) - if 0xFF & cv2.waitKey(5) == 27: + if cv2.waitChar(5) == 27: break cv2.destroyAllWindows() diff --git a/samples/python/feature_homography.py b/samples/python/feature_homography.py index 37f269f52e..3927aa2cef 100755 --- a/samples/python/feature_homography.py +++ b/samples/python/feature_homography.py @@ -80,8 +80,8 @@ class App: self.rect_sel.draw(vis) cv2.imshow('plane', vis) - ch = cv2.waitKey(1) - if ch == ord(' '): + ch = cv2.waitChar(1) + if ch == ' ': self.paused = not self.paused if ch == 27: break diff --git a/samples/python/fitline.py b/samples/python/fitline.py index 95fb2b8d10..2ce7884c20 100755 --- a/samples/python/fitline.py +++ b/samples/python/fitline.py @@ -88,8 +88,8 @@ if __name__ == '__main__': cv2.createTrackbar('outlier %', 'fit line', 30, 100, update) while True: update() - ch = cv2.waitKey(0) & 0xFF - if ch == ord('f'): + ch = cv2.waitChar(0) + if ch == 'f': if PY3: cur_func_name = next(dist_func_names) else: diff --git a/samples/python/floodfill.py b/samples/python/floodfill.py index 161c6323f4..6d9bb115d8 100755 --- a/samples/python/floodfill.py +++ b/samples/python/floodfill.py @@ -66,14 +66,14 @@ if __name__ == '__main__': cv2.createTrackbar('hi', 'floodfill', 20, 255, update) while True: - ch = 0xFF & cv2.waitKey() + ch = cv2.waitChar() if ch == 27: break - if ch == ord('f'): + if ch == 'f': fixed_range = not fixed_range print('using %s range' % ('floating', 'fixed')[fixed_range]) update() - if ch == ord('c'): + if ch == 'c': connectivity = 12-connectivity print('connectivity =', connectivity) update() diff --git a/samples/python/gaussian_mix.py b/samples/python/gaussian_mix.py index 64fbe23462..86875159d4 100755 --- a/samples/python/gaussian_mix.py +++ b/samples/python/gaussian_mix.py @@ -63,7 +63,7 @@ if __name__ == '__main__': draw_gaussain(img, m, cov, (0, 0, 255)) cv2.imshow('gaussian mixture', img) - ch = 0xFF & cv2.waitKey(0) + ch = cv2.waitChar(0) if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python/grabcut.py b/samples/python/grabcut.py index 19378e6cce..c7d9f07c79 100644 --- a/samples/python/grabcut.py +++ b/samples/python/grabcut.py @@ -129,27 +129,27 @@ if __name__ == '__main__': cv2.imshow('output',output) cv2.imshow('input',img) - k = 0xFF & cv2.waitKey(1) + k = cv2.waitChar(1) # key bindings if k == 27: # esc to exit break - elif k == ord('0'): # BG drawing + elif k == '0': # BG drawing print(" mark background regions with left mouse button \n") value = DRAW_BG - elif k == ord('1'): # FG drawing + elif k == '1': # FG drawing print(" mark foreground regions with left mouse button \n") value = DRAW_FG - elif k == ord('2'): # PR_BG drawing + elif k == '2': # PR_BG drawing value = DRAW_PR_BG - elif k == ord('3'): # PR_FG drawing + elif k == '3': # PR_FG drawing value = DRAW_PR_FG - elif k == ord('s'): # save image + elif k == 's': # save image bar = np.zeros((img.shape[0],5,3),np.uint8) res = np.hstack((img2,bar,img,bar,output)) cv2.imwrite('grabcut_output.png',res) print(" Result saved as image \n") - elif k == ord('r'): # reset everything + elif k == 'r': # reset everything print("resetting \n") rect = (0,0,1,1) drawing = False @@ -160,7 +160,7 @@ if __name__ == '__main__': img = img2.copy() mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG output = np.zeros(img.shape,np.uint8) # output image to be shown - elif k == ord('n'): # segment the image + elif k == 'n': # segment the image print(""" For finer touchups, mark foreground and background after pressing keys 0-3 and again press 'n' \n""") if (rect_or_mask == 0): # grabcut with rect diff --git a/samples/python/hist.py b/samples/python/hist.py index 80cc6b4802..a71e1e288e 100755 --- a/samples/python/hist.py +++ b/samples/python/hist.py @@ -84,29 +84,29 @@ if __name__ == '__main__': cv2.imshow('image',im) while True: - k = cv2.waitKey(0)&0xFF - if k == ord('a'): + k = cv2.waitChar(0) + if k == 'a': curve = hist_curve(im) cv2.imshow('histogram',curve) cv2.imshow('image',im) print('a') - elif k == ord('b'): + elif k == 'b': print('b') lines = hist_lines(im) cv2.imshow('histogram',lines) cv2.imshow('image',gray) - elif k == ord('c'): + elif k == 'c': print('c') equ = cv2.equalizeHist(gray) lines = hist_lines(equ) cv2.imshow('histogram',lines) cv2.imshow('image',equ) - elif k == ord('d'): + elif k == 'd': print('d') curve = hist_curve(gray) cv2.imshow('histogram',curve) cv2.imshow('image',gray) - elif k == ord('e'): + elif k == 'e': print('e') norm = cv2.normalize(gray, gray, alpha = 0,beta = 255,norm_type = cv2.NORM_MINMAX) lines = hist_lines(norm) diff --git a/samples/python/inpaint.py b/samples/python/inpaint.py index 0ca72f1a25..698a2c0ff6 100755 --- a/samples/python/inpaint.py +++ b/samples/python/inpaint.py @@ -41,13 +41,13 @@ if __name__ == '__main__': sketch = Sketcher('img', [img_mark, mark], lambda : ((255, 255, 255), 255)) while True: - ch = 0xFF & cv2.waitKey() + ch = cv2.waitChar() if ch == 27: break - if ch == ord(' '): + if ch == ' ': res = cv2.inpaint(img_mark, mark, 3, cv2.INPAINT_TELEA) cv2.imshow('inpaint', res) - if ch == ord('r'): + if ch == 'r': img_mark[:] = img mark[:] = 0 sketch.show() diff --git a/samples/python/kalman.py b/samples/python/kalman.py index be361ff068..b4bc7844d0 100755 --- a/samples/python/kalman.py +++ b/samples/python/kalman.py @@ -86,11 +86,11 @@ if __name__ == "__main__": cv2.imshow("Kalman", img) - code = cv2.waitKey(100) + code = cv2.waitChar(100) if code != -1: break - if (code % 0x100) in [27, ord('q'), ord('Q')]: + if code in [27, 'q', 'Q']: break cv2.destroyWindow("Kalman") diff --git a/samples/python/kmeans.py b/samples/python/kmeans.py index b2e6b6618d..b0d4ff5843 100755 --- a/samples/python/kmeans.py +++ b/samples/python/kmeans.py @@ -44,7 +44,7 @@ if __name__ == '__main__': cv2.circle(img, (x, y), 1, c, -1) cv2.imshow('gaussian mixture', img) - ch = 0xFF & cv2.waitKey(0) + ch = cv2.waitChar(0) if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python/lappyr.py b/samples/python/lappyr.py index d8fde0f004..107c1f113e 100755 --- a/samples/python/lappyr.py +++ b/samples/python/lappyr.py @@ -70,5 +70,5 @@ if __name__ == '__main__': cv2.imshow('laplacian pyramid filter', res) - if cv2.waitKey(1) & 0xFF == 27: + if cv2.waitChar(1) == 27: break diff --git a/samples/python/lk_homography.py b/samples/python/lk_homography.py index 3b940e415f..1dd9da884c 100755 --- a/samples/python/lk_homography.py +++ b/samples/python/lk_homography.py @@ -90,17 +90,17 @@ class App: cv2.imshow('lk_homography', vis) - ch = 0xFF & cv2.waitKey(1) + ch = cv2.waitChar(1) if ch == 27: break - if ch == ord(' '): + if ch == ' ': self.frame0 = frame.copy() self.p0 = cv2.goodFeaturesToTrack(frame_gray, **feature_params) if self.p0 is not None: self.p1 = self.p0 self.gray0 = frame_gray self.gray1 = frame_gray - if ch == ord('r'): + if ch == 'r': self.use_ransac = not self.use_ransac diff --git a/samples/python/lk_track.py b/samples/python/lk_track.py index 8aa94fe642..a6e91df7dc 100755 --- a/samples/python/lk_track.py +++ b/samples/python/lk_track.py @@ -85,7 +85,7 @@ class App: self.prev_gray = frame_gray cv2.imshow('lk_track', vis) - ch = 0xFF & cv2.waitKey(1) + ch = cv2.waitChar(1) if ch == 27: break diff --git a/samples/python/morphology.py b/samples/python/morphology.py index be287d33d4..936dee62ea 100755 --- a/samples/python/morphology.py +++ b/samples/python/morphology.py @@ -79,15 +79,15 @@ if __name__ == '__main__': cv2.createTrackbar('iters', 'morphology', 1, 10, update) update() while True: - ch = 0xFF & cv2.waitKey() + ch = cv2.waitChar() if ch == 27: break - if ch == ord('1'): + if ch == '1': if PY3: cur_mode = next(modes) else: cur_mode = modes.next() - if ch == ord('2'): + if ch == '2': if PY3: cur_str_mode = next(str_modes) else: diff --git a/samples/python/mosse.py b/samples/python/mosse.py index 29a3a697f1..84981f7919 100755 --- a/samples/python/mosse.py +++ b/samples/python/mosse.py @@ -176,12 +176,12 @@ class App: self.rect_sel.draw(vis) cv2.imshow('frame', vis) - ch = cv2.waitKey(10) & 0xFF + ch = cv2.waitChar(10) if ch == 27: break - if ch == ord(' '): + if ch == ' ': self.paused = not self.paused - if ch == ord('c'): + if ch == 'c': self.trackers = [] diff --git a/samples/python/mouse_and_match.py b/samples/python/mouse_and_match.py index adbd8babee..0523f83851 100755 --- a/samples/python/mouse_and_match.py +++ b/samples/python/mouse_and_match.py @@ -78,6 +78,6 @@ if __name__ == '__main__': drag_start = None gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.imshow("gray",gray) - if (cv2.waitKey() & 255) == 27: + if cv2.waitChar() == 27: break cv2.destroyAllWindows() diff --git a/samples/python/mser.py b/samples/python/mser.py index 9d7a65c10f..3d8cecfe4d 100755 --- a/samples/python/mser.py +++ b/samples/python/mser.py @@ -37,6 +37,6 @@ if __name__ == '__main__': cv2.polylines(vis, hulls, 1, (0, 255, 0)) cv2.imshow('img', vis) - if 0xFF & cv2.waitKey(5) == 27: + if cv2.waitChar(5) == 27: break cv2.destroyAllWindows() diff --git a/samples/python/opt_flow.py b/samples/python/opt_flow.py index be85262c91..ddb4131d19 100755 --- a/samples/python/opt_flow.py +++ b/samples/python/opt_flow.py @@ -83,13 +83,13 @@ if __name__ == '__main__': cur_glitch = warp_flow(cur_glitch, flow) cv2.imshow('glitch', cur_glitch) - ch = 0xFF & cv2.waitKey(5) + ch = cv2.waitChar(5) if ch == 27: break - if ch == ord('1'): + if ch == '1': show_hsv = not show_hsv print('HSV flow visualization is', ['off', 'on'][show_hsv]) - if ch == ord('2'): + if ch == '2': show_glitch = not show_glitch if show_glitch: cur_glitch = img.copy() diff --git a/samples/python/peopledetect.py b/samples/python/peopledetect.py index 1cad95288b..01b79c7211 100755 --- a/samples/python/peopledetect.py +++ b/samples/python/peopledetect.py @@ -65,7 +65,7 @@ if __name__ == '__main__': draw_detections(img, found_filtered, 3) print('%d (%d) found' % (len(found_filtered), len(found))) cv2.imshow('img', img) - ch = 0xFF & cv2.waitKey() + ch = cv2.waitChar() if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python/plane_ar.py b/samples/python/plane_ar.py index 7f2969cdd8..260f2a6f87 100755 --- a/samples/python/plane_ar.py +++ b/samples/python/plane_ar.py @@ -75,10 +75,10 @@ class App: self.rect_sel.draw(vis) cv2.imshow('plane', vis) - ch = cv2.waitKey(1) & 0xFF - if ch == ord(' '): + ch = cv2.waitChar(1) + if ch == ' ': self.paused = not self.paused - if ch == ord('c'): + if ch == 'c': self.tracker.clear() if ch == 27: break diff --git a/samples/python/plane_tracker.py b/samples/python/plane_tracker.py index f66f3829c8..cdfb1c7aa6 100755 --- a/samples/python/plane_tracker.py +++ b/samples/python/plane_tracker.py @@ -170,10 +170,10 @@ class App: self.rect_sel.draw(vis) cv2.imshow('plane', vis) - ch = cv2.waitKey(1) & 0xFF - if ch == ord(' '): + ch = cv2.waitChar(1) + if ch == ' ': self.paused = not self.paused - if ch == ord('c'): + if ch == 'c': self.tracker.clear() if ch == 27: break diff --git a/samples/python/squares.py b/samples/python/squares.py index cc33144deb..5fdeb9d00d 100755 --- a/samples/python/squares.py +++ b/samples/python/squares.py @@ -49,7 +49,7 @@ if __name__ == '__main__': squares = find_squares(img) cv2.drawContours( img, squares, -1, (0, 255, 0), 3 ) cv2.imshow('squares', img) - ch = 0xFF & cv2.waitKey() + ch = cv2.waitChar() if ch == 27: break cv2.destroyAllWindows() diff --git a/samples/python/tst_scene_render.py b/samples/python/tst_scene_render.py index 992baf34f3..0e3e16845c 100644 --- a/samples/python/tst_scene_render.py +++ b/samples/python/tst_scene_render.py @@ -108,9 +108,9 @@ if __name__ == '__main__': img = render.getNextFrame() cv2.imshow('img', img) - ch = 0xFF & cv2.waitKey(3) + ch = cv2.waitChar(3) if ch == 27: break #import os #print (os.environ['PYTHONPATH']) - cv2.destroyAllWindows() \ No newline at end of file + cv2.destroyAllWindows() diff --git a/samples/python/turing.py b/samples/python/turing.py index f9926ba909..5f5672bd82 100755 --- a/samples/python/turing.py +++ b/samples/python/turing.py @@ -69,6 +69,6 @@ if __name__ == '__main__': vis = a.copy() draw_str(vis, (20, 20), 'frame %d' % frame_i) cv2.imshow('a', vis) - if 0xFF & cv2.waitKey(5) == 27: + if cv2.waitChar(5) == 27: break cv2.destroyAllWindows() diff --git a/samples/python/video.py b/samples/python/video.py index bc0348fd93..4157ecc202 100755 --- a/samples/python/video.py +++ b/samples/python/video.py @@ -217,10 +217,10 @@ if __name__ == '__main__': ret, img = cap.read() imgs.append(img) cv2.imshow('capture %d' % i, img) - ch = 0xFF & cv2.waitKey(1) + ch = cv2.waitChar(1) if ch == 27: break - if ch == ord(' '): + if ch == ' ': for i, img in enumerate(imgs): fn = '%s/shot_%d_%03d.bmp' % (shotdir, i, shot_idx) cv2.imwrite(fn, img) diff --git a/samples/python/video_threaded.py b/samples/python/video_threaded.py index 76d764b62d..102d93cb01 100755 --- a/samples/python/video_threaded.py +++ b/samples/python/video_threaded.py @@ -81,8 +81,8 @@ if __name__ == '__main__': else: task = DummyTask(process_frame(frame, t)) pending.append(task) - ch = 0xFF & cv2.waitKey(1) - if ch == ord(' '): + ch = cv2.waitChar(1) + if ch == ' ': threaded_mode = not threaded_mode if ch == 27: break diff --git a/samples/python/video_v4l2.py b/samples/python/video_v4l2.py index eed22d11b8..5f1392a37b 100644 --- a/samples/python/video_v4l2.py +++ b/samples/python/video_v4l2.py @@ -58,10 +58,10 @@ while True: cv2.putText(img, "FPS: {}".format(fps), (15, 80), font, 1.0, color) cv2.imshow("Video", img) - k = 0xFF & cv2.waitKey(1) + k = cv2.waitChar(1) if k == 27: break - elif k == ord("g"): + elif k == 'g': convert_rgb = not convert_rgb cap.set(cv2.CAP_PROP_CONVERT_RGB, convert_rgb) diff --git a/samples/python/watershed.py b/samples/python/watershed.py index 134e499301..fd7b61f7c5 100755 --- a/samples/python/watershed.py +++ b/samples/python/watershed.py @@ -56,19 +56,19 @@ class App: def run(self): while cv2.getWindowProperty('img', 0) != -1 or cv2.getWindowProperty('watershed', 0) != -1: - ch = 0xFF & cv2.waitKey(50) + ch = cv2.waitChar(50) if ch == 27: break - if ch >= ord('1') and ch <= ord('7'): - self.cur_marker = ch - ord('0') + if ch >= '1' and ch <= '7': + self.cur_marker = ch - '0' print('marker: ', self.cur_marker) - if ch == ord(' ') or (self.sketch.dirty and self.auto_update): + if ch == ' ' or (self.sketch.dirty and self.auto_update): self.watershed() self.sketch.dirty = False - if ch in [ord('a'), ord('A')]: + if ch in ['a', 'A']: self.auto_update = not self.auto_update print('auto_update if', ['off', 'on'][self.auto_update]) - if ch in [ord('r'), ord('R')]: + if ch in ['r', 'R']: self.markers[:] = 0 self.markers_vis[:] = self.img self.sketch.show() diff --git a/samples/tapi/bgfg_segm.cpp b/samples/tapi/bgfg_segm.cpp index 8b944d184a..b9a693c030 100644 --- a/samples/tapi/bgfg_segm.cpp +++ b/samples/tapi/bgfg_segm.cpp @@ -105,7 +105,7 @@ int main(int argc, const char** argv) imshow("foreground mask", fgmask); imshow("foreground image", fgimg); - char key = (char)waitKey(30); + char key = waitChar(30); switch (key) { diff --git a/samples/tapi/camshift.cpp b/samples/tapi/camshift.cpp index 324e073400..dbd0aabe7e 100644 --- a/samples/tapi/camshift.cpp +++ b/samples/tapi/camshift.cpp @@ -193,7 +193,7 @@ int main(int argc, const char ** argv) if (showHist) cv::imshow("Histogram", histimg); - char c = (char)cv::waitKey(10); + char c = cv::waitChar(10); if (c == 27) break; diff --git a/samples/tapi/clahe.cpp b/samples/tapi/clahe.cpp index b663b020bf..5b2fb56dcf 100644 --- a/samples/tapi/clahe.cpp +++ b/samples/tapi/clahe.cpp @@ -94,7 +94,7 @@ int main(int argc, char** argv) imshow("CLAHE", outframe); - char key = (char)waitKey(3); + char key = waitChar(3); if(key == 'o') imwrite(outfile, outframe); else if(key == 27) diff --git a/samples/tapi/hog.cpp b/samples/tapi/hog.cpp index db31396106..5e0d6aa385 100644 --- a/samples/tapi/hog.cpp +++ b/samples/tapi/hog.cpp @@ -255,7 +255,7 @@ void App::run() } } - handleKey((char)waitKey(3)); + handleKey(waitChar(3)); } } } diff --git a/samples/tapi/pyrlk_optical_flow.cpp b/samples/tapi/pyrlk_optical_flow.cpp index bb426cbf76..4b0fe1c4e6 100644 --- a/samples/tapi/pyrlk_optical_flow.cpp +++ b/samples/tapi/pyrlk_optical_flow.cpp @@ -182,7 +182,7 @@ int main(int argc, const char* argv[]) drawArrows(frameCopy, pts, nextPts, status, Scalar(255, 0, 0)); imshow("PyrLK [Sparse]", frameCopy); } - char key = (char)waitKey(10); + char key = waitChar(10); if (key == 27) break; diff --git a/samples/tapi/tvl1_optical_flow.cpp b/samples/tapi/tvl1_optical_flow.cpp index 5efa4e2352..3bc92b9db8 100644 --- a/samples/tapi/tvl1_optical_flow.cpp +++ b/samples/tapi/tvl1_optical_flow.cpp @@ -180,7 +180,7 @@ int main(int argc, const char* argv[]) imshow("tvl1 optical flow field", show_flow); } - char key = (char)waitKey(10); + char key = waitChar(10); if (key == 27) break; else if (key == 'm' || key == 'M') diff --git a/samples/tapi/ufacedetect.cpp b/samples/tapi/ufacedetect.cpp index 760ee7090d..d9de63944e 100644 --- a/samples/tapi/ufacedetect.cpp +++ b/samples/tapi/ufacedetect.cpp @@ -78,9 +78,9 @@ int main( int argc, const char** argv ) if( inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1) ) { - int c = inputName.empty() ? 0 : inputName[0] - '0'; - if(!capture.open(c)) - cout << "Capture from camera #" << c << " didn't work" << endl; + int camera = inputName.empty() ? 0 : inputName[0] - '0'; + if(!capture.open(camera)) + cout << "Capture from camera #" << camera << " didn't work" << endl; } else { @@ -105,7 +105,7 @@ int main( int argc, const char** argv ) detectAndDraw( frame, canvas, cascade, nestedCascade, scale, tryflip ); - int c = waitKey(10); + char c = waitChar(10); if( c == 27 || c == 'q' || c == 'Q' ) break; } @@ -128,7 +128,7 @@ int main( int argc, const char** argv ) char buf[1000+1]; while( fgets( buf, 1000, f ) ) { - int len = (int)strlen(buf), c; + int len = (int)strlen(buf); while( len > 0 && isspace(buf[len-1]) ) len--; buf[len] = '\0'; @@ -137,7 +137,7 @@ int main( int argc, const char** argv ) if( !image.empty() ) { detectAndDraw( image, canvas, cascade, nestedCascade, scale, tryflip ); - c = waitKey(0); + char c = waitChar(0); if( c == 27 || c == 'q' || c == 'Q' ) break; }