-
-
Notifications
You must be signed in to change notification settings - Fork 55.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing waitKey commands to be universal #7105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @terfendail Decided to leave this here. Because the sample is mainly using C functionality, and since waitChar is not available as C version. |
||
{ | ||
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,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 ); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,7 +453,7 @@ int main() | |
|
||
for(;;) | ||
{ | ||
char key = (char) waitKey(0); | ||
char key = waitChar(0); | ||
|
||
if(key == 'd' && flag3 == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @StevenPuttemans , @alalek don't you think that after making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @apavlenko, I guess I am missing what you are trying to say here. Could you explain where you would like in INT cast to ensure that we have no loss of values above 127? Or am I completely missing your point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I get your point and agree, but isn't it best to serve a solution that tends to mass? |
||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be left uninitialized. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we leave it unitialized, then OpenCV generates a warning of an uninitialized char, which is seen as an error due to the |
||
|
||
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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cases like here, I would also like to replace 27 by 'ESC' because it simply is more understandable that we are looking the value of the ESC key. If in some future those backend values would change, the code itself would not need updating.
What you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure whether there is a dedicated escape sequence or standard constant for ESC value. If we replace it with
'ESC'
it will be converted to (int)4543299 at least for VStudio.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked, it seems that on Ubuntu calling the code
yields the same output as you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way could be to define a global KEYSTROKE_ESC and use that ... but that might be a bit overkill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more investigation shows that ESC is not a printable char, and thus there is no sequence assigned to that. We will have to stick to 27 or define an enum for non printable ASCI values, which could be interesting to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could still use 27 for ESC value. Enum definition for ESC and a few other useful values only will be inconsistent while all other(and IMO most of) values included to the enum will be never used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Lets keep it at 27 then!