void getproperty(unicap_handle_t handle, unicap_property_t *prop, char *propid) { int i; for(i = 0; SUCCESS(unicap_enumerate_properties(handle, NULL, prop,i)); i++) { unicap_property_t p = *prop; if(strcmp(propid, p.identifier) == 0) { unicap_get_property(handle, prop); break; } } }
//-------------------------------------------------------------------- void ofUCUtils::queryUC_imageProperties(void) { unicap_property_t property; ofLog(OF_NOTICE,"ofUCUtils : Video settings:"); const int PPTY_TYPE_MAPPED_FLOAT=UNICAP_PROPERTY_TYPE_UNKNOWN + 1; int status = STATUS_SUCCESS; int ppty_type; for (int i=0; i<MAX_PROPERTIES; i++) { status = unicap_enumerate_properties(handle, NULL, &property, i); if ( !SUCCESS( status )) return; status = unicap_get_property(handle, &property ); if ( !SUCCESS( status )) { ofLog(OF_ERROR,"ofUCUtils : Error getting %s value\n", property.identifier); return; } ppty_type = property.type; switch (ppty_type) { case PPTY_TYPE_MAPPED_FLOAT: case UNICAP_PROPERTY_TYPE_RANGE: case UNICAP_PROPERTY_TYPE_VALUE_LIST: if (property.value>0 && property.value<1) { ofLog(OF_NOTICE,"\t%s: 1/%.0f \n", property.identifier, 1/property.value); } else { ofLog(OF_NOTICE,"\t%s: %.2f \n", property.identifier, property.value); } break; case UNICAP_PROPERTY_TYPE_MENU: printf("\t%s: %s \n", property.identifier, property.menu_item); break; default: break; } } }
int main( int argc, char **argv ) { unicap_handle_t handle; unicap_device_t device; unicap_device_t device_spec; unicap_property_t property; unicap_property_t property_spec; int list_only = 0; int get_property = 0; int value_set = 0; int i; int c = 0; unicap_void_device( &device_spec ); unicap_void_property( &property ); while( c != -1 ) { c = getopt( argc, argv, "gp:M:v:m:l" ); switch( c ) { case 'p': if( optarg ) { strcpy( property.identifier, optarg ); } break; case 'M': if( optarg ) { printf( "Model: %s\n", optarg ); strcpy( device_spec.model_name, optarg ); } else { print_usage( argv[0] ); exit( 1 ); } break; case 'v': if( optarg ) { sscanf( optarg, "%f", &property_spec.value ); value_set = 1; } else { print_usage( argv[0] ); exit( 1 ); } break; case 'm': if( optarg ) { strcpy( property.menu_item, optarg ); } else { print_usage( argv[0] ); exit( 1 ); } break; case 'l': list_only = 1; break; case 'g': get_property = 1; break; case -1: printf( "optind: %d\n", optind ); break; default: print_usage( argv[0] ); exit( 1 ); break; } } // // Enumerate all video capture devices; if more than 1 device present, ask for which device to open // for( i = 0; SUCCESS( unicap_enumerate_devices( &device_spec, &device, i ) ); i++ ) { printf( "%i: %s\n", i, device.identifier ); } if( --i > 0 ) { printf( "Select video capture device: " ); scanf( "%d", &i ); } if( !SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ) ) { fprintf( stderr, "Failed to get info for device '%s'\n", device.identifier ); exit( 1 ); } /* Acquire a handle to this device */ if( !SUCCESS( unicap_open( &handle, &device ) ) ) { fprintf( stderr, "Failed to open device: %s\n", device.identifier ); exit( 1 ); } printf( "Opened video capture device: %s\n", device.identifier ); // Initialize a property specifier structure unicap_void_property( &property_spec ); strcpy( property_spec.identifier, property.identifier ); printf( "Supported properties: \n" ); printf( "\tName\t\tValue\n" ); // // Print a list of all properties matching the specifier. For a "void" specifier, this matches all // properties supported by the device // If more than 1 property is supported, ask for which property to modify for( i = 0; SUCCESS( unicap_enumerate_properties( handle, &property_spec, &property, i ) ); i++ ) { unicap_get_property( handle, &property ); printf( "%i: \t%s\t\t", i, property.identifier ); switch( property.type ) { case UNICAP_PROPERTY_TYPE_RANGE: case UNICAP_PROPERTY_TYPE_VALUE_LIST: printf( "%f", property.value ); break; case UNICAP_PROPERTY_TYPE_MENU: printf( "%s", property.menu_item ); break; case UNICAP_PROPERTY_TYPE_FLAGS: { int j; const char *flags[] = { "MANUAL", "AUTO", "ONE_PUSH", "READ_OUT", "ON_OFF", "READ_ONLY", "FORMAT_CHANGE" }; for( j = 0; j < ( sizeof( flags ) / sizeof( char* ) ); j++ ) { if( ( property.flags & ( 1<<j ) ) == ( 1<<j ) ) { printf( "%s ",flags[j] ); } } } break; default: break; } printf( "\n" ); } if( --i > 1 ) { printf( "Select a property to edit: " ); scanf( "%d", &i ); } // Now get the description of the requested property. unicap_enumerate_property gives the // property structure initialized to the default values. So just change the value of the // returned property to the new one and set it using 'unicap_set_property' if( !SUCCESS( unicap_enumerate_properties( handle, &property_spec, &property, i ) ) ) { printf( "Failed to enumerate property\n" ); exit( -1 ); } switch( property.type ) { case UNICAP_PROPERTY_TYPE_RANGE: case UNICAP_PROPERTY_TYPE_VALUE_LIST: { if( !value_set ) { double new_value; printf( "Enter new value for property '%s' ( floating point value ): ", property.identifier ); scanf( "%lf", &new_value ); property.value = new_value; property.flags = UNICAP_FLAGS_MANUAL; } else { property.value = property_spec.value; } } break; case UNICAP_PROPERTY_TYPE_MENU: { printf( "Enter new value for property '%s' ( string ): ", property.identifier ); scanf( "%128s", property.menu_item ); } break; case UNICAP_PROPERTY_TYPE_FLAGS: { int i; char buf[128]; char *str; printf( "Enter new flags for property '%s' ( out of ", property.identifier ); for( i = 0; i < ( sizeof( property_flag_strings ) / sizeof( struct flag_string ) ); i++ ) { if( property.flags_mask & property_flag_strings[i].flag ) { printf( "%s ", property_flag_strings[i].name ); } } printf( "): " ); scanf( "%128s", buf ); str = strtok( buf, " " ); property.flags = 0; while( str ) { for( i = 0; i < ( sizeof( property_flag_strings ) / sizeof( struct flag_string ) ); i++ ) { if( !strcmp( str, property_flag_strings[i].name ) ) { property.flags |= property_flag_strings[i].flag; break; } } if( i == ( sizeof( property_flag_strings ) / sizeof( struct flag_string ) ) ) { printf( "Unknown flag: %s\n", str ); break; } str = strtok( NULL, " " ); } } } if( !get_property ) { if( !SUCCESS( unicap_set_property( handle, &property ) ) ) { printf( "Failed to set property!\n" ); } } else { char buffer[512]; int s = sizeof( buffer ); if( !SUCCESS( unicap_get_property( handle, &property ) ) ) { printf( "Failed to set property!\n" ); } unicap_describe_property( &property, buffer, &s ); printf( "%s\n", buffer ); } unicap_close( handle ); return 0; }
int UnicapCamera::Open() { unicap_device_t device; unicap_handle_t handle; unicap_format_t format; //Initialisation if (m_Device == NULL) { m_Device = (unicap_device_t *)malloc(sizeof(unicap_device_t)); if (m_Device == NULL) { printf("UnicapCamera::Open: Error, no memory!\n"); return ERROR_NO_MEMORY; } } if (m_Handle == NULL) { m_Handle = (unicap_handle_t *)malloc(sizeof(unicap_handle_t)); if (m_Handle == NULL) { printf("UnicapCamera::Open: Error, no memory!\n"); return ERROR_NO_MEMORY; } } if (m_Format == NULL) { m_Format = (unicap_format_t *)malloc(sizeof(unicap_format_t)); if (m_Format == NULL) { printf("UnicapCamera::Open: Error, no memory!\n"); return ERROR_NO_MEMORY; } } // Search camera devices if( !SUCCESS( unicap_enumerate_devices( NULL, &device, 0 ) ) ) { printf("UnicapCamera::Open: No device found!\n"); return ERROR_NO_CAMERAS_FOUND; } else { *m_Device = device; printf("UnicapCamera::Open: Device %s found, vendor: %s, controlled by %s, %s\n", m_Device->identifier, m_Device->vendor_name, m_Device->device, m_Device->cpi_layer); } /* Acquire a handle to this device */ if( !SUCCESS( unicap_open( &handle, m_Device ) ) ) { printf("UnicapCamera::Open: Failed to open device %s: %s\n", m_Device->identifier, strerror(errno)); return ERROR_CAMERA_COULD_NOT_BE_OPENED; } else { *m_Handle = handle; m_CameraActive = true; printf("DUnicapCamera::Open:evice %s successfully opened!\n", m_Device->identifier); } //Set format according to specified resolution if( !SUCCESS( unicap_enumerate_formats( *m_Handle, NULL, &format, m_Resolution ) ) ) { printf("UnicapCamera::Open: Failed to get video format, setting to default\n" ); //return UNSPECIFIED_ERROR;; } else { *m_Format = format; printf("UnicapCamera::Open: Format %s chosen\n", format.identifier ); printf("UnicapCamera::Open: Setting video format: \nwidth: %d\nheight: %d\nbpp: %d\nFOURCC: %c%c%c%c\n\n", \ m_Format->size.width,\ m_Format->size.height,\ m_Format->bpp, \ m_Format->fourcc & 0xff, \ ( m_Format->fourcc >> 8 ) & 0xff, \ ( m_Format->fourcc >> 16 ) & 0xff, \ ( m_Format->fourcc >> 24 ) & 0xff \ ); /* Set this video format */ if( !SUCCESS( unicap_set_format( *m_Handle, m_Format ) ) ) { printf("UnicapCamera::Open: Failed to set video format\n" ); return UNSPECIFIED_ERROR; } } unicap_property_t property; // Set white balance mode to auto strcpy( property.identifier, "white_balance_mode" ); if( !SUCCESS( unicap_get_property( *m_Handle, &property ) ) ) { fprintf( stderr, "UnicapCamera::Open: Failed to get WB mode property\n" ); exit( 1 ); } // Set auto on this property property.flags = UNICAP_FLAGS_AUTO;//UNICAP_FLAGS_MANUAL; unicap_set_property( handle, &property ); if( !SUCCESS( unicap_set_property( *m_Handle, &property ) ) ) { printf( "UnicapCamera::Open: Failed to set property!\n" ); return UNSPECIFIED_ERROR; } if( !SUCCESS( unicap_get_property( *m_Handle, &property ) ) ) { fprintf( stderr, "UnicapCamera::Open: Failed to get WB mode property\n" ); exit( 1 ); } printf( "UnicapCamera::Open: Current white balance mode: %s\n", property.flags & UNICAP_FLAGS_AUTO ? "AUTO" : "MANUAL" ); if( !SUCCESS( unicap_start_capture( *m_Handle ) ) ) { printf( "UnicapCamera::Open: Failed to start capture on device %s\n", m_Device->identifier ); return UNSPECIFIED_ERROR; } return OK; }