Skip to content

Commit

Permalink
Merge pull request opencv#7866 from alalek:update_waitKey
Browse files Browse the repository at this point in the history
  • Loading branch information
vpisarev committed Dec 16, 2016
2 parents 2575c54 + f933335 commit bc7cbc1
Show file tree
Hide file tree
Showing 78 changed files with 167 additions and 155 deletions.
10 changes: 5 additions & 5 deletions apps/createsamples/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -1672,12 +1672,12 @@ 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 );
cvFree( &file.vector );
}
fclose( file.input );
}
}
}
2 changes: 1 addition & 1 deletion apps/interactive-calibration/calibPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > pr
for (std::vector<cv::Ptr<FrameProcessor> >::iterator it = processors.begin(); it != processors.end(); ++it)
processedFrame = (*it)->processFrame(processedFrame);
cv::imshow(mainWindowName, processedFrame);
int key = cv::waitKey(CAP_DELAY);
char key = (char)cv::waitKey(CAP_DELAY);

if(key == 27) // esc
return Finished;
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorials/imgproc/imgtrans/remap/remap.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ Explanation
while( true )
{
/// Each 1 sec. Press ESC to exit the program
int c = waitKey( 1000 );
char c = (char)waitKey( 1000 );

if( (char)c == 27 )
if( c == 27 )
{ break; }

/// Update map_x & map_y. Then apply remap
Expand Down
1 change: 1 addition & 0 deletions doc/tutorials/imgproc/pyramids/pyramids.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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')**
Expand Down
9 changes: 9 additions & 0 deletions modules/highgui/include/opencv2/highgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ CV_EXPORTS_W void destroyAllWindows();

CV_EXPORTS_W int startWindowThread();

/** @brief Similar to #waitKey, but returns full key code.
@note
Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc
*/
CV_EXPORTS_W int waitKeyEx(int delay = 0);

/** @brief Waits for a pressed key.
The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay
Expand Down
17 changes: 16 additions & 1 deletion modules/highgui/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,26 @@ double cv::getWindowProperty(const String& winname, int prop_id)
return cvGetWindowProperty(winname.c_str(), prop_id);
}

int cv::waitKey(int delay)
int cv::waitKeyEx(int delay)
{
return cvWaitKey(delay);
}

int cv::waitKey(int delay)
{
int code = waitKeyEx(delay);
#ifndef HAVE_WINRT
static int use_legacy = -1;
if (use_legacy < 0)
{
use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0;
}
if (use_legacy > 0)
return code;
#endif
return code & 0xff;
}

int cv::createTrackbar(const String& trackbarName, const String& winName,
int* value, int count, TrackbarCallback callback,
void* userdata)
Expand Down
6 changes: 3 additions & 3 deletions modules/python/test/tst_scene_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def resetTime(self):
img = render.getNextFrame()
cv2.imshow('img', img)

ch = 0xFF & cv2.waitKey(3)
if ch == 27:
ch = cv2.waitKey(3)
if ch == 27:
break
cv2.destroyAllWindows()
cv2.destroyAllWindows()
2 changes: 1 addition & 1 deletion samples/cpp/3calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(0);
if( c == 27 || c == 'q' || c == 'Q' )
break;
}
Expand Down
8 changes: 4 additions & 4 deletions samples/cpp/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ int main( int argc, char** argv )
}

imshow("Image View", view);
int key = 0xff & waitKey(capture.isOpened() ? 50 : 500);
char key = (char)waitKey(capture.isOpened() ? 50 : 500);

if( (key & 255) == 27 )
if( key == 27 )
break;

if( key == 'u' && mode == CALIBRATED )
Expand Down Expand Up @@ -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 = (char)waitKey();
if( c == 27 || c == 'q' || c == 'Q' )
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/cloning_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ int main()

for(;;)
{
char key = (char) waitKey(0);
char key = (char)waitKey(0);

if(key == 'd' && flag3 == 0)
{
Expand Down
3 changes: 1 addition & 2 deletions samples/cpp/convexhull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ int main( int argc, char** argv )

for(;;)
{
char key;
int i, count = (unsigned)rng%100 + 1;

vector<Point> points;
Expand Down Expand Up @@ -58,7 +57,7 @@ int main( int argc, char** argv )

imshow("hull", img);

key = (char)waitKey();
char key = (char)waitKey();
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
break;
}
Expand Down
4 changes: 2 additions & 2 deletions samples/cpp/detect_mser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ static void DrawOpenGLMSER(Mat img, Mat result)
for (;;)
{
updateWindow("OpenGL");
int key = waitKey(40);
if ((key & 0xff) == 27)
char key = (char)waitKey(40);
if (key == 27)
break;
if (key == 0x20)
rotateEnable = !rotateEnable;
Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/distrans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(0);

if( c == 27 )
break;
Expand Down
12 changes: 6 additions & 6 deletions samples/cpp/facedetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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 = (char)waitKey(10);
if( c == 27 || c == 'q' || c == 'Q' )
break;
}
Expand All @@ -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';
Expand All @@ -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 = (char)waitKey(0);
if( c == 27 || c == 'q' || c == 'Q' )
break;
}
Expand Down
6 changes: 3 additions & 3 deletions samples/cpp/ffilldemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(0);
if( c == 27 )
{
cout << "Exiting ...\n";
break;
}
switch( (char)c )
switch( c )
{
case 'c':
if( isColor )
Expand Down
4 changes: 2 additions & 2 deletions samples/cpp/grabcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ int main( int argc, char** argv )

for(;;)
{
int c = waitKey(0);
switch( (char) c )
char c = (char)waitKey(0);
switch( c )
{
case '\x1b':
cout << "Exiting ..." << endl;
Expand Down
4 changes: 2 additions & 2 deletions samples/cpp/laplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(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;
}

Expand Down
14 changes: 6 additions & 8 deletions samples/cpp/morphology2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(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;
}

Expand Down
4 changes: 2 additions & 2 deletions samples/cpp/pca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey();

return 0;
}
6 changes: 3 additions & 3 deletions samples/cpp/phase_corr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(int, char* [])
{
VideoCapture video(0);
Mat frame, curr, prev, curr64f, prev64f, hann;
int key = 0;
char key;

do
{
Expand Down Expand Up @@ -37,10 +37,10 @@ int main(int, char* [])
}

imshow("phase shift", frame);
key = waitKey(2);
key = (char)waitKey(2);

prev = curr.clone();
} while((char)key != 27); // Esc to exit...
} while(key != 27); // Esc to exit...

return 0;
}
2 changes: 1 addition & 1 deletion samples/cpp/points_classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ int main()

for(;;)
{
uchar key = (uchar)waitKey();
char key = (char)waitKey();

if( key == 27 ) break;

Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/segment_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(30);
if( keycode == 27 )
break;
if( keycode == ' ' )
Expand Down
6 changes: 3 additions & 3 deletions samples/cpp/select3dobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(30);
if( c == 27 )
{
nobjpt = 0;
}
Expand Down Expand Up @@ -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 = (char)waitKey(imageList.empty() && !box.empty() ? 30 : 300);
if( c == 'q' || c == 'Q' )
break;
if( c == '\r' || c == '\n' )
Expand Down
2 changes: 1 addition & 1 deletion samples/cpp/smiledetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char)waitKey(10);
if( c == 27 || c == 'q' || c == 'Q' )
break;
}
Expand Down
Loading

0 comments on commit bc7cbc1

Please sign in to comment.