//-------------------------------------------------------------------- ofxVideoGrabberPtgrey::ofxVideoGrabberPtgrey(){ bIsFrameNew = false; bVerbose = false; bGrabberInited = false; bUseTexture = true; bChooseDevice = false; deviceID = 0; width = 320; // default setting height = 240; // default setting pixels = NULL; frame = NULL; driver = NULL; deviceList = NULL; camera = NULL; video_mode = DC1394_VIDEO_MODE_FORMAT7_0; //2x2 pixel binning color_coding = DC1394_COLOR_CODING_MONO8; framerate = DC1394_FRAMERATE_60; driver = dc1394_new(); if (!driver) { return; } err = dc1394_camera_enumerate(driver, &deviceList); if(err){ ofLog(OF_LOG_ERROR, "Failed to enumerate cameras"); } if( deviceList->num == 0 ) { ofLog(OF_LOG_ERROR, "No cameras found"); } }
vector<CameraInfo> CameraIIDC::getCameraList(){ dc1394_t *context = dc1394_new(); dc1394camera_list_t *camera_list; dc1394error_t err; err = dc1394_camera_enumerate(context, &camera_list); DC1394_WRN(err,"libdc1394: Failed to enumerate cameras!"); vector<CameraInfo> ret; for (unsigned int i=0; i<camera_list->num; i++) { CameraInfo info; dc1394camera_t *cam; cam = dc1394_camera_new(context, camera_list->ids[i].guid); //info.vendor = std::string(cam->vendor ? cam->vendor : ""); info.vendor = "IIDC"; info.model = string(cam->model ? cam->model : ""); info.busID = (unsigned int)cam->guid; dc1394_camera_free(cam); ret.push_back(info); } dc1394_camera_free_list(camera_list); dc1394_free(context); return ret; }
FirewireVideo::FirewireVideo( unsigned deviceid, dc1394video_mode_t video_mode, dc1394framerate_t framerate, dc1394speed_t iso_speed, int dma_buffers ) :running(false),top(0),left(0) { d = dc1394_new (); if (!d) throw VideoException("Failed to get 1394 bus"); err=dc1394_camera_enumerate (d, &list); if( err != DC1394_SUCCESS ) throw VideoException("Failed to enumerate cameras"); if (list->num == 0) throw VideoException("No cameras found"); if( deviceid >= list->num ) throw VideoException("Invalid camera index"); const uint64_t guid = list->ids[deviceid].guid; dc1394_camera_free_list (list); init_camera(guid,dma_buffers,iso_speed,video_mode,framerate); }
FirewireVideo::FirewireVideo( unsigned deviceid, dc1394video_mode_t video_mode, float framerate, uint32_t width, uint32_t height, uint32_t left, uint32_t top, dc1394speed_t iso_speed, int dma_buffers, bool reset_at_boot ) :running(false) { d = dc1394_new (); if (!d) throw VideoException("Failed to get 1394 bus"); err=dc1394_camera_enumerate (d, &list); if( err != DC1394_SUCCESS ) throw VideoException("Failed to enumerate cameras"); if (list->num == 0) throw VideoException("No cameras found"); if( deviceid >= list->num ) throw VideoException("Invalid camera index"); const uint64_t guid = list->ids[deviceid].guid; dc1394_camera_free_list (list); init_format7_camera(guid,dma_buffers,iso_speed,video_mode,framerate,width,height,left,top, reset_at_boot); }
void ofxLibdc::startLibdcContext() { if(libdcCameras == 0) { ofLog(OF_LOG_VERBOSE, "Creating libdc1394 context with dc1394_new()."); libdcContext = dc1394_new(); } libdcCameras++; }
static dc1394camera_t *open_camera(void) { dc1394_t *d; dc1394camera_list_t * list; dc1394camera_t *camera; dc1394error_t err; d = dc1394_new(); if (!d) { return NULL; } err = dc1394_camera_enumerate(d, &list); if (err != DC1394_SUCCESS) { dc1394_free(d); return NULL; } if (list->num == 0) { dc1394_free(d); return NULL; } camera = dc1394_camera_new(d, list->ids[0].guid); if (!camera) { dc1394_free(d); return NULL; } dc1394_camera_free_list(list); printf("Using camera with GUID %"PRIx64"\n", camera->guid); return camera; }
CameraInfo* FWCamera::getCameraInfos(int deviceNumber) { #ifdef AVG_ENABLE_1394_2 dc1394_t* pDC1394 = dc1394_new(); if (pDC1394 == 0) { AVG_ASSERT(false); return NULL; } dc1394camera_list_t * pCameraList; int err=dc1394_camera_enumerate(pDC1394, &pCameraList); if (err != DC1394_SUCCESS) { AVG_ASSERT(false); return NULL; } if (pCameraList->num != 0) { dc1394camera_id_t id = pCameraList->ids[deviceNumber]; dc1394camera_t * pCamera = dc1394_camera_new_unit(pDC1394, id.guid, id.unit); if (pCamera) { stringstream deviceID; deviceID << hex << id.guid;//pCamera->guid; CameraInfo* camInfo = new CameraInfo("Firewire", deviceID.str()); getCameraControls(pCamera, camInfo); getCameraImageFormats(pCamera, camInfo); dc1394_camera_free(pCamera); dc1394_camera_free_list(pCameraList); dc1394_free(pDC1394); return camInfo; } } #endif return NULL; }
int _setupCam(long yExpo, long yGain, long *sizex, long *sizey, long speed){ dc1394camera_list_t * list; dc1394_t *d = dc1394_new (); if (!d) return -1; dc1394speed_t iso_speed; if(speed == 400) iso_speed = DC1394_ISO_SPEED_400; else if(speed == 800) iso_speed = DC1394_ISO_SPEED_800; else return -1; //iso_speed = DC1394_ISO_SPEED_400; dc1394_log_register_handler(DC1394_LOG_WARNING, NULL, NULL); err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { dc1394_log_error("No cameras found"); return -1; } camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { dc1394_log_error("Failed to initialize camera with guid %lld", list->ids[0].guid); return -1; } dc1394_camera_free_list (list); printf("Using camera with GUID %lld\n", camera->guid); release_iso_and_bw(); uint32_t expo = yExpo; uint32_t gain = yGain; /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B); DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not set operation mode"); err=dc1394_video_set_iso_speed(camera, iso_speed); DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not set iso speed"); _setVideoMode(0, sizex, sizey); err=dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, gain); DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not define gain"); err=dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, expo); DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not define shutter"); return 0; }
Camera::Camera() { camDict = dc1394_new(); error = dc1394_camera_enumerate(camDict, &camList); if (error != DC1394_SUCCESS) { std::cerr << "Failed to enumerate cameras." << std::endl; exit(EXIT_FAILURE); } numCams = camList->num; numDMABuffers = 3; FRAME_RATE = 15; /* undistort camera matrices */ K = cv::Mat::eye(3, 3, CV_64FC1); K.at<double>(0,0) = 751.79662626559286; /* fx */ K.at<double>(1,1) = 750.65231364204442; /* fy */ K.at<double>(0,2) = 306.70009070155015; /* cx */ K.at<double>(1,2) = 216.11302664191402; /* cy */ dist = cv::Mat::zeros(1, 4, CV_64FC1); dist.at<double>(0,0) = -0.38694196102815248; /* dist1 */ dist.at<double>(0,1) = 0.15311947060864667; /* dist2 */ dist.at<double>(0,2) = 0.002582758567387712; /* dist3 */ dist.at<double>(0,3) = 0.0036405418524754108; /* dist4 */ /* minimum resolution of camera */ camFrameHeight = IMG_HEIGHT; camFrameWidth = IMG_WIDTH; /* we crop images to quadratic dimensions for evenly divisable work-group items */ height = width = camFrameHeight; /* image index iterating modulo 8 */ imgIdx = START_LED; /* loading images for test mode */ std::stringstream s; s << PATH_ASSETS << "butterfly/image_ambient.png"; ambientImage = cv::imread(s.str(), CV_LOAD_IMAGE_GRAYSCALE); avgImgIntensity = cv::mean(ambientImage)[0]; for (int i=0; i<8; i++) { std::stringstream s; s << PATH_ASSETS << "butterfly/image" << i << ".png"; cv::Mat img = cv::imread(s.str(), CV_LOAD_IMAGE_GRAYSCALE); cv::GaussianBlur(img, img, cv::Size(3,3), 1.2); testImages.push_back(img); } /* counter iterating over (modulo 8) LEDs assigning image to current LED */ imgIdx = 3; testMode = false; /* setup undistortion */ initUndistLUT(); }
int main(int argc, char *argv[]) { unsigned int i; dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; dc1394featureset_t features; d = dc1394_new(); if(!d) return 1; err = dc1394_camera_enumerate(d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if(list->num == 0) { dc1394_log_error("No cameras found"); return 1; } for(i = 0; i < list->num; i++) { dc1394camera_t *camera = dc1394_camera_new(d, list->ids[i].guid); if(camera) { unsigned int j; dc1394video_modes_t modes; // Print hardware informations. dc1394_camera_print_info(camera, stdout); // Print supported camera features. err = dc1394_feature_get_all(camera,&features); if(err != DC1394_SUCCESS) { dc1394_log_warning("Could not get feature set"); } else { dc1394_feature_print_all(&features, stdout); } // Print a list of supported modes. printf("------ Supported Video Modes ------\n"); err = dc1394_video_get_supported_modes(camera, &modes); DC1394_ERR_RTN(err,"Could not get list of modes"); for(j = 0; j < modes.num; j++) { print_video_mode_info(camera, modes.modes[j]); } dc1394_camera_free(camera); } } dc1394_camera_free_list (list); dc1394_free (d); return 0; }
void DC1394Camera::initLibDC1394() { // Increment reference count s_camCount++; if (s_camCount == 1) { // Create library handle LOGGER.infoStream() << "Creating dc1394 library handle"; s_libHandle = dc1394_new(); } }
bool Libdc1394Grabber::initDc1394System() { /* Initialise libdc1394 */ if(!dc1394) { dc1394 = dc1394_new (); } if (!dc1394) { ofLog(OF_LOG_FATAL_ERROR,"Failed to initialise libdc1394."); return false; } return true; }
bool Camera::Init() { // VideoCapture Interface cv_image_ = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 3); // Initialize libdc1394 if ((d = dc1394_new ()) == NULL) return false; // Find cameras err = dc1394_camera_enumerate(d, &list); DC1394_ERR_RTN(err, "Failed to enumerate cameras"); // Verify that we have at least one cameraDC1394_BYTE_ORDER_YUYV if(list->num == 0) { dc1394_log_error("No cameras found"); return false; } // Work with first camera found if ((camera = dc1394_camera_new (d, list->ids[0].guid)) == NULL) { dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid); return false; } // Not using the list anymore, clean it up dc1394_camera_free_list(list); // Power ON dc1394_camera_set_power(camera, DC1394_ON); // Print camera info dc1394_camera_print_info(camera, stdout); // Setup capture err = dc1394_capture_setup(camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT); // Set video mode dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_640x480_YUV422); // Start transmission err = dc1394_video_set_transmission(camera, DC1394_ON); // VideoCapture Interface init_ = true; return true; }
FirewireVideo::FirewireVideo( Guid guid, dc1394video_mode_t video_mode, dc1394framerate_t framerate, dc1394speed_t iso_speed, int dma_buffers ) :running(false),top(0),left(0) { d = dc1394_new (); if (!d) throw VideoException("Failed to get 1394 bus"); init_camera(guid.guid,dma_buffers,iso_speed,video_mode,framerate); }
int FWCamera::countCameras() { #ifdef AVG_ENABLE_1394_2 dc1394_t* pDC1394 = dc1394_new(); if (pDC1394 == 0) { return 0; } dc1394camera_list_t * pCameraList; int err=dc1394_camera_enumerate(pDC1394, &pCameraList); if (err == DC1394_SUCCESS) { int numCameras = pCameraList->num; return numCameras; } #endif return 0; }
FirewireVideo::FirewireVideo( Guid guid, dc1394video_mode_t video_mode, float framerate, uint32_t width, uint32_t height, uint32_t left, uint32_t top, dc1394speed_t iso_speed, int dma_buffers, bool reset_at_boot ) :running(false) { d = dc1394_new (); if (!d) throw VideoException("Failed to get 1394 bus"); init_format7_camera(guid.guid,dma_buffers,iso_speed,video_mode,framerate,width,height,left,top, reset_at_boot); }
int main(int argc, char *argv[]) { dc1394camera_t * camera; dc1394error_t err; dc1394video_frame_t * frame; dc1394_t * d; dc1394camera_list_t * list; d = dc1394_new (); /* Initialize libdc1394 */ if (!d) return 1; err=dc1394_camera_enumerate (d, &list); /* Find cameras */ DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { /* Verify that we have at least one camera */ dc1394_log_error("No cameras found"); return 1; } camera = dc1394_camera_new (d, list->ids[0].guid); /* Work with first camera */ if (!camera) { dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid); return 1; } dc1394_camera_free_list (list); err=dc1394_capture_setup(camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT); /* Setup capture */ err=dc1394_video_set_transmission(camera, DC1394_ON); /* Start transmission */ err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);/* Capture */ DC1394_ERR_RTN(err,"Problem getting an image"); err=dc1394_capture_enqueue(camera, frame); /* Release the buffer */ err=dc1394_video_set_transmission(camera, DC1394_OFF); /* Stop transmission */ err=dc1394_capture_stop(camera); /* Stop capture */ printf("Hello World\n"); /* Hey, this is a HELLO WORLD program!! */ dc1394_camera_free (camera); /* cleanup and exit */ dc1394_free (d); return 0; }
int main (int argc, char **argv) { opts_t opts = OPTS_INIT; dc1394_t *dc1394_cxt = NULL; dc1394camera_list_t *cam_list = NULL; dc1394error_t err; if (argc < 2) { show_help (); return EXIT_SUCCESS; } parse_opts (&opts, argc, argv); dc1394_cxt = dc1394_new (); if (dc1394_cxt == NULL) { printf ("error: dc1394_new() failed.\n"); return EXIT_FAILURE; } err = dc1394_camera_enumerate (dc1394_cxt, &cam_list); if (err != DC1394_SUCCESS || cam_list == NULL) { printf ("error: dc1394_camera_enumerate() failed.\n"); dc1394_free (dc1394_cxt); return EXIT_FAILURE; } /* reset specified buses */ if (opts.show_list == 0) { reset_bus (&opts, dc1394_cxt, cam_list); } else /* show the list of detected cameras */ { list_cameras (dc1394_cxt, cam_list); } dc1394_camera_free_list (cam_list); dc1394_free (dc1394_cxt); return EXIT_SUCCESS; }
void FWCamera::resetBus() { #ifdef AVG_ENABLE_1394_2 dc1394_t* pDC1394 = dc1394_new(); if (pDC1394 == 0) { return; } dc1394camera_list_t * pCameraList; int err=dc1394_camera_enumerate(pDC1394, &pCameraList); if (err == DC1394_SUCCESS) { if (pCameraList->num != 0) { dc1394camera_t * pCam = dc1394_camera_new(pDC1394, pCameraList->ids[0].guid); if (pCam) { dc1394_reset_bus(pCam); dc1394_camera_free(pCam); } } dc1394_camera_free_list(pCameraList); } dc1394_free(pDC1394); #endif }
/** Set up device connection to first camera on the bus. * * @returns true if successful * * Failure cleanup is sketchy, but that is OK because the node * terminates, anyway. */ bool setup(void) { dc1394_t *dev = dc1394_new(); if (dev == NULL) { ROS_FATAL("Failed to initialize dc1394_context."); return false; } // list all 1394 cameras attached to this computer dc1394camera_list_t *cameras; int err = dc1394_camera_enumerate(dev, &cameras); if (err != DC1394_SUCCESS) { ROS_FATAL("Could not get list of cameras"); return false; } if (cameras->num == 0) { ROS_FATAL("No cameras found"); return false; } // attach to first camera found ROS_INFO_STREAM("Connecting to first camera, GUID: " << std::setw(16) << std::setfill('0') << std::hex << cameras->ids[0].guid); camera_ = dc1394_camera_new(dev, cameras->ids[0].guid); if (!camera_) { ROS_FATAL("Failed to initialize camera."); return false; } dc1394_camera_free_list(cameras); return true; }
int main(int argc, char *argv[]) { fitsfile *fptr; long fpixel=1, nelements, naxes[3]; dc1394camera_t *camera; int grab_n_frames; struct timeval start_time, end_time; time_t start_sec, end_sec; suseconds_t start_usec, end_usec; float elapsed_time, fps; int i, status; unsigned int min_bytes, max_bytes, max_height, max_width; unsigned int actual_bytes; uint64_t total_bytes = 0; unsigned int width, height; dc1394video_frame_t *frame=NULL; dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; char *filename; grab_n_frames = atoi(argv[1]); filename = argv[2]; width = 320; height = 240; naxes[0] = width; naxes[1] = height; naxes[2] = grab_n_frames; nelements = naxes[0]*naxes[1]*naxes[2]; stderr = freopen("grab_cube.log", "w", stderr); d = dc1394_new (); if (!d) return 1; err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { dc1394_log_error("No cameras found"); return 1; } camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { dc1394_log_error("Failed to initialize camera with guid %"PRIx64, list->ids[0].guid); return 1; } dc1394_camera_free_list (list); printf("Using camera with GUID %"PRIx64"\n", camera->guid); /*----------------------------------------------------------------------- * setup capture for format 7 *-----------------------------------------------------------------------*/ // err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B); // DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot operate at 1394B"); // libdc1394 doesn't work well with firewire800 yet so set to legacy 400 mode dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400); // configure camera for format7 err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_1); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot choose format7_0"); printf ("I: video mode is format7_0\n"); err = dc1394_format7_get_max_image_size (camera, DC1394_VIDEO_MODE_FORMAT7_1, &max_width, &max_height); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot get max image size for format7_0"); printf ("I: max image size is: height = %d, width = %d\n", max_height, max_width); printf ("I: current image size is: height = %d, width = %d\n", height, width); err = dc1394_format7_set_roi (camera, DC1394_VIDEO_MODE_FORMAT7_1, DC1394_COLOR_CODING_MONO16, // not sure why RAW8/16 don't work DC1394_USE_MAX_AVAIL, 0, 0, // left, top width, height); // width, height DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set roi"); printf ("I: roi is (0, 0) - (%d, %d)\n", width, height); // set the frame rate to absolute value in frames/sec err = dc1394_feature_set_mode(camera, DC1394_FEATURE_FRAME_RATE, DC1394_FEATURE_MODE_MANUAL); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate to manual"); err = dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_FRAME_RATE, DC1394_TRUE); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate to absolute mode"); err = dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_FRAME_RATE, 330.0); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate"); printf("I: framerate is %f fps\n", 330.0); // set the shutter speed to absolute value in seconds err = dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter to manual"); err = dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_SHUTTER, DC1394_TRUE); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter to absolute mode"); err = dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_SHUTTER, 3.0e-3); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter"); printf("I: exptime is %f s\n", 3.0e-3); // set gain manually. use relative value here in range 48 to 730. err = dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set gain to manual"); err = dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 400); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set gain"); printf ("I: gain is %d\n", 400); // set brightness manually. use relative value in range 0 to 1023. err = dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set brightness to manual"); err = dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 100); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set brightness"); printf ("I: brightness is %d\n", 100); err = dc1394_format7_get_total_bytes (camera, DC1394_VIDEO_MODE_FORMAT7_1, &total_bytes); DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot get total bytes"); printf ("I: total bytes is %"PRIu64" before SFF enabled\n", total_bytes); err=dc1394_capture_setup(camera, 16, DC1394_CAPTURE_FLAGS_DEFAULT); DC1394_ERR_CLN_RTN(err, dc1394_camera_free(camera), "Error capturing"); /*----------------------------------------------------------------------- * print allowed and used packet size *-----------------------------------------------------------------------*/ err=dc1394_format7_get_packet_parameters(camera, DC1394_VIDEO_MODE_FORMAT7_1, &min_bytes, &max_bytes); DC1394_ERR_RTN(err,"Packet para inq error"); printf( "camera reports allowed packet size from %d - %d bytes\n", min_bytes, max_bytes); err=dc1394_format7_get_packet_size(camera, DC1394_VIDEO_MODE_FORMAT7_1, &actual_bytes); DC1394_ERR_RTN(err,"dc1394_format7_get_packet_size error"); printf( "camera reports actual packet size = %d bytes\n", actual_bytes); err=dc1394_format7_get_total_bytes(camera, DC1394_VIDEO_MODE_FORMAT7_1, &total_bytes); DC1394_ERR_RTN(err,"dc1394_query_format7_total_bytes error"); printf( "camera reports total bytes per frame = %"PRId64" bytes\n", total_bytes); /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera,DC1394_ON); if (err!=DC1394_SUCCESS) { dc1394_log_error("unable to start camera iso transmission"); dc1394_capture_stop(camera); dc1394_camera_free(camera); exit(1); } // set up FITS image and capture fits_create_file(&fptr, filename, &status); dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_FORMAT7_1, &width, &height); fits_create_img(fptr, USHORT_IMG, 3, naxes, &status); /*----------------------------------------------------------------------- * capture frames and measure the time for this operation *-----------------------------------------------------------------------*/ gettimeofday(&start_time, NULL); printf("Start capture:\n"); for( i = 0; i < grab_n_frames; ++i) { /*----------------------------------------------------------------------- * capture one frame *-----------------------------------------------------------------------*/ err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame); if (err!=DC1394_SUCCESS) { dc1394_log_error("unable to capture"); dc1394_capture_stop(camera); dc1394_camera_free(camera); exit(1); } // attempt to preallocate image array and write to memory before dumping to disk. // turns out to be slow due to large size of images. cfitsio buffering is far // more efficient. //memcpy(im_buffer+2*i*naxes[0]*naxes[1], //frame->image-1, //naxes[0]*naxes[1]*sizeof(short)); // just writing each frame to the FITS file goes pretty fast fits_write_img(fptr, TUSHORT, fpixel+i*naxes[0]*naxes[1], naxes[0]*naxes[1], frame->image-1, &status); // release buffer dc1394_capture_enqueue(camera,frame); } gettimeofday(&end_time, NULL); printf("End capture.\n"); /*----------------------------------------------------------------------- * stop data transmission *-----------------------------------------------------------------------*/ start_sec = start_time.tv_sec; start_usec = start_time.tv_usec; end_sec = end_time.tv_sec; end_usec = end_time.tv_usec; elapsed_time = (float)((end_sec + 1.0e-6*end_usec) - (start_sec + 1.0e-6*start_usec)); fps = grab_n_frames/elapsed_time; printf("Elapsed time = %g seconds.\n", elapsed_time); printf("Framerate = %g fps.\n", fps); err=dc1394_video_set_transmission(camera,DC1394_OFF); DC1394_ERR_RTN(err,"couldn't stop the camera?"); /*----------------------------------------------------------------------- * save FITS image to disk *-----------------------------------------------------------------------*/ //fits_write_img(fptr, TUSHORT, fpixel, naxes[0]*naxes[1]*naxes[2], im_buffer, &status); fits_close_file(fptr, &status); fits_report_error(stderr, status); //free(im_buffer); printf("wrote: %s\n", filename); printf("Image is %d bits/pixel.\n", frame->data_depth); /*----------------------------------------------------------------------- * close camera, cleanup *-----------------------------------------------------------------------*/ dc1394_capture_stop(camera); dc1394_video_set_transmission(camera, DC1394_OFF); dc1394_camera_free(camera); dc1394_free (d); return 0; }
int main(int argc,char *argv[]) { XEvent xev; XGCValues xgcv; long background=0x010203; int i, j; dc1394_t * d; dc1394camera_list_t * list; get_options(argc,argv); /* process options */ switch(fps) { case 1: fps = DC1394_FRAMERATE_1_875; break; case 3: fps = DC1394_FRAMERATE_3_75; break; case 15: fps = DC1394_FRAMERATE_15; break; case 30: fps = DC1394_FRAMERATE_30; break; case 60: fps = DC1394_FRAMERATE_60; break; default: fps = DC1394_FRAMERATE_7_5; break; } switch(res) { case 1: res = DC1394_VIDEO_MODE_640x480_YUV411; device_width=640; device_height=480; format=XV_YUY2; break; case 2: res = DC1394_VIDEO_MODE_640x480_RGB8; device_width=640; device_height=480; format=XV_YUY2; break; case 3: res = DC1394_VIDEO_MODE_800x600_YUV422; device_width=800; device_height=600; format=XV_UYVY; break; default: res = DC1394_VIDEO_MODE_320x240_YUV422; device_width=320; device_height=240; format=XV_UYVY; break; } dc1394error_t err; d = dc1394_new (); if (!d) return 1; err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { dc1394_log_error("No cameras found"); return 1; } j = 0; for (i = 0; i < list->num; i++) { if (j >= MAX_CAMERAS) break; cameras[j] = dc1394_camera_new (d, list->ids[i].guid); if (!cameras[j]) { dc1394_log_warning("Failed to initialize camera with guid %llx", list->ids[i].guid); continue; } j++; } numCameras = j; dc1394_camera_free_list (list); if (numCameras == 0) { dc1394_log_error("No cameras found"); exit (1); } /* setup cameras for capture */ for (i = 0; i < numCameras; i++) { //err=dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_400); //dc1394_video_set_operation_mode(my_camera_ptr[i], DC1394_OPERATION_MODE_1394B); err= dc1394_video_set_operation_mode(cameras[i], DC1394_OPERATION_MODE_1394B); err=dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_800); DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set ISO speed"); err=dc1394_video_set_mode(cameras[i], res); DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set video mode"); err=dc1394_video_set_framerate(cameras[i], fps); DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set framerate"); err=dc1394_capture_setup(cameras[i],NUM_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT); DC1394_ERR_CLN_RTN(err,cleanup(),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera"); err=dc1394_video_set_transmission(cameras[i], DC1394_ON); DC1394_ERR_CLN_RTN(err,cleanup(),"Could not start camera iso transmission"); // Camera settings err = dc1394_feature_set_value(cameras[i],DC1394_FEATURE_SHUTTER,1400); err = dc1394_feature_set_value(cameras[i],DC1394_FEATURE_BRIGHTNESS,800); err = dc1394_feature_set_value(cameras[i],DC1394_FEATURE_EXPOSURE,150); err = dc1394_feature_whitebalance_set_value(cameras[i],500,400); } fflush(stdout); if (numCameras < 1) { perror("no cameras found :(\n"); cleanup(); exit(-1); } switch(format){ case XV_YV12: set_frame_length(device_width*device_height*3/2, numCameras); break; case XV_YUY2: case XV_UYVY: set_frame_length(device_width*device_height*2, numCameras); break; default: dc1394_log_error("Unknown format set (internal error)"); exit(255); } /* make the window */ display=XOpenDisplay(getenv("DISPLAY")); if(display==NULL) { dc1394_log_error("Could not open display \"%s\"",getenv("DISPLAY")); cleanup(); exit(-1); } QueryXv(); if ( adaptor < 0 ) { cleanup(); exit(-1); } width=device_width; height=device_height * numCameras; //width=device_width * numCameras; //height=device_height; window=XCreateSimpleWindow(display,DefaultRootWindow(display),0,0,width,height,0, WhitePixel(display,DefaultScreen(display)), background); XSelectInput(display,window,StructureNotifyMask|KeyPressMask); XMapWindow(display,window); connection=ConnectionNumber(display); gc=XCreateGC(display,window,0,&xgcv); /* main event loop */ while(1){ for (i = 0; i < numCameras; i++) { if (dc1394_capture_dequeue(cameras[i], DC1394_CAPTURE_POLICY_WAIT, &frames[i])!=DC1394_SUCCESS) dc1394_log_error("Failed to capture from camera %d", i); } display_frames(); XFlush(display); while(XPending(display)>0){ XNextEvent(display,&xev); switch(xev.type){ case ConfigureNotify: width=xev.xconfigure.width; height=xev.xconfigure.height; display_frames(); break; case KeyPress: switch(XKeycodeToKeysym(display,xev.xkey.keycode,0)){ case XK_q: case XK_Q: cleanup(); exit(0); break; case XK_comma: case XK_less: //width=width/2; //height=height/2; width--; XResizeWindow(display,window,width,height); display_frames(); break; case XK_period: case XK_greater: //width=2*width; //height=2*height; width++; XResizeWindow(display,window,width,height); display_frames(); break; case XK_0: freeze = !freeze; break; case XK_1: fps = DC1394_FRAMERATE_1_875; for (i = 0; i < numCameras; i++) dc1394_video_set_framerate(cameras[i], fps); break; case XK_2: fps = DC1394_FRAMERATE_3_75; for (i = 0; i < numCameras; i++) dc1394_video_set_framerate(cameras[i], fps); break; case XK_4: fps = DC1394_FRAMERATE_15; for (i = 0; i < numCameras; i++) dc1394_video_set_framerate(cameras[i], fps); break; case XK_5: fps = DC1394_FRAMERATE_30; for (i = 0; i < numCameras; i++) dc1394_video_set_framerate(cameras[i], fps); break; case XK_3: fps = DC1394_FRAMERATE_7_5; for (i = 0; i < numCameras; i++) dc1394_video_set_framerate(cameras[i], fps); break; } break; } } /* XPending */ for (i = 0; i < numCameras; i++) { if (frames[i]) dc1394_capture_enqueue (cameras[i], frames[i]); } } /* while not interrupted */ exit(0); }
void *pdp_dc1394_new(t_symbol *vdef) { t_pdp_dc1394 *x = (t_pdp_dc1394 *)pd_new(pdp_dc1394_class); x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); x->d = dc1394_new (); x->err=dc1394_camera_enumerate (x->d, &x->list); //DC1394_ERR_RTN(x->err,"Failed to enumerate cameras"); //post("Failed to enumerate cameras"); if (x->list->num == 0) { dc1394_log_error("No cameras found"); return 1; } x->camera = dc1394_camera_new (x->d, x->list->ids[0].guid); if (!x->camera) { //dc1394_log_error("Failed to initialize camera with guid %"PRIx64, list->ids[0].guid); return 1; } dc1394_camera_free_list (x->list); //printf("Using camera with GUID %"PRIx64"\n", camera->guid); /*----------------------------------------------------------------------- * get the best video mode and highest framerate. This can be skipped * if you already know which mode/framerate you want... *-----------------------------------------------------------------------*/ // get video modes: x->err=dc1394_video_get_supported_modes(x->camera,&x->video_modes); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Can't get video modes"); // select highest res mode: for (x->i=x->video_modes.num-1;x->i>=0;x->i--) { if (!dc1394_is_video_mode_scalable(x->video_modes.modes[x->i])) { dc1394_get_color_coding_from_video_mode(x->camera,x->video_modes.modes[x->i], &x->coding); if (x->coding==DC1394_COLOR_CODING_MONO8) { x->video_mode=x->video_modes.modes[x->i]; fprintf(stderr,"video_mode %d: %d\n",x->i,x->video_modes.modes[x->i]); break; } } } if (x->i < 0) { dc1394_log_error("Could not get a valid MONO8 mode"); cleanup_and_exit(x->camera); } x->err=dc1394_get_color_coding_from_video_mode(x->camera, x->video_mode,&x->coding); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not get color coding"); fprintf(stderr,"color_coding : %d\n",x->coding); // get highest framerate x->err=dc1394_video_get_supported_framerates(x->camera,x->video_mode,&x->framerates); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not get framrates"); x->framerate=x->framerates.framerates[x->framerates.num-1]; fprintf(stderr,"framerate : %d\n",x->framerate); /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ x->err=dc1394_video_set_iso_speed(x->camera, DC1394_ISO_SPEED_400); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set iso speed"); x->err=dc1394_video_set_mode(x->camera, x->video_mode); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set video mode"); x->err=dc1394_video_set_framerate(x->camera, x->framerate); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set framerate"); x->err=dc1394_capture_setup(x->camera,4, DC1394_CAPTURE_FLAGS_DEFAULT); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera"); /*----------------------------------------------------------------------- * report camera's features *-----------------------------------------------------------------------*/ x->err=dc1394_feature_get_all(x->camera,&x->features); if (x->err!=DC1394_SUCCESS) { dc1394_log_warning("Could not get feature set"); } else { dc1394_feature_print_all(&x->features, stdout); } /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ x->err=dc1394_video_set_transmission(x->camera, DC1394_ON); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not start camera iso transmission"); x->x_initialized = true; return (void *)x; }
bool ieee1394capture::init(RoboCompCamera::TCamParams ¶ms_, RoboCompJointMotor::JointMotorPrx head_ , RoboCompDifferentialRobot::DifferentialRobotPrx base_ ) { params = params_; head = head_; base = base_; int32_t i; fps = (dc1394framerate_t)params.FPS;//15; res = (dc1394video_mode_t)0; switch (fps) { case 1: fps = DC1394_FRAMERATE_1_875; break; case 3: fps = DC1394_FRAMERATE_3_75; break; case 15: fps = DC1394_FRAMERATE_15; break; case 30: fps = DC1394_FRAMERATE_30; break; case 60: fps = DC1394_FRAMERATE_60; break; default: fps = DC1394_FRAMERATE_7_5; break; } switch (res) { case 1: res = DC1394_VIDEO_MODE_640x480_YUV411; device_width = 640; device_height = 480; break; case 2: res = DC1394_VIDEO_MODE_640x480_RGB8; device_width = 640; device_height = 480; break; default: res = DC1394_VIDEO_MODE_320x240_YUV422; device_width = 320; device_height = 240; break; } /// Get handle qDebug() << "ieee1394capture::init() -> Initializating first Firewire Card in the system..."; if (!(d = dc1394_new())) { qDebug() << "ieee1394capture::init() -> Fatal error: Unable to aquire a handle to the Ieee1394 device"; qDebug() << "Please check if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded or if you have read/write access to /dev/raw1394 and to /dev/video1394-0 " ; return false; } CREATED_BUS = true; /// Create camera interfaces numCameras = 0; err = dc1394_camera_enumerate(d, &list); DC1394_ERR_RTN(err, "Failed to enumerate cameras"); if (list->num == 0) { dc1394_log_error("No cameras found"); return 1; } numCameras = 0; for (uint32_t di = 0; di < list->num; di++) { if (numCameras >= MAX_CAMERAS) break; cameras[numCameras] = dc1394_camera_new(d, list->ids[di].guid); if (!cameras[numCameras]) { dc1394_log_warning("Failed to initialize camera with guid %llx", list->ids[di].guid); continue; } printf("Camera #%d\n", numCameras); numCameras++; } dc1394_camera_free_list(list); if ( numCameras < 1 ) { qDebug() << "ieee1394capture::init() -> Fatal error: No cameras found in the bus! Called from "; cleanup(); return false; } /// Check if one camera has become the root node /* for ( int n=0; n < numCameras; n++ ) { if ( cameraNodeList[n] == numNodes ) { qDebug() << "ieee1394capture::init() -> Fatal error: Sorry, your camera is the highest numbered node of the bus, and has therefore become the root node." ; cleanup(); return false; } }*/ CREATED_CAMS = true; /// Setup cameras for capture qDebug() << "ieee1394capture::init() -> Searching cameras with requested parameters:"; printf("%s\n",params.mode.c_str()); if (params.mode == "MODE_320x240_YUV422") { res = DC1394_VIDEO_MODE_320x240_YUV422; params.width = 320; params.height = 240; } else if (params.mode == "MODE_640x480_YUV422" ) { res = DC1394_VIDEO_MODE_640x480_YUV422; params.width = 640; params.height = 480; } else if (params.mode == "MODE_640x480_RGB" ) { res = DC1394_VIDEO_MODE_640x480_RGB8; params.width = 640; params.height = 480; } else if (params.mode == "MODE_640x480_YUV411") { res = DC1394_VIDEO_MODE_640x480_YUV411; params.width = 640; params.height = 480; } else if (params.mode == "MODE_640x480_MONO") { res = DC1394_VIDEO_MODE_640x480_MONO8; params.width = 640; params.height = 480; } else if (params.mode == "MODE_640x480_MONO16") { res = DC1394_VIDEO_MODE_640x480_MONO16; params.width = 640; params.height = 480; } else if (params.mode == "MODE_516x338_YUV422") { res = DC1394_VIDEO_MODE_FORMAT7_1; params.width = 516; params.height = 338; } else qFatal("ieee1394capture::init() -> Image Mode %s not available. Aborting...", params.mode.c_str()); params.size = params.width*params.height; if (params.FPS!=15 and params.FPS!=30) { qWarning("ieee1394capture::init() -> Framerate %d not available. Aborting...", params.FPS ); cleanup(); return false; } dc1394format7modeset_t info; for (i = 0; i < numCameras; i++) { if (params.mode == "MODE_516x338_YUV422") { err = dc1394_format7_get_modeset(cameras[i], &info); for( int j=0;j<DC1394_VIDEO_MODE_FORMAT7_NUM;j++) { qDebug() << info.mode[j].present; qDebug() << info.mode[j].size_x; qDebug() << info.mode[j].size_y; qDebug() << info.mode[j].max_size_x; qDebug() << info.mode[j].max_size_y; qDebug() << info.mode[j].pos_x; qDebug() << info.mode[j].pos_y; qDebug() << info.mode[j].unit_size_x; qDebug() << info.mode[j].unit_size_y; qDebug() << info.mode[j].unit_pos_x; qDebug() << info.mode[j].unit_pos_y; qDebug() << info.mode[j].pixnum; qDebug() << info.mode[j].packet_size; /* in bytes */ qDebug() << info.mode[j].unit_packet_size; qDebug() << info.mode[j].max_packet_size; } } release_iso_and_bw(i); err = dc1394_video_set_mode(cameras[i], res); DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set video mode"); err = dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_400); DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set ISO speed"); //For format 7 modes only if (params.mode == "MODE_516x338_YUV422") { // uint32_t packet_size; // err=dc1394_format7_set_image_size(cameras[i], res, 514, 384); // DC1394_ERR_RTN(err,"Could not set image size"); // err=dc1394_format7_get_recommended_packet_size(cameras[i], res, &packet_size); // DC1394_ERR_RTN(err,"Could not get format 7 recommended packet size"); // err=dc1394_format7_set_roi(cameras[i], res, DC1394_COLOR_CODING_YUV422, packet_size, 0,0, 514, 384); // DC1394_ERR_RTN(err,"Could not set ROI"); qDebug() << "ya"; } err = dc1394_video_set_framerate(cameras[i], fps); DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set framerate"); err = dc1394_capture_setup(cameras[i], NUM_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT); DC1394_ERR_CLN_RTN(err, cleanup(), "Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera"); err = dc1394_video_set_transmission(cameras[i], DC1394_ON); DC1394_ERR_CLN_RTN(err, cleanup(), "Could not start camera iso transmission"); } fflush(stdout); qDebug() << " ieee1394capture::init() -> Iso transmission started."; ///Buffers de imagen qDebug() << "BUFFERS DE IMAGEN ------------------------------------------"; for ( int i=0; i < numCameras; i++ ) { AimgBuffer[i] = ( Ipp8u * ) ippsMalloc_8u ( params.size * 9 ); BimgBuffer[i] = ( Ipp8u * ) ippsMalloc_8u ( params.size * 9 ); img8u_lum[i] = AimgBuffer[i]; img8u_YUV[i] = AimgBuffer[i]+params.size; localYRGBImgBufferPtr[i] = BimgBuffer[i]; qDebug() << "Reservando" << params.size * 9 <<" para localYRGBImgBufferPtr["<<i<<"]"; printf("(de %p a %p)\n", localYRGBImgBufferPtr[i], localYRGBImgBufferPtr[i]+(params.size*9-1)); } planos[0]=BimgBuffer[0]+params.size*3; planos[1]=BimgBuffer[0]+ ( params.size*4 ); planos[2]=BimgBuffer[0]+ ( params.size*5 ); //img8u_aux = BimgBuffer[0]+(params.size*6); imgSize_ipp.width=params.width; imgSize_ipp.height=params.height; return true; }
CvDC1394::CvDC1394() { dc = dc1394_new(); FD_ZERO(&camFds); }
//-------------------------------------------------------------------- int of1394VideoGrabber::initGrabber() { // moved from constructor int i; printf("Making new camera\n"); d = dc1394_new (); err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { if(err!=0 && bVerbose)printf("\n No cameras found\n "); return 1; } camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { if(err!=0 && bVerbose)printf("\n Failed to initialize camera with guid %PRIx64", list->ids[0].guid); return 1; } dc1394_camera_free_list (list); /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0); uint32_t f, f2; dc1394_format7_get_image_size(camera, DC1394_VIDEO_MODE_FORMAT7_0, &f, &f2); err=dc1394_capture_setup(camera,4, DC1394_CAPTURE_FLAGS_DEFAULT); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera\n"); /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera, DC1394_ON); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not start camera iso transmission\n"); dc1394_get_image_size_from_video_mode(camera, video_mode, &width, &height); if(err != DC1394_SUCCESS){ cout<<"get image size error: "<<err<<endl; } printf("Size from video mode = %i wide %i high\n", width, height); pixels = new unsigned char[width*height*3]; // x3 for RGB pixels2 = new unsigned char[width*height*3]; // x3 for RGB tex.allocate(width,height,GL_LUMINANCE); err = dc1394_capture_dequeue( camera, DC1394_CAPTURE_POLICY_WAIT, &frame ) ; DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not capture a frame\n"); memcpy( pixels, frame->image, width * height*3) ; dc1394_capture_enqueue( camera, frame ) ; ofSleepMillis(10); startThread(true, false); failedToInit = false; dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(camera, DC1394_FEATURE_GAMMA, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_IRIS, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_WHITE_BALANCE, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_TEMPERATURE, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_WHITE_SHADING, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_SATURATION, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_HUE, DC1394_FEATURE_MODE_AUTO); //Print features dc1394_feature_get_all(camera, &features); dc1394_feature_print_all(&features, stdout); return 0; }
/************************************************************************************** ** Client is asking us to establish connection to the device ***************************************************************************************/ bool FFMVCCD::Connect() { dc1394camera_list_t *list; dc1394error_t err; bool supported; bool settings_valid; uint32_t val; dc1394format7mode_t fm7; dc1394feature_info_t feature; float min, max; dc1394 = dc1394_new(); if (!dc1394) { return false; } err = dc1394_camera_enumerate(dc1394, &list); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not find DC1394 cameras!"); return false; } if (!list->num) { IDMessage(getDeviceName(), "No DC1394 cameras found!"); return false; } dcam = dc1394_camera_new(dc1394, list->ids[0].guid); if (!dcam) { IDMessage(getDeviceName(), "Unable to connect to camera!"); return false; } /* Reset camera */ err = dc1394_camera_reset(dcam); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to reset camera!"); return false; } /* Set mode */ err = dc1394_video_set_mode(dcam, DC1394_VIDEO_MODE_640x480_MONO16); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to connect to set videomode!"); return false; } /* Disable Auto exposure control */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_EXPOSURE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable auto exposure control"); return false; } /* Set frame rate to the lowest possible */ err = dc1394_video_set_framerate(dcam, DC1394_FRAMERATE_7_5); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to connect to set framerate!"); return false; } /* Turn frame rate control off to enable extended exposure (subs of 512ms) */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_FRAME_RATE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable framerate!"); return false; } /* Get the longest possible exposure length */ err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable manual shutter control."); } err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_SHUTTER, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable absolute shutter control."); } err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_SHUTTER, &min, &max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not get max shutter length"); } else { max_exposure = max; } /* Set gain to max. By setting the register directly, we can achieve a * gain of 24 dB...compared to a gain of 12 dB which is reported as the * max */ err = dc1394_set_control_register(dcam, 0x820, 0x40); //err = dc1394_set_control_register(dcam, 0x820, 0x7f); if (err != DC1394_SUCCESS) { return err; } #if 0 /* Set absolute gain to max */ err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_GAIN, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable ansolute gain control."); } err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_GAIN, &min, &max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not get max gain value"); } else { err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAIN, max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set max gain value"); } } #endif /* Set brightness */ err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable manual brightness control."); } err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable ansolute brightness control."); } err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_BRIGHTNESS, 1); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set max brightness value"); } /* Turn gamma control off */ err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAMMA, 1); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set gamma value"); } err = dc1394_feature_set_power(dcam, DC1394_FEATURE_GAMMA, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable gamma!"); return false; } /* Turn off white balance */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_WHITE_BALANCE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable white balance!"); return false; } err=dc1394_capture_setup(dcam,10, DC1394_CAPTURE_FLAGS_DEFAULT); return true; }
VideoIIDC1394::VideoIIDC1394(int source, uint8_t iso, uint8_t vid_mode, uint8_t f_rate, uint32_t w, uint32_t h) { #if defined(DUNE_WITH_DC1394) std::cout << " Entered constructor " << std:: endl; width = w; height = h; iidc = dc1394_new(); frame = NULL; std::cout << " Built Object " << std:: endl; dc1394error_t error_code; if (!iidc) { throw std::runtime_error("Failed to start IEEE 1394 IIDC interface"); } error_code = dc1394_camera_enumerate(iidc, &list); std::cout << " Enumerated camera objects " << std:: endl; if (error_code < 0) { throw std::runtime_error("Failed to enumerate cameras"); } std::cout << "Number of cameras found: " << list->num << std:: endl; camera = dc1394_camera_new(iidc, list->ids[0].guid); std::cout << " Built new camera object " << std:: endl; if (!camera) { throw std::runtime_error("Failed to initialize camera"); } dc1394_camera_free_list(list); error_code = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400); if (error_code < 0) { throw std::runtime_error("Failed to set ISO SPEED"); } error_code = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_640x480_YUV422); if (error_code < 0) { throw std::runtime_error("Failed to set video mode"); } error_code = dc1394_video_set_framerate(camera, DC1394_FRAMERATE_15); if (error_code < 0) { free(this); throw std::runtime_error("Failed to set ISO SPEED"); } error_code = dc1394_capture_setup(camera, 8, DC1394_CAPTURE_FLAGS_DEFAULT); if (error_code < 0) { throw std::runtime_error("Failed to set ISO SPEED"); } error_code = dc1394_video_set_transmission(camera, DC1394_ON); if (error_code < 0) { throw std::runtime_error("Could not start video capture"); } converted_frame = new dc1394video_frame_t; std::memset(converted_frame, 0, sizeof(dc1394video_frame_t)); std::cout << " Finished setting everything up " << std:: endl; #else (void)source; (void)iso; (void)vid_mode; (void)f_rate; (void)w; (void)h; throw std::runtime_error("IIDC Firewire Video interface is not yet implemented in this system."); #endif }
int main (int argc, char **argv) { char* ntry = (char*)""; if (argc > 1) { ntry = argv[1]; } double fps = FPS; double target_dur = 1.0/fps; double tol = 1.0e-3; double total_dur = 0.0; dc1394_t * d = dc1394_new(); if (!d) { return 1; } dc1394camera_list_t * list; dc1394error_t err = dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { /* Verify that we have at least one camera */ dc1394_log_error("No cameras found"); return 1; } gCamera.init(d, list->ids[0].guid); if (!gCamera.cam()) { dc1394_log_error("Failed to initialize camera with guid %ld", list->ids[0].guid); dc1394_camera_free_list (list); return 1; } dc1394_camera_free_list (list); /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ err = gCamera.start_transmission(); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(gCamera),"Could not start camera iso transmission"); /*----------------------------------------------------------------------- * capture one frame *-----------------------------------------------------------------------*/ uint32_t width = 0; uint32_t height = 0; gCamera.get_image_size(&width, &height); cv::Mat mapping = cv::getRotationMatrix2D(cv::Point2f(width/2.0, height/2.0), 180.0, 1.0); #ifdef USE_SDL static char *var = (char*)"SDL_VIDEO_WINDOW_POS=\"1280,480\""; int ret = putenv(var); if (SDL_Init(SDL_INIT_VIDEO) != 0) { std::cerr << "DC1394: Unable to initialize SDL: " << SDL_GetError() << std::endl; return 1; } atexit(SDL_Quit); SDL_Surface *screen; screen = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE); if (screen == NULL) { std::cerr << "DC1394: Unable to set SDL video mode:" << SDL_GetError() << std::endl; } SDL_Event event; #endif #ifndef LICKOMETER pthread_t save_thread, acq_thread; pthread_create( &save_thread, NULL, &thread_save_image, NULL); #endif pthread_t save_thread, acq_thread; pthread_create( &acq_thread, NULL, &thread_acq_image, NULL); timespec t_sleep, t_rem; t_sleep.tv_sec = 0; t_sleep.tv_nsec = 1000; #ifndef STANDALONE int s; if ((s = socket(SOCKTYPE, SOCK_STREAM, 0)) < 0) { perror("DC1394: client: socket"); cleanup_and_exit(gCamera); return 1; } /* * Create the address we will be connecting to. */ #ifndef INET sockaddr_un sa; sa.sun_family = AF_UNIX; std::ostringstream tmpfn; tmpfn << "fwsocket" << ntry; std::cout << "DC1394: socket name " << tmpfn.str() << std::endl; int nameLen = strlen(tmpfn.str().c_str()); if (nameLen >= (int) sizeof(sa.sun_path) -1) { /* too long? */ cleanup_and_exit(gCamera); return 1; } sa.sun_path[0] = '\0'; /* abstract namespace */ strcpy(sa.sun_path+1, tmpfn.str().c_str()); int len = 1 + nameLen + offsetof(struct sockaddr_un, sun_path); #else sockaddr_in sa; bzero((char *) &sa, sizeof(sa)); sa.sin_family = AF_INET; hostent *server = gethostbyname("128.40.156.129"); bcopy((char *)server->h_addr, (char *)&sa.sin_addr.s_addr, server->h_length); sa.sin_port = htons(35000); int len = sizeof(sa); #endif /* * Try to connect to the address. For this to * succeed, the server must already have bound * this address, and must have issued a listen() * request. * * The third argument indicates the "length" of * the structure, not just the length of the * socket name. */ std::cout << "DC1394: Waiting for connection... " << std::flush; while (true) { // wait for connection: if (connect(s, (sockaddr*)&sa, len) < 0) { nanosleep(&t_sleep, &t_rem); } else { break; } } std::cout << "done" << std::endl; bool connected = false; std::vector<char> data(BUFSIZE); int nrec = recv(s, &data[0], data.size(), 0); std::string datastr(data.begin(), data.end()); if (nrec<=0) { std::cerr << "DC1394: Didn't receive start message; exiting now" << std::endl; cleanup_and_exit(gCamera); close(s); return 1; } connected = true; std::string ready = "ready"; while (send(s, ready.c_str(), ready.size(), 0) < 0) { perror("DC1394: client: send"); } int flags = 0; if (-1 == (flags = fcntl(s, F_GETFL, 0))) flags = 0; if (fcntl(s, F_SETFL, flags | O_NONBLOCK)==-1) { perror("DC1394: client: unblock"); } #endif /* pthread_mutex_lock( &camera_mutex ); gCamera.wait_for_trigger(); pthread_mutex_unlock( &camera_mutex ); Wait for acq_frame_buffer to fill instead */ int ncount = 0; cv::Mat im(cv::Size(width, height), CV_8UC1); cv::Mat thresh = cv::Mat::ones(cv::Size(width, height), CV_8UC1); cv::Mat prevs(cv::Size(width, height), CV_8UC1); cv::Mat gray(cv::Size(width, height), CV_8UC1); // wait for image: int nframes = get_image(im, mapping, false, -1, "", ncount); std::cout << "DC1394: Waiting for first image to arrive... " << std::flush; int nwait = 0; while (!nframes) { nanosleep(&t_sleep, &t_rem); std::cout << "." << std::flush; nframes = get_image(im, mapping, false, -1, "", ncount); nwait++; #ifdef STANDALONE if (nwait > 1000) { #else if (nwait > 100000) { #endif std::cout << "Time out, stopping now\n"; cleanup_and_exit(gCamera); } } timespec time0; clock_gettime(CLOCK_REALTIME, &time0); std::cout << "DC1394: image arrived: " << IplImage(im).depth << " bits, " << IplImage(im).nChannels << " channels, " << IplImage(im).widthStep << " step width" << std::endl; #ifdef USE_SDL SDL_Surface *surface = SDL_CreateRGBSurfaceFrom((void*)im.data, im.cols, im.rows, IplImage(im).depth*IplImage(im).nChannels, IplImage(im).widthStep, 0xffffff, 0xffffff, 0xffffff, 0); screen = SDL_GetVideoSurface(); if(SDL_BlitSurface(surface, NULL, screen, NULL) == 0) SDL_UpdateRect(screen, 0, 0, 0, 0); #else cv::namedWindow("DC1394", CV_WINDOW_AUTOSIZE); cvMoveWindow("DC1394", 1280, 480); cv::imshow("DC1394", im); #endif timespec time1 = time0; timespec time2 = time0; timespec time3 = time0; timespec time4 = time0; timespec t_disconnect = time0; timespec t_notrigger = time0; #ifdef STANDALONE int s = -1; #endif std::string fn = ""; #ifdef LICKOMETER std::string fn_lick = ""; FILE* fp_lick = NULL; #endif int key = 0; int nloop = 0; while (true) { clock_gettime( CLOCK_REALTIME, &time1); #ifndef STANDALONE std::vector<char> data(BUFSIZE); int nrec = recv(s, &data[0], data.size(), 0); std::string datastr(data.begin(), data.end()); #endif nframes += get_image(im, mapping, false, s, fn, ncount); #ifndef STANDALONE // no update from blender in a long time, terminate process if (datastr.find("1")==std::string::npos) { if (connected) { t_disconnect = time1; connected = false; } else { if (tdiff(time1, t_disconnect) > TIMEOUT) { std::cout << "DC1394: Received termination signal" << std::endl; close(s); pthread_cancel(acq_thread); pthread_cancel(save_thread); return 0; } } } else { connected = true; } /* Explicit termination */ if (datastr.find("quit")!=std::string::npos) { std::cout << "DC1394: Game over signal." << std::endl; std::string sclose = "close"; while (send(s, sclose.c_str(), sclose.size(), 0) < 0) { perror("DC1394: client: send"); } close(s); pthread_cancel(acq_thread); pthread_cancel(save_thread); return 0; } // Stop recording if (datastr.find("stop") != std::string::npos && fn != "") { fn = ""; #ifdef LICKOMETER fn_lick = ""; if (fp_lick) { fclose(fp_lick); fp_lick = NULL; } #endif std::cout << "DC1394: Stopping video" << std::endl; connected = true; ncount = 0; } // Start recording if (datastr.find("avi") != std::string::npos && datastr.find("stop") == std::string::npos && fn == "") { std::size_t startpos = datastr.find("begin")+5; std::size_t endpos = datastr.find("end") - datastr.find("begin") - 5; fn = datastr.substr(startpos, endpos); fn = std::string(trunk) + "data/" + fn; #ifdef LICKOMETER fn_lick = fn + "_lick"; fp_lick = fopen(fn_lick.c_str(), "wb"); std::cout << "DC1394: Recording lick detection, writing to " << fn_lick << std::endl; #else boost::filesystem::path path(fn); boost::filesystem::path writepath(path); // Test whether dir exists: if (!boost::filesystem::exists(writepath)) { std::cout << "DC1394: Creating directory " << writepath << std::endl; boost::filesystem::create_directories(writepath); } fn += "/"; /* check save frame buffer */ std::size_t nfb = save_frame_buffer.size(); if (nfb) std::cerr << "DC1394: Frame buffer isn't empty!" << std::endl; std::cout << "DC1394: Starting video, writing to " << fn << std::endl; connected = true; ncount = 0; #endif } #endif // #nstandalone #ifdef USE_SDL if (SDL_PollEvent(&event)) { #ifdef STANDALONE /* Any of these event types will end the program */ if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) { std::cout << std::endl; std::cout << std::endl << "DC1394: Total number of frames was " << nframes << std::endl; std::cout << std::endl << "DC1394: Frame buffer: " << acq_frame_buffer.size() << " frames left" << std::endl; close(s); pthread_cancel(acq_thread); pthread_cancel(save_thread); return 0; } #endif // STANDALONE } surface->pixels = (void*)im.data; // SDL_CreateRGBSurfaceFrom((void*)IplImage(im).imageData, // IplImage(im).width, // IplImage(im).height, // IplImage(im).depth*IplImage(im).nChannels, // IplImage(im).widthStep, // 1, 1, 1, 0); screen = SDL_GetVideoSurface(); if(SDL_BlitSurface(surface, NULL, screen, NULL) == 0) SDL_UpdateRect(screen, 0, 0, 0, 0); #else // not SDL key = cv::waitKey(2); cv::imshow("DC1394", im); if (key == 1114155 || key == 65579 || key==43 /*+*/) { uint32_t gain = 0; err = dc1394_feature_get_value(gCamera.cam(), DC1394_FEATURE_GAIN, &gain); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(gCamera),"Can't get gain"); if (gain < gCamera.get_maxgain()-10) { gain += 10; pthread_mutex_lock( &camera_mutex ); err = dc1394_feature_set_value(gCamera.cam(), DC1394_FEATURE_GAIN, gain); pthread_mutex_unlock( &camera_mutex ); std::cout << "DC1394: New gain value: " << gain << std::endl; DC1394_ERR_CLN_RTN(err,cleanup_and_exit(gCamera),"Can't set gain"); } } if (key == 1114207 || key == 45 /*-*/) { uint32_t gain = 0; err = dc1394_feature_get_value(gCamera.cam(), DC1394_FEATURE_GAIN, &gain); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(gCamera),"Can't get gain"); if (gain > gCamera.get_mingain()+10) { gain -= 10; pthread_mutex_lock( &camera_mutex ); err = dc1394_feature_set_value(gCamera.cam(), DC1394_FEATURE_GAIN, gain); pthread_mutex_unlock( &camera_mutex ); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(gCamera),"Can't set gain"); } } #endif // not SDL #ifdef LICKOMETER /* IS THIS ALL YOU NEED THEN? Lick detection */ /* Not required because the captured image is already gray cv::Mat gray = bgr2gray(im); */ gray = thresholding(im, LICK_FRAME_THRESHOLD); if (nloop != 0) { cv::absdiff(prevs, gray, thresh); double pixel_sum_thresh = cv::sum(thresh)[0]; double pixel_sum_gray = cv::sum(gray)[0]; if (pixel_sum_thresh > LICK_SUM_THRESHOLD) { std::cout << "DC1394: Lick" << std::endl; } if (fp_lick != NULL) { fwrite(&pixel_sum_thresh, sizeof(pixel_sum_thresh), 1, fp_lick); fwrite(&pixel_sum_gray, sizeof(pixel_sum_gray), 1, fp_lick); } } prevs = gray.clone(); nloop++; #endif #ifdef STANDALONE if (key == 1048689 || key == 113 /*q*/) { std::cout << "DC1394: Mean frame rate was " << nframes/total_dur << " fps" << std::endl; pthread_cancel(acq_thread); pthread_cancel(save_thread); return 0; } if (key == 1048691 /*s*/) { fn = ""; std::cout << "DC1394: Stopping video" << std::endl; ncount = 0; } if (key == 1048690 /*r*/) { fn = trunk + std::string("tmp/"); std::cout << "DC1394: Starting video, writing to " << fn << std::endl; ncount = 0; } #endif // #standalone clock_gettime( CLOCK_REALTIME, &time2); double loop_dur = tdiff(time2, time3); clock_gettime( CLOCK_REALTIME, &time3); double meanfps = 0; total_dur = tdiff(time3, time0); if (total_dur > 0) meanfps = nframes / total_dur; double currentfps = ret / loop_dur; std::cout << "DC1394: Current fps: " << std::setprecision(7) << currentfps << " Average fps: " << std::setprecision(7) << meanfps << "\r" << std::flush; #ifdef STANDALONE // std::cout << capture_dur << "\t" << target_dur << "\t" << rem << "\t" << loop_dur << std::endl; #endif } if (d) { dc1394_free(d); } #ifndef STANDALONE close(s); #endif return 0; }
int main(int argc, char *argv[]) { FILE* imagefile; dc1394camera_t *camera; unsigned int width, height; dc1394video_frame_t *frame=NULL; //dc1394featureset_t features; dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; int counter = 0; d = dc1394_new (); if (!d) return 1; err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { dc1394_log_error("No cameras found"); return 1; } camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid); return 1; } dc1394_camera_free_list (list); printf("Using camera with GUID %" PRIx64 "\n", camera->guid); /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ err=dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set iso speed"); err=dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_7); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set video mode\n"); err=dc1394_video_set_framerate(camera, DC1394_FRAMERATE_7_5); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set framerate\n"); err=dc1394_capture_setup(camera,4, DC1394_CAPTURE_FLAGS_DEFAULT); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera\n"); /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera, DC1394_ON); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not start camera iso transmission\n"); for(;;){ /*----------------------------------------------------------------------- * capture one frame *-----------------------------------------------------------------------*/ err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not capture a frame\n"); dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_FORMAT7_7, &width, &height); cv::Mat img = cv::Mat(height, width, CV_8U, frame->image); err = dc1394_capture_enqueue(camera, frame); frame=NULL; cv::imshow("Image", img); printf("Frame %d\n", counter); counter++; cv::waitKey(10); } /*----------------------------------------------------------------------- * stop data transmission *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera,DC1394_OFF); DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not stop the camera?\n"); /*----------------------------------------------------------------------- * close camera *-----------------------------------------------------------------------*/ dc1394_video_set_transmission(camera, DC1394_OFF); dc1394_capture_stop(camera); dc1394_camera_free(camera); dc1394_free (d); return 0; }