Add two missing waitFor functions into the C library

Release_2.0_Bugfix
Bradlee Speice 2012-08-17 12:06:47 -04:00
parent 4b60fbf922
commit ea46db9106
2 changed files with 121 additions and 2 deletions

View File

@ -109,6 +109,12 @@ cvaPoint xte_waitForImage ( Display *displayLocation, IplImage *subImage, int se
/* Wait for an image from file to show up on screen */
cvaPoint xte_waitForImage_location ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout );
/* Wait for an image to show up on screen, return the center point */
cvaPoint xte_waitForImage_center( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout );
/* Wait for an image from file to show up on screen, return the center point */
cvaPoint xte_waitForImage_location_center( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout );
/* Use one of the functions by command name */
cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int mouseButton, int searchMethod, int tolerance, int timeout );
@ -662,6 +668,7 @@ Wait for an image to show up on screen. For example, this can be used to make su
* \param key The key to click as a string
* \see \ref xtest_key_strings
*/
/** \fn cvaPoint xte_waitForImage ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout );
* \brief Wait for an image to show up on screen
* \details This method allows you to search for an image on screen and wait for it to show up - this way you can make sure an image exists, and then respond to it. Also makes error checking easy.
@ -684,6 +691,28 @@ Wait for an image to show up on screen. For example, this can be used to make su
* \see \ref libcvautomation_search_methods
*/
/** \fn cvaPoint xte_waitForImage_center ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout );
* \brief Wait for an image to show up on screen, return the center point
* \details This method allows you to search for an image on screen and wait for it to show up - this way you can make sure an image exists, and then respond to it. Also makes error checking easy.
* \param displayLocation The Display of which to search for an image
* \param subImage The sub image to search for
* \param searchMethod The search method to use when searching for \c subImage
* \param tolerance The tolerance to use when searching for \c tolerance
* \param timeout The time (in seconds) to search for the image
* \see \ref libcvautomation_search_methods
*/
/** \fn cvaPoint xte_waitForImage_location_center ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout );
* \brief Wait for an image from file to show up on screen, return the center point
* \details This method allows you to search for an image on screen and wait for it to show up - this way you can make sure an image exists, and then respond to it. Also makes error checking easy.
* \param displayLocation The Display of which to search for an image
* \param fileName The file to load an image from before searching
* \param searchMethod The search method to use when searching for \c subImage
* \param tolerance The tolerance to use when searching for \c tolerance
* \param timeout The time (in seconds) to search for the image
* \see \ref libcvautomation_search_methods
*/
/** \fn cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int mouseButton, int searchMethod, int tolerance, int timeout );
* \brief Execute a command where the command is coming from a string
* \details This function allows you to input a command to libcvautomation from a string. For example, to click a mouse button, you would use the \c command 'mouseclick'. Please note that some <tt>command</tt>s may need arguments to the string, and some may use function arguments. See \ref xtest_command_strings for a full list of command and arguments

View File

@ -774,6 +774,20 @@ cvaPoint xte_waitForImage ( Display *displayLocation, IplImage *subImage, int se
cvaPoint resultPoint;
resultPoint.x = resultPoint.y = -1;
/* The next conditional bears some discussion. Due to the way template matching works,
* if the tolerance is INT_MAX or INT_MIN (depending on the search method) you will
* *always* get a result back. Thus, while your intentions may be good, you kill
* the point of waiting until an image appears. Please tune your tolerance values. */
if ((searchMethod == CV_TM_SQDIFF && tolerance == INT_MAX) ||
(searchMethod == CV_TM_SQDIFF_NORMED && tolerance == INT_MAX) ||
(searchMethod == CV_TM_CCORR && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCORR_NORMED && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCOEFF && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCOEFF_NORMED && tolerance == INT_MIN) )
fprintf( stderr, "Passing a bad tolerance value to xte_waitForImage()...\n" );
int localTime = 0;
while ( localTime < timeout )
{
@ -823,14 +837,90 @@ cvaPoint xte_waitForImage_location ( Display *displayLocation, const char *fileN
if ( resultPoint.x != -1 && resultPoint.y != -1 )
return resultPoint;
sleep( 1 );
localTime++;
sleep( 1 ); localTime++;
}
/* Return error, we couldn't find the image */
return resultPoint;
} /* ----- end of function xte_waitForImage_location ----- */
/*
* === FUNCTION ======================================================================
* Name: xte_waitForImage_center
* Description: Wait for an image to show up on screen, return the center point
* =====================================================================================
*/
cvaPoint xte_waitForImage_center( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout )
{
cvaPoint resultPoint;
resultPoint.x = resultPoint.y = -1;
/* The next conditional bears some discussion. Due to the way template matching works,
* if the tolerance is INT_MAX or INT_MIN (depending on the search method) you will
* *always* get a result back. Thus, while your intentions may be good, you kill
* the point of waiting until an image appears. Please tune your tolerance values. */
if ((searchMethod == CV_TM_SQDIFF && tolerance == INT_MAX) ||
(searchMethod == CV_TM_SQDIFF_NORMED && tolerance == INT_MAX) ||
(searchMethod == CV_TM_CCORR && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCORR_NORMED && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCOEFF && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCOEFF_NORMED && tolerance == INT_MIN) )
fprintf( stderr, "Passing a bad tolerance value to xte_waitForImage_center()...\n" );
int localTime = 0;
while ( localTime < timeout )
{
resultPoint = matchSubImage_X11_center( displayLocation, subImage, searchMethod, tolerance );
if ( resultPoint.x != -1 && resultPoint.y != -1 )
return resultPoint;
sleep( 1 ); localTime++;
}
/* Return error, we couldn't find the image */
return resultPoint;
} /* ----- end of function xte_waitForImage_center ----- */
/*
* === FUNCTION ======================================================================
* Name: xte_waitForImage_location_center
* Description: Wait for an image from file to show up on screen, return the center point
* =====================================================================================
*/
cvaPoint xte_waitForImage_location_center ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout )
{
cvaPoint resultPoint;
resultPoint.x = resultPoint.y = -1;
/* The next conditional bears some discussion. Due to the way template matching works,
* if the tolerance is INT_MAX or INT_MIN (depending on the search method) you will
* *always* get a result back. Thus, while your intentions may be good, you kill
* the point of waiting until an image appears. Please tune your tolerance values. */
if ((searchMethod == CV_TM_SQDIFF && tolerance == INT_MAX) ||
(searchMethod == CV_TM_SQDIFF_NORMED && tolerance == INT_MAX) ||
(searchMethod == CV_TM_CCORR && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCORR_NORMED && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCOEFF && tolerance == INT_MIN) ||
(searchMethod == CV_TM_CCOEFF_NORMED && tolerance == INT_MIN) )
fprintf( stderr, "Passing a bad tolerance value to xte_waitForImage_location_center()...\n" );
int localTime = 0;
while ( localTime < timeout )
{
resultPoint = matchSubImage_X11_location_center( displayLocation, fileName, searchMethod, tolerance );
if ( resultPoint.x != -1 && resultPoint.y != -1 )
return resultPoint;
sleep( 1 ); localTime++;
}
/* Return error, we couldn't find the image */
return resultPoint;
} /* ----- end of function xte_waitForImage_location_center ----- */
/*
* === FUNCTION ======================================================================