Browse Source

Add two missing waitFor functions into the C library

Bradlee Speice 7 years ago
parent
commit
ea46db9106

+ 29
- 0
include/libcvautomation/libcvautomation-xtest.h View File

@@ -109,6 +109,12 @@ cvaPoint xte_waitForImage ( Display *displayLocation, IplImage *subImage, int se
109 109
 /* Wait for an image from file to show up on screen */
110 110
 cvaPoint xte_waitForImage_location ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout );
111 111
 
112
+/* Wait for an image to show up on screen, return the center point */
113
+cvaPoint xte_waitForImage_center( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout );
114
+
115
+/* Wait for an image from file to show up on screen, return the center point */
116
+cvaPoint xte_waitForImage_location_center( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout );
117
+
112 118
 /* Use one of the functions by command name */
113 119
 cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int mouseButton, int searchMethod, int tolerance, int timeout );
114 120
 
@@ -662,6 +668,7 @@ Wait for an image to show up on screen. For example, this can be used to make su
662 668
  * \param key The key to click as a string
663 669
  * \see \ref xtest_key_strings
664 670
  */
671
+
665 672
 /** \fn cvaPoint xte_waitForImage ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout );
666 673
  * \brief Wait for an image to show up on screen
667 674
  * \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
684 691
  * \see \ref libcvautomation_search_methods
685 692
  */
686 693
 
694
+/** \fn cvaPoint xte_waitForImage_center ( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout );
695
+ * \brief Wait for an image to show up on screen, return the center point
696
+ * \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.
697
+ * \param displayLocation The Display of which to search for an image
698
+ * \param subImage The sub image to search for
699
+ * \param searchMethod The search method to use when searching for \c subImage
700
+ * \param tolerance The tolerance to use when searching for \c tolerance
701
+ * \param timeout The time (in seconds) to search for the image
702
+ * \see \ref libcvautomation_search_methods
703
+ */
704
+
705
+/** \fn cvaPoint xte_waitForImage_location_center ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout );
706
+ * \brief Wait for an image from file to show up on screen, return the center point
707
+ * \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.
708
+ * \param displayLocation The Display of which to search for an image
709
+ * \param fileName The file to load an image from before searching
710
+ * \param searchMethod The search method to use when searching for \c subImage
711
+ * \param tolerance The tolerance to use when searching for \c tolerance
712
+ * \param timeout The time (in seconds) to search for the image
713
+ * \see \ref libcvautomation_search_methods
714
+ */
715
+
687 716
 /** \fn cvaPoint xte_commandString ( Display *displayLocation, char *commandString, int mouseButton, int searchMethod, int tolerance, int timeout );
688 717
  * \brief Execute a command where the command is coming from a string
689 718
  * \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

+ 92
- 2
libcvautomation/libcvautomation-xtest.c View File

@@ -774,6 +774,20 @@ cvaPoint xte_waitForImage ( Display *displayLocation, IplImage *subImage, int se
774 774
 	cvaPoint resultPoint;
775 775
 	resultPoint.x = resultPoint.y = -1;
776 776
 
777
+	/* The next conditional bears some discussion. Due to the way template matching works,
778
+	 * if the tolerance is INT_MAX or INT_MIN (depending on the search method) you will
779
+	 * *always* get a result back. Thus, while your intentions may be good, you kill
780
+	 * the point of waiting until an image appears. Please tune your tolerance values. */
781
+	if ((searchMethod == CV_TM_SQDIFF && tolerance == INT_MAX) ||
782
+		(searchMethod == CV_TM_SQDIFF_NORMED && tolerance == INT_MAX) ||
783
+		(searchMethod == CV_TM_CCORR && tolerance == INT_MIN) ||
784
+		(searchMethod == CV_TM_CCORR_NORMED && tolerance == INT_MIN) ||
785
+		(searchMethod == CV_TM_CCOEFF && tolerance == INT_MIN) ||
786
+		(searchMethod == CV_TM_CCOEFF_NORMED && tolerance == INT_MIN) )
787
+		
788
+		fprintf( stderr, "Passing a bad tolerance value to xte_waitForImage()...\n" );
789
+
790
+
777 791
 	int localTime = 0;
778 792
 	while ( localTime < timeout )
779 793
 	{
@@ -823,14 +837,90 @@ cvaPoint xte_waitForImage_location ( Display *displayLocation, const char *fileN
823 837
 		if ( resultPoint.x != -1 && resultPoint.y != -1 )
824 838
 			return resultPoint;
825 839
 
826
-		sleep( 1 );
827
-		localTime++;
840
+		sleep( 1 ); localTime++;
828 841
 	}
829 842
 
830 843
 	/* Return error, we couldn't find the image */
831 844
 	return resultPoint;
832 845
 }		/* -----  end of function xte_waitForImage_location  ----- */
