[vtkusers] Import image from ARToolKit

Francesco Caruso guernika_devel at yahoo.it
Thu Apr 1 05:55:30 EST 2004


Hello,

i can't display image grabbed by ARToolKit...

ARToolKit grab image and store it in a vector of unsigned char "dataPtr".
i tried to import and show it  but the routine crashes due to an error 
of access violation.
i think my mistake is how to pass the dataPtr to vtkImageImport...

please, help!

here are the sources...

static void vtkInit( void )
{
    renWin        =    vtkRenderWindow::New();
    ren              =    vtkRenderer::New();
    importer      =    vtkImageImport::New();
    imActor       =    vtkOpenGLImageActor::New();

    importer->SetWholeExtent(0, 319, 0, 239, 0,0);     // 320x240 image...
    importer->SetDataExtentToWholeExtent();
    importer->SetNumberOfScalarComponents( 4 );     // 4 for R G B A ....
    importer->SetDataSpacing(1,1,1);
    importer->SetDataScalarTypeToUnsignedChar();
    imActor->SetInput( importer->GetOutput() );
    imActor->SetDisplayExtent(0, 319, 0, 239, 0, 0);
    renWin->SetSize(640,480);
    renWin->AddRenderer( ren );
    ren->AddActor2D( imActor );
}

static void artkInit( 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);
    }

     //argInit( &cparam, 2.0, 0, 0, 0, 0 );
    arVideoCapStart();
}

static void vtk2artkLoop(void)

{
    ARUint8         *dataPtr;  // ARTK store the image grabbed in this 
vector of unsigned char !!!

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }

    importer->SetImportVoidPointer((void * ) dataPtr, 1);   // I think 
my mistake is HERE !!! 
    renWin->Render();
    arVideoCapNext();

    argSwapBuffers();
}

void CleanUp()
{
  importer->Delete();
  imActor->Delete();
  ren->Delete();
  renWin->Delete();
  arVideoCapStop();
  arVideoClose();
  argCleanup();
}

void main( int argc, char *argv[] )
{
    vtkInit();
    artkInit();
    for ( i=0; i<20; i++)
        vtk2artkLoop();
    CleanUp();
}





More information about the vtkusers mailing list