예제 #1
0
/**
	compute image DCT
*/
void computeImgDCT(image img, image output, s_args args){

    float *data = malloc(sizeof(float)*BLOCK_SIZE*BLOCK_SIZE);
    int i=0,j=0;

    for (i = 0; i < img.h; i += BLOCK_SIZE) 
    { 
        for (j = 0; j < img.w; j+= BLOCK_SIZE) 
        {
            dct(&img, data, i, j);
            putDCTValues(&output, data, i, j);          
        }        
    }

    free(data);
    writePgm(args.outFilename, &output);
}
예제 #2
0
/**
	quantify image
*/
void quantifyImg(image img, image output, s_args args){

    int *quantizeData = malloc(sizeof(int)*BLOCK_SIZE*BLOCK_SIZE);
    float *dctData = malloc(sizeof(float)*BLOCK_SIZE*BLOCK_SIZE);

    for (int i = 0; i < img.h; i += BLOCK_SIZE) {
      for (int j = 0; j < img.w; j+= BLOCK_SIZE) 
        {
            dct(&img, dctData, i, j);
            quantize(dctData, quantizeData);
            putQUANTIZEValues(&output, quantizeData, i, j);          
        }
    }

    free(quantizeData);
    free(dctData);
    writePgm(args.outFilename, &output);
}
예제 #3
0
/**
	vectorize Image
*/
void vectorizeImg(image img, image output, s_args args){

    int *quantizeData = malloc(sizeof(int)*BLOCK_SIZE*BLOCK_SIZE);
    int *vectorizeData = malloc(sizeof(int)*BLOCK_SIZE*BLOCK_SIZE);
    float *dctData = malloc(sizeof(float)*BLOCK_SIZE*BLOCK_SIZE);
    int offset = 0;

    for (int i = 0; i < img.h; i += BLOCK_SIZE){
        for (int j = 0; j < img.w; j+= BLOCK_SIZE) 
        {
            dct(&img, dctData, j, i);
            quantize(dctData, quantizeData);
            vectorize(quantizeData, vectorizeData);
            putValues(&output, vectorizeData, offset);
            offset += BLOCK_SIZE*BLOCK_SIZE;
        }
        
    }

    free(quantizeData);
    free(vectorizeData);
    free(dctData);
    writePgm(args.outFilename, &output);
}
예제 #4
0
int hrt_main (int argc, char **argv) 
{
    int flag;

    int i;

    // detection parameters
    float scaleFactor = 1.2;
    int minNeighbours = 3;
    int size;

    printf("-- entering main function --\r\n");

    printf("-- loading image --\r\n");

    MyImage imageObj;
    MyImage *image = &imageObj;

    flag = readPgm((char *)INPUT_FILENAME, image);
    if (flag == -1)
    {
        printf( "Unable to open input image\n");
        return 1;
    }

    printf("-- loading cascade classifier --\r\n");

    myCascade cascadeObj;
    myCascade *cascade = &cascadeObj;
    MySize minSize = {20, 20};
    MySize maxSize = {0, 0};

    // classifier properties
    cascade->n_stages=25;
    cascade->total_nodes=2913;
    cascade->orig_window_size.height = 24;
    cascade->orig_window_size.width = 24;

    readTextClassifier(cascade);

    struct MyRect *result[NUM] = {};

    //Load the program 
    hrt_cell_load_program_id(CELL, haar);

    hrt_scalar_store(CELL, MyImage, myimage, image);
    hrt_indexed_store(CELL, MySize, mysize, 0, minSize);
    hrt_indexed_store(CELL, MySize, mysize, 1, maxSize);
    hrt_scalar_store(CELL, myCascade, mycascade, cascade);
    hrt_scalar_store(CELL, float, scalefactor, scaleFactor);
    hrt_scalar_store(CELL, int, minneighbours, minNeighbours); 
    hrt_scalar_store(CELL, MyRect, myrect, result); 

    printf("-- detecting faces --\r\n");
    
    //size = detectObjects(image, minSize, maxSize, cascade, scaleFactor, minNeighbours, result);
    detectObjects();
    size = hrt_scalar_load(CELL, int, size);


    printf("-- drawing boxes --\r\n");
    for(i = 0; i < NUM; i++ )
    {
        if ( result[i] != NULL) {
            struct MyRect *r = result[i];
            drawRectangle(image, r);
        }
        else
            break;
    }

    printf("-- saving output --\r\n");
    flag = writePgm((char *)OUTPUT_FILENAME, image);

    printf("-- image saved --\r\n");

    //    delete image and free classifier
    releaseTextClassifier(cascade);
    freeImage(image);

    

    return 0;
}
예제 #5
0
int main( int argc, char *argv[] )
{
   dc1394camera_t* 	camera;
   dc1394error_t 	err;
   dc1394_t * d;
   dc1394camera_list_t * list;
   unsigned int nThisCam;

   // Find cameras on the 1394 buses
   d = dc1394_new ();

   // Enumerate cameras connected to the PC
   err = dc1394_camera_enumerate (d, &list);
   if ( err != DC1394_SUCCESS )
   {
       fprintf( stderr, "Unable to look for cameras\n\n"
             "Please check \n"
	         "  - if the kernel modules `ieee1394',`raw1394' and `ohci1394' "
	         "are loaded \n"
	         "  - if you have read/write access to /dev/raw1394\n\n");
       return 1;
    }

    if (list->num == 0)
    {
        fprintf( stderr, "No cameras found!\n");
        return 1;
    }

    printf( "There were %d camera(s) found attached to your PC\n", list->num  );

    // Identify cameras. Use the first stereo camera that is found
    for ( nThisCam = 0; nThisCam < list->num; nThisCam++ )
    {
        camera = dc1394_camera_new(d, list->ids[nThisCam].guid);

        if(!camera)
        {
            printf("Failed to initialize camera with guid %llx", list->ids[nThisCam].guid);
            continue;
        }

        printf( "Camera %d model = '%s'\n", nThisCam, camera->model );

        if ( isStereoCamera(camera))
        {
            printf( "Using this camera\n" );
            break;
        }
        dc1394_camera_free(camera);
   }

   if ( nThisCam == list->num )
   {
      printf( "No stereo cameras were detected\n" );
      return 0;
   }

   // Free memory used by the camera list
   dc1394_camera_free_list (list);

   PGRStereoCamera_t stereoCamera;

   // query information about this stereo camera
   err = queryStereoCamera( camera, &stereoCamera );
   if ( err != DC1394_SUCCESS )
   {
      fprintf( stderr, "Cannot query all information from camera\n" );
      cleanup_and_exit( camera );
   }

   // set the capture mode
   printf( "Setting stereo video capture mode\n" );
   err = setStereoVideoCapture( &stereoCamera );
   if ( err != DC1394_SUCCESS )
   {
      fprintf( stderr, "Could not set up video capture mode\n" );
      cleanup_and_exit( stereoCamera.camera );
   }

   // have the camera start sending us data
   printf( "Start transmission\n" );
   err = startTransmission( &stereoCamera );
   if ( err != DC1394_SUCCESS )
   {
      fprintf( stderr, "Unable to start camera iso transmission\n" );
      cleanup_and_exit( stereoCamera.camera );
   }

   // give the auto-gain algorithms a chance to catch up
   printf( "Wait for the auto-gain algorithm to stabilize\n" );
   sleep( 5 );


   // Allocate all the buffers.
   // Unfortunately color processing is a bit inefficient because of the number of
   // data copies.  Color data needs to be
   // - de-interleaved into separate bayer tile images
   // - color processed into RGB images
   // - de-interleaved to extract the green channel for stereo (or other mono conversion)

   // size of capture buffer
   unsigned int   nBufferSize = stereoCamera.nRows *
                                stereoCamera.nCols *
                                stereoCamera.nBytesPerPixel;
   // allocate a buffer to hold the de-interleaved images
   unsigned char* pucDeInterlacedBuffer = new unsigned char[ nBufferSize ];

   if ( stereoCamera.bColor )
   {
      unsigned char* pucRGBBuffer 	= new unsigned char[ 3 * nBufferSize ];
      unsigned char* pucGreenBuffer 	= new unsigned char[ nBufferSize ];
      unsigned char* pucRightRGB	= NULL;
      unsigned char* pucLeftRGB		= NULL;
      unsigned char* pucCenterRGB	= NULL;
      TriclopsInput input;

      // get the images from the capture buffer and do all required processing
      // note: produces a TriclopsInput that can be used for stereo processing
      extractImagesColor( &stereoCamera,
			  DC1394_BAYER_METHOD_NEAREST,
			  pucDeInterlacedBuffer,
			  pucRGBBuffer,
			  pucGreenBuffer,
			  &pucRightRGB,
			  &pucLeftRGB,
			  &pucCenterRGB,
			  &input );

      // write the color images to file
      if ( !writePpm( "right.ppm", pucRightRGB, stereoCamera.nCols, stereoCamera.nRows ) )
	 printf( "wrote right.ppm\n" );
      if ( !writePpm( "left.ppm", pucLeftRGB, stereoCamera.nCols, stereoCamera.nRows ) )
	 printf( "wrote left.ppm\n" );
      if ( pucCenterRGB != pucLeftRGB )
	 if ( !writePpm( "center.ppm", pucCenterRGB, stereoCamera.nCols, stereoCamera.nRows ) )
	    printf( "wrote center.ppm\n" );

      delete[] pucRGBBuffer;
      delete[] pucGreenBuffer;
   }
   else
   {
      unsigned char* pucRightMono	= NULL;
      unsigned char* pucLeftMono	= NULL;
      unsigned char* pucCenterMono	= NULL;
      TriclopsInput input;
      // get the images from the capture buffer and do all required processing
      // note: produces a TriclopsInput that can be used for stereo processing
      extractImagesMono( &stereoCamera,
			  pucDeInterlacedBuffer,
			  &pucRightMono,
			  &pucLeftMono,
			  &pucCenterMono,
			  &input );


      // write the greyscale images to file
      if ( !writePgm( "right.pgm", pucRightMono, stereoCamera.nCols, stereoCamera.nRows ) )
	 printf( "wrote right.pgm\n" );
      if ( !writePgm( "left.pgm", pucLeftMono, stereoCamera.nCols, stereoCamera.nRows ) )
	 printf( "wrote left.pgm\n" );
      if ( pucCenterMono != pucLeftMono )
	 if ( !writePgm( "center.pgm", pucCenterMono, stereoCamera.nCols, stereoCamera.nRows ) )
	    printf( "wrote center.pgm\n" );
   }

   printf( "Stop transmission\n" );
   //  Stop data transmission
   if ( dc1394_video_set_transmission( stereoCamera.camera, DC1394_OFF ) != DC1394_SUCCESS )
   {
      fprintf( stderr, "Couldn't stop the camera?\n" );
   }

   delete[] pucDeInterlacedBuffer;

   // close camera
   cleanup_and_exit( camera );

   return 0;
}