//--------------------------------------------------------------- void Device1394::initCapture() { unsigned int channel; unsigned int speed; if (dc1394_get_iso_channel_and_speed(handle_, p_camera_->node, &channel, &speed) != DC1394_SUCCESS) throw Miro::Exception("Device1394:initDevice: unable to get iso channel number"); MIRO_DBG_OSTR(VIDEO, LL_DEBUG, "ISO channel: " << channel << " speed: " << speed); channel = 1; #if ( LIBDC1394_VERSION == 1 ) // old version if (dc1394_dma_setup_capture(handle_, p_camera_->node, channel, FORMAT_VGA_NONCOMPRESSED, imageFormat_, SPEED_400, frameRate_, NUM_BUFFERS, DROP_FRAMES, params_.device.c_str(), p_camera_) != DC1394_SUCCESS) #elif ( LIBDC1394_VERSION == 2 ) // new version if (dc1394_dma_setup_capture(handle_, p_camera_->node, channel, FORMAT_VGA_NONCOMPRESSED, imageFormat_, SPEED_400, frameRate_, NUM_BUFFERS, 1, DROP_FRAMES, params_.device.c_str(), p_camera_) != DC1394_SUCCESS) #endif throw Miro::Exception("Device1394::handleConnect: unable to setup camera"); if (dc1394_start_iso_transmission(handle_, p_camera_->node) != DC1394_SUCCESS) throw Miro::Exception("Device1394::handleConnect: unable to start camera iso transmission"); is_open_ = true; }
static int cam_setup( struct dc1394_input *conf, int cam, int port, nodeid_t node, int dma_chan ) { unsigned int channel; unsigned int speed; conf->cam[cam].running = 0; conf->camera[cam].node = node; conf->cam[cam].handle = dc1394_create_handle( port ); if( ! conf->cam[cam].handle ) { spook_log( SL_ERR, "dc1394: unable to create a camera handle" ); return -1; } if( dc1394_get_iso_channel_and_speed( conf->cam[cam].handle, node, &channel, &speed ) != DC1394_SUCCESS ) { spook_log( SL_ERR, "dc1394: unable to create an ISO channel" ); return -1; } if( dc1394_dma_setup_capture( conf->cam[cam].handle, node, dma_chan, FORMAT_VGA_NONCOMPRESSED, MODE_320x240_YUV422, SPEED_400, FRAMERATE_30, 8 /* num buffers */, #ifdef DC1394_EXTRA_BUFFERING_FLAG 0 /* do_extra_buffering */, #endif 1 /* drop frames */, NULL /* device name */, &conf->camera[cam] ) != DC1394_SUCCESS ) { spook_log( SL_ERR, "dc1394: unable to set up DMA for camera" ); return -1; } if( dc1394_start_iso_transmission( conf->cam[cam].handle, conf->camera[cam].node ) != DC1394_SUCCESS ) { spook_log( SL_ERR, "dc1394: unable to start ISO transfer from camera" ); return -1; } conf->cam[cam].outq = new_soft_queue( 16 ); add_softqueue_event( conf->cam[cam].outq, 0, get_back_frame, &conf->cam[cam] ); return 0; }
int CameraDcam::moduleOn(void) { unsigned int uvValue, uuValue; int ret; RackTask::disableRealtimeMode(); if (lossRate < 1) { GDOS_ERROR("Lossrate must not be less than 1!! EXITING! \n"); return -EINVAL; } ret = loadCameraParameter(¶m, intrParFile, lossRate, extrParFile); if(ret) { GDOS_ERROR("Couldn't load camera parameter!! code = %d\n", ret); return ret; } if ( getFirewirePortnum() != DC1394_SUCCESS) return FW_ERROR; if ( findCameraByGuid() != DC1394_SUCCESS) { GDOS_ERROR("Camera by given guid not found. \n"); return FW_ERROR; } GDOS_DBG_INFO("camera_dcam initalising dcam part\n"); /*----------------------------------------------------------------------- * setup capture format 2 + 7 *-----------------------------------------------------------------------*/ if ( dc1394_get_iso_channel_and_speed( porthandle[dc1394CameraPortNo], camera_node, &channel, &speed) !=DC1394_SUCCESS ) { GDOS_WARNING("Unable to get the iso channel number\n" ); return FW_ERROR; } switch(mode) { case CAMERA_MODE_YUV422: case CAMERA_MODE_MONO12: setupCaptureFormat2(); break; case CAMERA_MODE_MONO8: //format 2 is possible but no external trigger case CAMERA_MODE_RAW8: case CAMERA_MODE_RAW12: setupCaptureFormat7(); break; default: GDOS_ERROR("Set undefined ColorMode.\n" ); return -EINVAL; } //need to get max size of image from this camera and also set dataBuffer according if (CAMERA_MAX_WIDTH < (dc1394Camera.frame_width / lossRate) || CAMERA_MAX_HEIGHT < (dc1394Camera.frame_height / lossRate) ) { GDOS_ERROR("Size parameter set too small in camera.h!! EXITING! \n"); return -ENOMEM; } if (param.calibration_width != (int)(dc1394Camera.frame_width / lossRate) || param.calibration_height != (int)(dc1394Camera.frame_height / lossRate) ) { GDOS_ERROR("Size parameter of intrinsic parameter file (%i,%i) and camera (%i,%i) doesn't fit together!!\n", param.calibration_width, param.calibration_height, dc1394Camera.frame_width / lossRate, dc1394Camera.frame_height / lossRate); return -EAGAIN; } /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ if ( dc1394_start_iso_transmission( porthandle[dc1394CameraPortNo], dc1394Camera.node ) !=DC1394_SUCCESS ) { GDOS_WARNING("Unable to start camera iso transmission\n" ); return DC1394_FAILURE; } GDOS_DBG_INFO("Started iso transmission.\n" ); if (dc1394_get_white_balance(porthandle[dc1394CameraPortNo], camera_node, &uuValue, &uvValue) != DC1394_SUCCESS) { GDOS_WARNING("getting of white balance failed! "); return DC1394_FAILURE; } uvValue = vValue; uuValue = uValue; if (dc1394_set_white_balance(porthandle[dc1394CameraPortNo], camera_node, uuValue, uvValue) != DC1394_SUCCESS) { GDOS_WARNING("setting of white balance failed u:%i v:%i!\n", uuValue, uvValue); return DC1394_FAILURE; } GDOS_DBG_INFO("set u:%i v:%i \n", uuValue, uvValue); return RackDataModule::moduleOn(); // has to be last command in moduleOn(); }
int main(int argc, char *argv[]) { XGCValues xgcv; long background = 0x010203; unsigned int channel; unsigned int speed; int i, p, cn; raw1394handle_t raw_handle; struct raw1394_portinfo ports[MAX_PORTS]; get_options(argc, argv); /* process options */ switch (fps) { case 1: fps = FRAMERATE_1_875; break; case 3: fps = FRAMERATE_3_75; break; case 15: fps = FRAMERATE_15; break; case 30: fps = FRAMERATE_30; break; case 60: fps = FRAMERATE_60; break; default: fps = FRAMERATE_7_5; break; } switch (res) { case 1: res = MODE_640x480_YUV411; device_width = 640; device_height = 480; format = XV_YUY2; break; case 2: res = MODE_640x480_RGB; device_width = 640; device_height = 480; format = XV_YUY2; break; default: res = MODE_320x240_YUV422; device_width = 320; device_height = 240; format = XV_UYVY; break; } /* get the number of ports (cards) */ raw_handle = raw1394_new_handle(); if (raw_handle == NULL) { perror("Unable to aquire a raw1394 handle\n"); perror("did you load the drivers?\n"); exit(-1); } numPorts = raw1394_get_port_info(raw_handle, ports, numPorts); raw1394_destroy_handle(raw_handle); if (verbose) printf("number of ports = %d\n", numPorts); /* get dc1394 handle to each port */ for (p = 0; p < numPorts; p++) { int camCount; handles[p] = dc1394_create_handle(p); if (handles[p] == NULL) { perror("Unable to aquire a raw1394 handle\n"); perror("did you load the drivers?\n"); cleanup(); exit(-1); } /* get the camera nodes and describe them as we find them */ camera_nodes = dc1394_get_camera_nodes(handles[p], &camCount, verbose); /* setup cameras for capture */ for (i = 0; i < camCount; i++) { cameras[numCameras].node = camera_nodes[i]; if (dc1394_get_camera_feature_set (handles[p], cameras[numCameras].node, &features) != DC1394_SUCCESS) { printf("unable to get feature set\n"); } else if (verbose) { dc1394_print_feature_set(&features); } if (dc1394_get_iso_channel_and_speed (handles[p], cameras[numCameras].node, &channel, &speed) != DC1394_SUCCESS) { printf("unable to get the iso channel number\n"); cleanup(); exit(-1); } if (dc1394_dma_setup_capture (handles[p], cameras[numCameras].node, i + 1 /*channel */ , FORMAT_VGA_NONCOMPRESSED, res, SPEED_400, fps, NUM_BUFFERS, DROP_FRAMES, device_name, &cameras[numCameras]) != DC1394_SUCCESS) { fprintf(stderr, "unable to setup camera - check line %d of %s to make sure\n", __LINE__, __FILE__); perror("that the video mode, framerate and format are supported\n"); printf("by your camera(s)\n"); cleanup(); exit(-1); } /*have the camera start sending us data */ if (dc1394_start_iso_transmission (handles[p], cameras[numCameras].node) != DC1394_SUCCESS) { perror("unable to start camera iso transmission\n"); cleanup(); exit(-1); } numCameras++; } } fflush(stdout); if (numCameras < 1) { perror("no cameras found :(\n"); cleanup(); exit(-1); } //set_manual_exposure_gain(0, 440, 30); 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: fprintf(stderr, "Unknown format set (internal error)\n"); exit(255); } /* create OpenCV image wrappers */ for (cn = 0; cn < MAX_CAMERAS; cn++) { if (cn < numCameras) { iplImages[cn] = cvCreateImage(cvSize(device_width, device_height), IPL_DEPTH_8U, 3); readOnlyImg = cvCreateImageHeader(cvSize(device_width, device_height), IPL_DEPTH_8U, 3); } else { iplImages[cn] = NULL; } } /* initialize handvu */ hvInitialize(device_width, device_height); hvLoadConductor(string(conductor_fname)); hvStartRecognition(); hvSetOverlayLevel(3); if (async_processing) { hvAsyncSetup(num_async_bufs, displayCallback); hvAsyncGetImageBuffer(&m_async_image, &m_async_bufID); if (sync_display) async_display_image = cvCloneImage(iplImages[0]); } /* make the window */ display = XOpenDisplay(getenv("DISPLAY")); if (display == NULL) { fprintf(stderr, "Could not open display \"%s\"\n", getenv("DISPLAY")); cleanup(); exit(-1); } QueryXv(); if (adaptor < 0) { cleanup(); exit(-1); } width = device_width; height = device_height * numCameras; 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); /* local main event loop */ while (1) { if (async_processing) { // asynchronous processing in HandVu capture_frame(); process_frame(); if (sync_display) display_frame(); handle_events(); } else { // synchronous processing in HandVu capture_frame(); process_frame(); display_frame(); handle_events(); } /* XPending */ } /* while not interrupted */ exit(0); }