mirror of
https://github.com/bspeice/libcvautomation
synced 2025-07-01 22:07:38 -04:00
Add basic XTest functionality, clean up and refactor other sources
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
#Need to include the -Ilibcvautomation so that libcvautomation.h can find everything that it needs
|
||||
AM_CFLAGS = -Wall -O2 -I$(top_srcdir)/include #-I$(top_srcdir)/include/libcvautomation
|
||||
if USEOPENCV2
|
||||
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` -lopencv_imgproc -lopencv_core -lopencv_highgui
|
||||
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` -lopencv_imgproc -lopencv_core -lopencv_highgui -lXtst
|
||||
else
|
||||
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` `pkg-config --libs opencv`
|
||||
AM_LDFLAGS = -L../libcvautomation/.libs -lcvautomation `pkg-config --libs x11` `pkg-config --libs opencv` -lXtst
|
||||
endif
|
||||
|
||||
#Build only if we're building the examples
|
||||
bin_PROGRAMS = cva-match
|
||||
bin_PROGRAMS = cva-match cva-input
|
||||
cva_match_SOURCES = cva-match.c
|
||||
cva_input_SOURCES = cva-input.c
|
||||
|
102
examples/cva-input.c
Normal file
102
examples/cva-input.c
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: cva-input.c
|
||||
*
|
||||
* Description: This is an example program to demonstrate the XTest and XInput
|
||||
* functionality in libcvautomation
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 06/26/2012 09:20:20 AM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Bradlee Speice (), bspeice.nc@gmail.com
|
||||
* Organization:
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
void usage ();
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* Start getopt */
|
||||
while (1)
|
||||
{
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"usage", no_argument, 0, 'u'},
|
||||
/* Other valid values are "optional_argument"
|
||||
* and "required_argument" */
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int option_index = 0;
|
||||
opterr = 0;
|
||||
|
||||
int c = getopt_long (argc, argv, "hu", /* Use a single colon for required_argument,
|
||||
* double colon for optional_argument */
|
||||
long_options, &option_index);
|
||||
|
||||
/* We're done with parsing options */
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
usage();
|
||||
break;
|
||||
|
||||
case '?':
|
||||
/* Error routine */
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf( stderr, "Unknown option..." );
|
||||
exit(0);
|
||||
};
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* === FUNCTION ======================================================================
|
||||
* Name: usage
|
||||
* Description: I really shouldn't need to write this
|
||||
* =====================================================================================
|
||||
*/
|
||||
void usage ( )
|
||||
{
|
||||
fprintf( stderr, "\n\
|
||||
<program_name> version <program_version>\n\
|
||||
\n\
|
||||
Put your usage or help text here.\n\
|
||||
\n\
|
||||
Usage: \n\
|
||||
\n\
|
||||
\t-h, --help:\t\tDisplay this usage message.\n\
|
||||
\t-u, --usage:\t\tDisplay this usage message.\n\
|
||||
\n\
|
||||
If you have any questions, comments, concerns, email somebody else.\n" );
|
||||
|
||||
exit (0);
|
||||
|
||||
} /* ----- end of function usage ----- */
|
||||
|
@ -45,10 +45,13 @@ int main( int argc, char** argv )
|
||||
int search_method = CV_TM_SQDIFF;
|
||||
int useX = 0; /* bool useX = false; */
|
||||
int useCenter = 0;
|
||||
char *xDisplay;
|
||||
char *xDisplayLocation;
|
||||
Display *display;
|
||||
/* This line to suppress a compiler warning */
|
||||
display = NULL;
|
||||
|
||||
/* Set the default display */
|
||||
xDisplay = "";
|
||||
xDisplayLocation = "";
|
||||
|
||||
/* Set up the linked list for slave images */
|
||||
basic_list *list_head = NULL, *list_curr = NULL, *list_prev = NULL;
|
||||
@ -124,10 +127,12 @@ int main( int argc, char** argv )
|
||||
case 'x':
|
||||
if ( optarg != NULL ) {
|
||||
useX = 1;
|
||||
xDisplay = optarg;
|
||||
xDisplayLocation = optarg;
|
||||
display = XOpenDisplay(xDisplayLocation);
|
||||
} else {
|
||||
useX = 1;
|
||||
xDisplay = "";
|
||||
xDisplayLocation = "";
|
||||
display = XOpenDisplay(xDisplayLocation);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -163,9 +168,9 @@ int main( int argc, char** argv )
|
||||
sub_location = list_curr->fileName;
|
||||
|
||||
if (useX && useCenter)
|
||||
result_point = matchSubImage_X11_location_center( xDisplay, sub_location, search_method, tolerance );
|
||||
result_point = matchSubImage_X11_location_center( display, sub_location, search_method, tolerance );
|
||||
else if (useX && !useCenter)
|
||||
result_point = matchSubImage_X11_location( xDisplay, sub_location, search_method, tolerance );
|
||||
result_point = matchSubImage_X11_location( display, sub_location, search_method, tolerance );
|
||||
else if (!useX && useCenter)
|
||||
result_point = matchSubImage_location_center( root_location, sub_location, search_method, tolerance );
|
||||
else /* if (!useX && !useCenter) */
|
||||
@ -188,6 +193,10 @@ int main( int argc, char** argv )
|
||||
/* And free the final element */
|
||||
free(list_curr);
|
||||
|
||||
/* Clean up X */
|
||||
if (useX)
|
||||
XCloseDisplay(display);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user