int main(int argc, char** argv)
{        
    fc2Error error;
    fc2Context context;
    fc2PGRGuid guid;
    unsigned int numCameras = 0;
    fc2CameraInfo camInfo[10];
    unsigned int numCamInfo = 10;
    FILE* tempFile;
    unsigned int i;

    PrintBuildInfo();

    // Since this application saves images in the current folder
    // we must ensure that we have permission to write to this folder.
    // If we do not have permission, fail right away.
    tempFile = fopen("test.txt", "w+");
    if (tempFile == NULL)
    {
        printf("Failed to create file in current folder.  Please check permissions.\n");
        return -1;
    }
    fclose(tempFile);
    remove("test.txt");    

    error = fc2CreateGigEContext( &context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateContext: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }        

    error = fc2DiscoverGigECameras( context, camInfo, &numCamInfo);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2DiscoverGigECameras: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    printf( "Number of cameras discovered: %u\n", numCamInfo );

    for ( i=0; i < numCamInfo; i++)
    {
        PrintCameraInfo( &camInfo[i] );
    }

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

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

    for (i=0; i < numCameras; i++)
    {
        fc2InterfaceType interfaceType;

        error = fc2GetCameraFromIndex( context, i, &guid);
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2GetCameraFromIndex: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }    

        error = fc2GetInterfaceTypeFromGuid( context, &guid, &interfaceType );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2GetInterfaceTypFromGuid: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }    

        if ( interfaceType == FC2_INTERFACE_GIGE )
        {
            RunSingleCamera( context, guid);
        }
    }

	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;
}
Beispiel #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;
}