Ejemplo n.º 1
0
int main(int argc, char** argv)
{        
    fc2Error error;
    fc2Context context;
    fc2PGRGuid guid;
    unsigned int numCameras = 0;    
    const int k_numImages = 100;

    // Since this application saves images in the OUTPUT_DIR folder
    // we must ensure that the folder exists and we have permission 
    //to write to this folder. If we do not have permission, fail right away.
    struct stat sb;

    if (!(stat(OUTPUT_DIR, &sb) == 0 && S_ISDIR(sb.st_mode)))
    {
      printf("Directory %s NOT found\n",OUTPUT_DIR);
      if (mkdir(OUTPUT_DIR, S_IRWXU | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH) != 0)
      {
	printf("Error creating directory %s\n",OUTPUT_DIR);
	return -1;
      }
    }
    // else
    // {
    //   printf("Directory %s NOT FOUND\n",OUTPUT_DIR);
    //}

    char tempFileName[512];
    sprintf(tempFileName, "%stest.txt",OUTPUT_DIR);
    FILE* tempFile = fopen(tempFileName, "w+");
    if (tempFile == NULL)
    {
      printf("Failed to create file in current folder.  Please check permissions.\n");
      return -1;
    }
    fclose(tempFile);
    remove(tempFileName);

    //if we get here, we know the directory exists and we can write to it



    PrintBuildInfo();

    error = fc2CreateContext( &context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateContext: %d\n", error );
        return 0;
    }        

    error = fc2GetNumOfCameras( context, &numCameras );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetNumOfCameras: %d\n", error );
        return 0;
    }

    if ( numCameras == 0 )
    {
        // No cameras detected
        printf( "No cameras detected.\n");
        return 0;
    }

    // Get the 0th camera
    error = fc2GetCameraFromIndex( context, 0, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetCameraFromIndex: %d\n", error );
        return 0;
    }    

    error = fc2Connect( context, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2Connect: %d\n", error );
        return 0;
    }

    PrintCameraInfo( context );    

    SetTimeStamping( context, TRUE );

    error = fc2StartCapture( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StartCapture: %d\n", error );
        return 0;
    }

    GrabImages( context, k_numImages );   

    error = fc2StopCapture( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StopCapture: %d\n", error );
        return 0;
    }

    error = fc2DestroyContext( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2DestroyContext: %d\n", error );
        return 0;
    }

    printf( "Done! Press Enter to exit...\n" );
    getchar();

	return 0;
}
Ejemplo n.º 2
0
fleaCamera* open_camera(int brightness, unsigned int height, unsigned int width)
{
        fc2Error error;
        fleaCamera* camera = calloc(1, sizeof(fleaCamera));
        fc2PGRGuid guid;
        fc2GigEImageSettings image_settings;
    
        printf("Creating context\n");
        error = fc2CreateGigEContext( &camera->context );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2CreateContext: %d\n", error );
            free(camera);
            return NULL;
        }        
    
        // Get the 0th camera
        fc2GetCameraFromIndex( camera->context, 0, &guid );
        
        error = fc2Connect( camera->context, &guid );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2Connect: %d\n", error );
            close_camera(camera);
            return NULL;
        }
    
        //set_property_value(camera, FC2_BRIGHTNESS, brightness);
        //PrintCameraInfo( camera->context );  
        //setup_camera( camera );
        SetTimeStamping( camera->context, TRUE );      
        error = fc2GetGigEImageSettings(camera->context, &image_settings);
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error getting image settings settings: %d\n", error );
            return NULL;
        }
    
       
        image_settings.width = width;
        image_settings.height = height;
        image_settings.offsetX = (int)(MAX_WIDTH - width)/2;
        image_settings.offsetY = (int)(MAX_HEIGHT - height)/2;
        image_settings.pixelFormat = FC2_PIXEL_FORMAT_RAW8;
    
        error = fc2SetGigEImageSettings(camera->context, &image_settings);
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error setting format7 settings: %d\n", error );
            return NULL;
        }
        sleep(0.5);
    
        error = fc2StartCapture( camera->context );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2StartCapture: %d\n", error );
        }
    
        sleep(0.5);

    return camera;
}