// LaserPointerServer.cpp : Defines the entry point for the console application.
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifndef __APPLE__
#include <GL/gl.h>
#include <GL/glut.h>
#else
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif
#include <AR/gsub.h>
#include <AR/video.h>
#include <AR/param.h>
#include <AR/ar.h>
/* set up the video format globals */
#ifdef _WIN32
char *vconf = "Data\\WDM_camera_flipV.xml";
#else
char *vconf = "";
#endif
int xsize, ysize;
int count = 0;
char *cparam_name = "Data/camera_para.dat";
ARParam cparam;
static void init(void);
static void cleanup(void);
static void keyEvent( unsigned char key, int x, int y);
static void mainLoop(void);
int main(int argc, char **argv)
{
//initialize applications
glutInit(&argc, argv);
init();
//start video capture
arVideoCapStart();
printf("%d", sizeof(ARUint8));
//start the main event loop
argMainLoop( NULL, keyEvent, mainLoop );
return 0;
}
static void keyEvent( unsigned char key, int x, int y)
{
/* quit if the ESC key is pressed */
if( key == 0x1b ) {
printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
cleanup();
exit(0);
}
}
/* main loop */
static void mainLoop(void)
{
ARUint8 *dataPtr;
ARUint8 winner = 0;
int winX = 0, winY = 0;
float fwinX = 0, fwinY = 0;
/* grab a video frame */
if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
arUtilSleep(2);
return;
}
if( count == 0 ) arUtilTimerReset();
count++;
/*
Basic search for red laser point. The config.h file in the ARToolKit
gives a pixelformat of BGRA for windows, so searching for the red value
means finding the 3rd value in every block of 4. This is tested against
the current highest value, and if it is higher, it is used for the new
mouse coordinates.
*/
for (int i = 0; i < xsize*ysize; i++)
{
if (dataPtr[(i*4)+2] > winner)
{
winner = dataPtr[(i*4)+2];
winY = i/xsize;
winX = i%xsize;
}
}
/*
Checks the value for a threshold value. This is to stop
a value that is not the laser pointer from being used if
the laser pointer is off. It is configured to a static
screen resolution of 1024x768. fwinX and Y are used as
floats to avoid rounding errors in the ratio adjustment.
*/
if (winner > 250)
{
fwinX = winX * (1024.0 / (float)xsize);
fwinY = winY * (768.0 / (float)ysize);
SetCursorPos(fwinX, fwinY);
}
/*draw the video*/
argDrawMode2D();
argDispImage( dataPtr, 0,0 );
/* capture the next video frame */
arVideoCapNext();
/*swap the graphics buffers*/
argSwapBuffers();
}
static void init( void )
{
ARParam wparam;
/* open the video path */
if( arVideoOpen( vconf ) < 0 ) exit(0);
/* find the size of the window */
if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
/* set the initial camera parameters */
if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
printf("Camera parameter load error !!\n");
exit(0);
}
arParamChangeSize( &wparam, xsize, ysize, &cparam );
/* open the graphics window */
argInit( &cparam, 1.0, 0, 0, 0, 0 );
}
/* cleanup function called when program exits */
static void cleanup(void)
{
arVideoCapStop();
arVideoClose();
argCleanup();
}