// Toggle setting about whether or not RGB color conversion is to be performed // Allocates/Initializes capture->frame appropriately int icvSetConvertRGB(CvCaptureCAM_DC1394 * capture, int convert){ if(convert==capture->convert){ // no action necessary return 1; } capture->convert = convert; return icvResizeFrame( capture ); }
// Toggle setting about whether or not RGB color conversion is to be performed // Allocates/Initializes capture->frame appropriately int icvSetConvertRGB(CvCaptureCAM_DC1394 * capture, int convert){ _V_MW_ fprintf(stderr,"icvSetConvertRGB\n"); if(convert==capture->convert){ // no action necessary return 0; } capture->convert = convert; return icvResizeFrame( capture ); }
// Setup camera to use given dc1394 mode static int icvSetModeCAM_DC1394( CvCaptureCAM_DC1394 * capture, int mode ){ quadlet_t modes, formats; //printf("<icvSetModeCAM_DC1394>\n"); // figure out corrent format for this mode int format = (mode - MODE_FORMAT0_MIN) / 32 + FORMAT_MIN; // get supported formats if (dc1394_query_supported_formats(capture->handle, capture->camera->node, &formats)<0) { fprintf(stderr,"%s:%d: Could not query supported formats\n",__FILE__,__LINE__); return 0; } // is format for requested mode supported ? if(icvFormatSupportedCAM_DC1394(format, formats)==0){ return 0; } // get supported modes for requested format if (dc1394_query_supported_modes(capture->handle, capture->camera->node, format, &modes)<0){ fprintf(stderr,"%s:%d: Could not query supported modes for format %d\n",__FILE__,__LINE__, capture->format); return 0; } // is requested mode supported ? if(! icvModeSupportedCAM_DC1394(format, mode, modes) ){ return 0; } int color_mode = icvColorMode( mode ); if(color_mode == -1){ return 0; } int frame_rate = icvGetBestFrameRate(capture, format, mode); dc1394_dma_unlisten(capture->handle, capture->camera); if (dc1394_dma_setup_capture(capture->handle, capture->camera->node, capture->camera->channel /*channel*/, format, mode, SPEED_400, frame_rate, NUM_BUFFERS, #ifdef HAVE_DC1394_095 0 /*do_extra_buffering*/, #endif 1 /*DROP_FRAMES*/, capture->device_name, capture->camera) != DC1394_SUCCESS) { fprintf(stderr,"%s:%d: Failed to setup DMA capture with VIDEO1394\n",__FILE__,__LINE__); return 0; } dc1394_start_iso_transmission(capture->handle, capture->camera->node); capture->frame_rate = frame_rate; capture->format = format; capture->mode = mode; capture->color_mode = color_mode; // now fix image size to match new mode icvResizeFrame( capture ); return 1; }
CvCapture * cvCaptureFromCAM_DC1394 (int index) { quadlet_t modes[8], formats; int i; if (numPorts<0) icvInitCapture_DC1394(); if (numPorts==0) return 0; /* No i1394 ports found */ if (numCameras<1) return 0; if (index>=numCameras) return 0; if (index<0) return 0; CvCaptureCAM_DC1394 * pcap = (CvCaptureCAM_DC1394*)cvAlloc(sizeof(CvCaptureCAM_DC1394)); pcap->vtable = &captureCAM_DC1394_vtable; /* Select a port and camera */ pcap->device_name = videodev[cameras[index].portnum]; pcap->handle = handles[cameras[index].portnum]; pcap->camera = &cameras[index].cam; // get supported formats if (dc1394_query_supported_formats(pcap->handle, pcap->camera->node, &formats)<0) { fprintf(stderr,"%s:%d: Could not query supported formats\n",__FILE__,__LINE__); formats=0x0; } for (i=0; i < NUM_FORMATS; i++) { modes[i]=0; if (icvFormatSupportedCAM_DC1394(i+FORMAT_MIN, formats)){ if (dc1394_query_supported_modes(pcap->handle, pcap->camera->node, i+FORMAT_MIN, &modes[i])<0) { fprintf(stderr,"%s:%d: Could not query Format%d modes\n",__FILE__,__LINE__,i); } } } pcap->format = 0; pcap->mode = 0; pcap->color_mode = 0; pcap->frame_rate = 0; int format_idx = -1; // scan the list of preferred modes, and find a supported one for(i=0; (pcap->mode == 0) && (preferred_modes[i] != 0); i++) { if((preferred_modes[i] >= FORMAT_MIN) && (preferred_modes[i] <= FORMAT_MAX)) { pcap->format = preferred_modes[i]; format_idx = preferred_modes[i] - FORMAT_MIN; continue; } assert(format_idx != -1); if ( ! icvFormatSupportedCAM_DC1394(pcap->format, formats) ) continue; if ( icvModeSupportedCAM_DC1394(pcap->format, preferred_modes[i], modes[format_idx]) ){ pcap->mode = preferred_modes[i]; } } if (pcap->mode == 0) { fprintf(stderr,"%s:%d: Could not find a supported mode for this camera\n",__FILE__,__LINE__); goto ERROR; } pcap->color_mode = icvColorMode( pcap->mode ); if( pcap->color_mode == -1){ fprintf(stderr,"%s:%d: ERROR: BPP is Unsupported!!\n",__FILE__,__LINE__); goto ERROR; } // set frame rate to optimal value given format and mode pcap->frame_rate = icvGetBestFrameRate(pcap, pcap->format, pcap->mode); if (pcap->format!=FORMAT_SCALABLE_IMAGE_SIZE) { // everything except Format 7 if (dc1394_dma_setup_capture(pcap->handle, pcap->camera->node, index+1 /*channel*/, pcap->format, pcap->mode, SPEED_400, pcap->frame_rate, NUM_BUFFERS, #ifdef HAVE_DC1394_095 0 /*do_extra_buffering*/, #endif 1 /*DROP_FRAMES*/, pcap->device_name, pcap->camera) != DC1394_SUCCESS) { fprintf(stderr,"%s:%d: Failed to setup DMA capture with VIDEO1394\n",__FILE__,__LINE__); goto ERROR; } } else { if(dc1394_dma_setup_format7_capture(pcap->handle,pcap->camera->node,index+1 /*channel*/, pcap->mode, SPEED_400, QUERY_FROM_CAMERA, (unsigned int)QUERY_FROM_CAMERA, (unsigned int)QUERY_FROM_CAMERA, (unsigned int)QUERY_FROM_CAMERA, (unsigned int)QUERY_FROM_CAMERA, NUM_BUFFERS, #ifdef HAVE_DC1394_095 0 /*do_extra_buffering*/, #endif 1 /*DROP_FRAMES*/, pcap->device_name, pcap->camera) != DC1394_SUCCESS) { fprintf(stderr,"%s:%d: Failed to setup DMA capture with VIDEO1394\n",__FILE__,__LINE__); goto ERROR; } } if (dc1394_start_iso_transmission(pcap->handle, pcap->camera->node)!=DC1394_SUCCESS) { fprintf(stderr,"%s:%d: Could not start ISO transmission\n",__FILE__,__LINE__); goto ERROR; } usleep(DELAY); dc1394bool_t status; if (dc1394_get_iso_status(pcap->handle, pcap->camera->node, &status)!=DC1394_SUCCESS) { fprintf(stderr,"%s:%d: Could get ISO status",__FILE__,__LINE__); goto ERROR; } if (status==DC1394_FALSE) { fprintf(stderr,"%s:%d: ISO transmission refuses to start",__FILE__,__LINE__); goto ERROR; } // convert camera image to RGB by default pcap->convert=1; // no image data allocated yet pcap->buffer_is_writeable = 0; memset(&(pcap->frame), 0, sizeof(IplImage)); icvResizeFrame( pcap ); return (CvCapture *)pcap; ERROR: return 0; };