833 846
 
847
+/* 
848
+ * ===  FUNCTION  ======================================================================
849
+ *         Name:  xte_waitForImage_center
850
+ *  Description:  Wait for an image to show up on screen, return the center point
851
+ * =====================================================================================
852
+ */
853
+cvaPoint xte_waitForImage_center( Display *displayLocation, IplImage *subImage, int searchMethod, int tolerance, int timeout )
854
+{
855
+	cvaPoint resultPoint;
856
+	resultPoint.x = resultPoint.y = -1;
857
+
858
+	/* The next conditional bears some discussion. Due to the way template matching works,
859
+	 * if the tolerance is INT_MAX or INT_MIN (depending on the search method) you will
860
+	 * *always* get a result back. Thus, while your intentions may be good, you kill
861
+	 * the point of waiting until an image appears. Please tune your tolerance values. */
862
+	if ((searchMethod == CV_TM_SQDIFF && tolerance == INT_MAX) ||
863
+		(searchMethod == CV_TM_SQDIFF_NORMED && tolerance == INT_MAX) ||
864
+		(searchMethod == CV_TM_CCORR && tolerance == INT_MIN) ||
865
+		(searchMethod == CV_TM_CCORR_NORMED && tolerance == INT_MIN) ||
866
+		(searchMethod == CV_TM_CCOEFF && tolerance == INT_MIN) ||
867
+		(searchMethod == CV_TM_CCOEFF_NORMED && tolerance == INT_MIN) )
868
+		
869
+		fprintf( stderr, "Passing a bad tolerance value to xte_waitForImage_center()...\n" );
870
+
871
+	int localTime = 0;
872
+	while ( localTime < timeout )
873
+	{
874
+		resultPoint = matchSubImage_X11_center( displayLocation, subImage, searchMethod, tolerance );
875
+
876
+		if ( resultPoint.x != -1 && resultPoint.y != -1 )
877
+			return resultPoint;
878
+
879
+		sleep( 1 ); localTime++;
880
+	}
881
+
882
+	/* Return error, we couldn't find the image */
883
+	return resultPoint;
884
+}		/* ----- end of function xte_waitForImage_center ----- */
885
+
886
+/* 
887
+ * ===  FUNCTION  ======================================================================
888
+ *         Name:  xte_waitForImage_location_center
889
+ *  Description:  Wait for an image from file to show up on screen, return the center point
890
+ * =====================================================================================
891
+ */
892
+cvaPoint xte_waitForImage_location_center ( Display *displayLocation, const char *fileName, int searchMethod, int tolerance, int timeout )
893
+{
894
+	cvaPoint resultPoint;
895
+	resultPoint.x = resultPoint.y = -1;
896
+
897
+	/* The next conditional bears some discussion. Due to the way template matching works,
898
+	 * if the tolerance is INT_MAX or INT_MIN (depending on the search method) you will
899
+	 * *always* get a result back. Thus, while your intentions may be good, you kill
900
+	 * the point of waiting until an image appears. Please tune your tolerance values. */
901
+	if ((searchMethod == CV_TM_SQDIFF && tolerance == INT_MAX) ||
902
+		(searchMethod == CV_TM_SQDIFF_NORMED && tolerance == INT_MAX) ||
903
+		(searchMethod == CV_TM_CCORR && tolerance == INT_MIN) ||
904
+		(searchMethod == CV_TM_CCORR_NORMED && tolerance == INT_MIN) ||
905
+		(searchMethod == CV_TM_CCOEFF && tolerance == INT_MIN) ||
906
+		(searchMethod == CV_TM_CCOEFF_NORMED && tolerance == INT_MIN) )
907
+		
908
+		fprintf( stderr, "Passing a bad tolerance value to xte_waitForImage_location_center()...\n" );
909
+
910
+	int localTime = 0;
911
+	while ( localTime < timeout )
912
+	{
913
+		resultPoint = matchSubImage_X11_location_center( displayLocation, fileName, searchMethod, tolerance );
914
+
915
+		if ( resultPoint.x != -1 && resultPoint.y != -1 )
916
+			return resultPoint;
917
+
918
+		sleep( 1 ); localTime++;
919
+	}
920
+
921
+	/* Return error, we couldn't find the image */
922
+	return resultPoint;
923
+}		/* -----  end of function xte_waitForImage_location_center  ----- */
834 924
 
835 925
 /* 
836 926
  * ===  FUNCTION  ======================================================================

Loading…
Cancel
Save