int  arVideoOpen(char *config)
{
    if( open_flag == 1 ) return(0);

    /* Connect to the VFW camera */
    VisAddProviderRegEntryForVFW();

    VisFindImageSource(sequence);

    if (!(sequence.HasImageSource()) || !(sequence.ImageSource().IsValid()))
        error_exit();

    // Don't use continuous grab since it chews up the processor like crazy
    sequence.ImageSource().SetUseContinuousGrab(false);

    // Grab an initial image
    if (!sequence.Pop(image, 40000))
    printf("Error in v_open: Couldn't get the image (init)\n");

    printf("Size = [%d, %d]\n", image.Width(), image.Height());


    open_flag = 1;
	
#ifdef FLIPPED
    // memory for a flipped copy of the image (for the USB camera)
    flipped_image.Allocate(image.Width(), image.Height());
#endif

    return(0);
}
int arVideoInqSize( int *x, int *y )
{
    if( open_flag == 0 ) return(-1);

    *x = image.Width();
    *y = image.Height();

    return(0);
}
Exemplo n.º 3
0
//////////////////////////////////////////////////////////////////////////\/
//  
//  FUNCTION:
//      VisMakePixelsInvisible
//  
//  DECLARATION:
//      static void VisMakePixelsInvisible(CVisRGBAByteImage &img, int v);
//  
//  PARAMETERS:
//      img - 
//          Image
//  
//      v - 
//			A value of the pixel to be set invisible.
//          
//  
//  DESCRIPTION:
//      
//		Sets all the pixels equal to (v,v,v,255) to be invisible (0,0,0,0).
//			
//  
//////////////////////////////////////////////////////////////////////////\/
void VisMakePixelsInvisible(CVisRGBAByteImage &img, int v)
{
    int rows = img.Height(), cols = img.Width()*img.NBands();
    for (int r = 0; r < rows; r++) {
        CVisRGBABytePixel input(v, v, v, 255);
        int iv = *(int *) &input;
        int *p = (int *) img.PtrToFirstPixelInRow(r + img.Top());
        for (int c = 0; c < cols; c++)
            if (p[c] == iv)
                p[c] = 0;
    }
}
Exemplo n.º 4
0
//////////////////////////////////////////////////////////////////////////\/
//  
//  FUNCTION:
//      VisBackInvisiblePixels
//  
//  DECLARATION:
//      static void VisBackInvisiblePixels(CVisRGBAByteImage &img, int v);
//  
//  PARAMETERS:
//      img - 
//          Image to which backing color should be added
//  
//      v - 
//			Gray-level value of backing pixel.
//          
//  
//  DESCRIPTION:
//      
//		Sets out to in OVER (v,v,v,255).
//      Also, sets any (v,v,v,255) value to (v+e,v+e,v+e,255), e = +/- 1
//			
//  
//////////////////////////////////////////////////////////////////////////\/
void VisBackInvisiblePixels(CVisRGBAByteImage &img, int v)
{
    int rows = img.Height(), cols = img.Width()*img.NBands();
    int ic, e = (v < 128) ? 1 : -1;
    *(CVisRGBABytePixel *) &ic = CVisRGBABytePixel(v, v, v, 255);
    int i0 = ic;
    *(CVisRGBABytePixel *) &ic = CVisRGBABytePixel(v+e, v+e, v+e, 255);
    int i1 = ic;
    CVisRGBABytePixel a_mask(0, 0, 0, 255);
    int ia_mask = *(int *) &a_mask;
    for (int r = 0; r < rows; r++) {
        CVisRGBABytePixel *p = img.PtrToFirstPixelInRow(r + img.Top());
        int *ip = (int *) p;
        for (int c = 0; c < cols; c++) {
#ifdef FASTER
            // Test 8 pixels at a time (speedup)
            if ((c & 7) == 0 && (c+7) < cols) {
                int *f = &ip[c];
                int f255 = f[0] & f[1] & f[2] & f[3] & 
                           f[4] & f[5] & f[6] & f[7];
                if ((f255 & ia_mask) == ia_mask) {
                    c += 7;
                    continue;   // all 8 pixels are opaque
                }
                int f000 = f[0] | f[1] | f[2] | f[3] | 
                           f[4] | f[5] | f[6] | f[7];
                if ((f000  & ia_mask) == 0) {
                    // all 8 pixels are transparent
                    f[0] = f[1] = f[2] = f[3] =
                    f[4] = f[5] = f[6] = f[7] = i0;
                    c += 7;
                    continue;
                }
            }
#endif
            if (ip[c] == 0)
                ip[c] = i0;
            else if (ip[c] == i0)
                ip[c] = i1;
            else if (p[c].A() != 255) {
                int w = ((255 - p[c].A())*v + 127)/255;
                p[c].SetR(p[c].R() + w);
				p[c].SetG(p[c].G() + w);
				p[c].SetB(p[c].B() + w);
				p[c].SetA(255);
            }
        }
    }
}
unsigned char *arVideoGetImage( void )
{
#ifdef FLIPPED
    int             i, j;
#endif

    if( open_flag == 0 )              return(NULL);

    if (!sequence.Pop(image, 20000)){
        printf("Couldn't get the image\n");
        return NULL;
    }

#ifdef FLIPPED
    // make a flipped copy
    for (j = 0; j < image.Height(); j++){
        for (i = 0; i < image.Width(); i++){
            flipped_image.Pixel(i,(image.Height()-1-j)).SetR( image.Pixel(i, j).R() );
            flipped_image.Pixel(i,(image.Height()-1-j)).SetG( image.Pixel(i, j).G() );
            flipped_image.Pixel(i,(image.Height()-1-j)).SetB( image.Pixel(i, j).B() );
            flipped_image.Pixel(i,(image.Height()-1-j)).SetA( image.Pixel(i, j).A() );
        }
    }
    return (unsigned char*)flipped_image.PbPixel(flipped_image.StartPoint());
#endif

//  printf("Size = [%d, %d]\n", image.Width(), image.Height());
    return (unsigned char*)image.PbPixel(image.StartPoint());

    return(NULL);
}