| ARToolKit | Mailing List Archive |
|
| From: | "Yuan Miaolong" <smayml@n .........> | Received: | May 13, 2003 |
| To | artoolkit@h .................. | ||
| Subject: | Intel OpenCV for ARToolKit | ||
Dear All, Has anyone used Intel Open CV library for ARToolkit? I would like to use some functions of Open CV library into ARToolkit, anyone has such experience and can give me some advice? Best Regards Yuan Miaolong |
|||
| From: | Hendrik Wendler <wendler@s ...................> | Received: | May 14, 2003 |
| To | ART liste <artoolkit@h ..................> | ||
| Subject: | Re: Intel OpenCV for ARToolKit | ||
This is a multi-part message in MIME format.
--------------040008030009010909080005
Content-Type:
Content-Transfer-Encoding: 8bit
if was completely easy as you would exspect.
look at this codesnippet:
(modifies simple example (for linux (for YUV420 cams like phillips
webcams)) )
the sampel makes no sense right now,
but you could put any functionality
in balldetect()
regards,
hendrik
Am Die, 2003-05-13 um 06.48 schrieb Yuan Miaolong:
> Dear All,
>
> Has anyone used Intel Open CV library for ARToolkit? I would like to use some functions of Open CV library into ARToolkit, anyone has such experience and can give me some advice?
>
> Best Regards
> Yuan Miaolong
--------------040008030009010909080005
Content-Type: text/x-csrc; charset=windows-1252;
name="simpleTe.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="simpleTe.c"
#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>
/*todo hw -----------------------------------------------------
- get channel number 3/4
-------------------------------------------------------------*/
//opencv stuff
#include <cv.hpp>
#include <math.h>
void ballDetect();
CvImage *image;
CvSize *size;
int channels, maxlength;
IplImage *m_pEdge; // result of canny edge detection
IplImage *m_pGray; // result of conversion to grayscale
IplImage *img; // tmp prescale gray
IplImage *pyr; // tmp afterscale gray
int canny_thres;
CvPoint myCenter;
ARUint8 *dataPtr;
char *vconf = "-dev=/dev/video0 -channel=0";
int xsize, ysize;
int thresh = 100;
int count = 0;
char *cparam_name = "Data/camera_para.dat";
ARParam cparam;
char *patt_name = "Data/patt.hiro";
int patt_id;
double patt_width = 80.0;
double patt_center[2] = {0.0, 0.0};
double patt_trans[3][4];
static void init(void);
static void cleanup(void);
static void keyEvent( unsigned char key, int x, int y);
static void mainLoop(void);
static void draw( void );
main(int argc, char *argv[])
{
init();
arVideoCapStart();
argMainLoop( NULL, keyEvent, mainLoop );
}
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;
ARMarkerInfo *marker_info;
int marker_num;
int j, k;
/* grab a vide frame */
if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
arUtilSleep(2);
return;
}
if( count == 0 ) arUtilTimerReset();
count++;
/* detect the markers in the video frame */
if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
cleanup();
exit(0);
}
//ballDetect();
//argDrawMode2D();
argDispImage( dataPtr, 0,0 );
arVideoCapNext();
/* check for object visibility */
k = -1;
for( j = 0; j < marker_num; j++ ) {
if( patt_id == marker_info[j].id ) {
if( k == -1 ) k = j;
else if( marker_info[k].cf < marker_info[j].cf ) k = j;
}
}
if( k == -1 ) {
argSwapBuffers();
return;
}
/* get the transformation between the marker and the real camera */
arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
draw();
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 );
arInitCparam( &cparam );
printf("*** Camera Parameter ***\n");
arParamDisp( &cparam );
if( (patt_id=arLoadPatt(patt_name)) < 0 ) {
printf("pattern load error !!\n");
exit(0);
}
/* open the graphics window */
#ifndef __APPLE__
argInit( &cparam, 1.0, 0, 0, 0, 0 );
#else
argInit( &cparam, 2.0, 0, 0, 0, 0 );
#endif
//--------------------------------------------------------------------------
//hwcode: OpenCV init
m_pGray = m_pEdge = NULL;
image = new CvImage();
size = new CvSize();
size->width = xsize;
size->height = ysize;
channels = 3;
canny_thres = 50;
cvInitImageHeader( image, *size, IPL_DEPTH_8U, channels );
m_pGray = cvCreateImage( *size, IPL_DEPTH_8U , 1);
img = cvCreateImage( *size,
image->byte_per_pixel()*8/image->nChannels,
1 );
pyr = cvCreateImage( cvSize(size->width/2, size->height/2),
image->byte_per_pixel()*8/image->nChannels,
1 );
printf("CvImage created (x,y) = (%d,%d)\n", size->width, size->height);
//--------------------------------------------------------------------------
}
/* cleanup function called when program exits */
static void cleanup(void)
{
arVideoCapStop();
arVideoClose();
argCleanup();
cvReleaseImage(&m_pGray);
cvReleaseImage(&m_pEdge);
cvReleaseImage(&img);
cvReleaseImage(&pyr);
}
static void draw( void )
{
double gl_para[16];
GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_flash_shiny[] = {50.0};
GLfloat light_position[] = {100.0,-200.0,200.0,0.0};
GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};
argDrawMode3D();
argDraw3dCamera( 0, 0 );
glClearDepth( 1.0 );
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
/* load the camera transformation matrix */
argConvGlpara(patt_trans, gl_para);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd( gl_para );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMatrixMode(GL_MODELVIEW);
glTranslatef( 0.0, 0.0, 25.0 );
glutSolidCube(50.0);
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );
}
void ballDetect()
{
cvSetImageData( image, dataPtr, size->width * channels );
//printf("channels %d\n", channels);
canny_thres = 100;
//cvCvtColor( image ,m_pGray, CV_RGB2GRAY);
//cvCanny( m_pGray,m_pGray, canny_thres, canny_thres, 3 );
//cvCvtColor( m_pGray ,image, CV_GRAY2RGB);
}
--------------040008030009010909080005
Content-Type: text/x-makefile; charset=windows-1252;
name="Makefile.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Makefile.txt"
INC_DIR= ../../include
LIB_DIR= ../../lib
BIN_DIR= ../../bin
LDFLAG=-L/usr/X11R6/lib -L$(LIB_DIR)
LIBS= -lARgsub -lARvideo -lAR -lglut -lGLU -lGL -lXi -lXmu -lX11 -lm -lopencv -lcvaux
CFLAG= -O -I/usr/X11R6/include -I$(INC_DIR) -I/usr/local/include/opencv
OBJS =
HEADDERS =
all: $(BIN_DIR)/simpleTest
$(BIN_DIR)/simpleTest: simpleTest.o $(OBJS)
g++ -o $(BIN_DIR)/simpleTest simpleTest.o $(OBJS) $(LDFLAG) $(LIBS)
simpleTest.o: simpleTest.c $(HEADDERS)
g++ -c $(CFLAG) simpleTest.c
clean:
rm -f *.o
rm -f $(BIN_DIR)/simpleTest
allclean:
rm -f *.o
rm -f $(BIN_DIR)/simpleTest
rm -f Makefile
--------------040008030009010909080005--
|
|||
| From: | Hendrik Wendler <wendler@s ...................> | Received: | May 14, 2003 |
| To | ART liste <artoolkit@h ..................> | ||
| Subject: | Re: Intel OpenCV for ARToolKit | ||
This is a multi-part message in MIME format.
--------------040602030709070402070503
Content-Type:
Content-Transfer-Encoding: 8bit
if was completely easy as you would exspect.
look at this codesnippet:
(modifies simple example (for linux (for YUV420 cams like phillips
webcams)) )
the sampel makes no sense right now,
but you could put any functionality
in balldetect()
regards,
hendrik
Am Die, 2003-05-13 um 06.48 schrieb Yuan Miaolong:
> Dear All,
>
> Has anyone used Intel Open CV library for ARToolkit? I would like to use some functions of Open CV library into ARToolkit, anyone has such experience and can give me some advice?
>
> Best Regards
> Yuan Miaolong
--------------040602030709070402070503
Content-Type: text/x-csrc; charset=windows-1252;
name="simpleTe.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="simpleTe.c"
#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>
/*todo hw -----------------------------------------------------
- get channel number 3/4
-------------------------------------------------------------*/
//opencv stuff
#include <cv.hpp>
#include <math.h>
void ballDetect();
CvImage *image;
CvSize *size;
int channels, maxlength;
IplImage *m_pEdge; // result of canny edge detection
IplImage *m_pGray; // result of conversion to grayscale
IplImage *img; // tmp prescale gray
IplImage *pyr; // tmp afterscale gray
int canny_thres;
CvPoint myCenter;
ARUint8 *dataPtr;
char *vconf = "-dev=/dev/video0 -channel=0";
int xsize, ysize;
int thresh = 100;
int count = 0;
char *cparam_name = "Data/camera_para.dat";
ARParam cparam;
char *patt_name = "Data/patt.hiro";
int patt_id;
double patt_width = 80.0;
double patt_center[2] = {0.0, 0.0};
double patt_trans[3][4];
static void init(void);
static void cleanup(void);
static void keyEvent( unsigned char key, int x, int y);
static void mainLoop(void);
static void draw( void );
main(int argc, char *argv[])
{
init();
arVideoCapStart();
argMainLoop( NULL, keyEvent, mainLoop );
}
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;
ARMarkerInfo *marker_info;
int marker_num;
int j, k;
/* grab a vide frame */
if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
arUtilSleep(2);
return;
}
if( count == 0 ) arUtilTimerReset();
count++;
/* detect the markers in the video frame */
if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
cleanup();
exit(0);
}
//ballDetect();
//argDrawMode2D();
argDispImage( dataPtr, 0,0 );
arVideoCapNext();
/* check for object visibility */
k = -1;
for( j = 0; j < marker_num; j++ ) {
if( patt_id == marker_info[j].id ) {
if( k == -1 ) k = j;
else if( marker_info[k].cf < marker_info[j].cf ) k = j;
}
}
if( k == -1 ) {
argSwapBuffers();
return;
}
/* get the transformation between the marker and the real camera */
arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
draw();
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 );
arInitCparam( &cparam );
printf("*** Camera Parameter ***\n");
arParamDisp( &cparam );
if( (patt_id=arLoadPatt(patt_name)) < 0 ) {
printf("pattern load error !!\n");
exit(0);
}
/* open the graphics window */
#ifndef __APPLE__
argInit( &cparam, 1.0, 0, 0, 0, 0 );
#else
argInit( &cparam, 2.0, 0, 0, 0, 0 );
#endif
//--------------------------------------------------------------------------
//hwcode: OpenCV init
m_pGray = m_pEdge = NULL;
image = new CvImage();
size = new CvSize();
size->width = xsize;
size->height = ysize;
channels = 3;
canny_thres = 50;
cvInitImageHeader( image, *size, IPL_DEPTH_8U, channels );
m_pGray = cvCreateImage( *size, IPL_DEPTH_8U , 1);
img = cvCreateImage( *size,
image->byte_per_pixel()*8/image->nChannels,
1 );
pyr = cvCreateImage( cvSize(size->width/2, size->height/2),
image->byte_per_pixel()*8/image->nChannels,
1 );
printf("CvImage created (x,y) = (%d,%d)\n", size->width, size->height);
//--------------------------------------------------------------------------
}
/* cleanup function called when program exits */
static void cleanup(void)
{
arVideoCapStop();
arVideoClose();
argCleanup();
cvReleaseImage(&m_pGray);
cvReleaseImage(&m_pEdge);
cvReleaseImage(&img);
cvReleaseImage(&pyr);
}
static void draw( void )
{
double gl_para[16];
GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_flash[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_flash_shiny[] = {50.0};
GLfloat light_position[] = {100.0,-200.0,200.0,0.0};
GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};
argDrawMode3D();
argDraw3dCamera( 0, 0 );
glClearDepth( 1.0 );
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
/* load the camera transformation matrix */
argConvGlpara(patt_trans, gl_para);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd( gl_para );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMatrixMode(GL_MODELVIEW);
glTranslatef( 0.0, 0.0, 25.0 );
glutSolidCube(50.0);
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH_TEST );
}
void ballDetect()
{
cvSetImageData( image, dataPtr, size->width * channels );
//printf("channels %d\n", channels);
canny_thres = 100;
//cvCvtColor( image ,m_pGray, CV_RGB2GRAY);
//cvCanny( m_pGray,m_pGray, canny_thres, canny_thres, 3 );
//cvCvtColor( m_pGray ,image, CV_GRAY2RGB);
}
--------------040602030709070402070503
Content-Type: text/x-makefile; charset=windows-1252;
name="Makefile.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Makefile.txt"
INC_DIR= ../../include
LIB_DIR= ../../lib
BIN_DIR= ../../bin
LDFLAG=-L/usr/X11R6/lib -L$(LIB_DIR)
LIBS= -lARgsub -lARvideo -lAR -lglut -lGLU -lGL -lXi -lXmu -lX11 -lm -lopencv -lcvaux
CFLAG= -O -I/usr/X11R6/include -I$(INC_DIR) -I/usr/local/include/opencv
OBJS =
HEADDERS =
all: $(BIN_DIR)/simpleTest
$(BIN_DIR)/simpleTest: simpleTest.o $(OBJS)
g++ -o $(BIN_DIR)/simpleTest simpleTest.o $(OBJS) $(LDFLAG) $(LIBS)
simpleTest.o: simpleTest.c $(HEADDERS)
g++ -c $(CFLAG) simpleTest.c
clean:
rm -f *.o
rm -f $(BIN_DIR)/simpleTest
allclean:
rm -f *.o
rm -f $(BIN_DIR)/simpleTest
rm -f Makefile
--------------040602030709070402070503--
|
|||