示例#1
0
// query camera for supported frame rates and select fastest for given format and mode
static unsigned int icvGetBestFrameRate( CvCaptureCAM_DC1394 * capture, int format, int mode  ){
	quadlet_t framerates;
	if (dc1394_query_supported_framerates(capture->handle, capture->camera->node, 
				format, mode, &framerates)!=DC1394_SUCCESS) 
	{
		fprintf(stderr,"%s:%d: Could not query supported framerates\n",__FILE__,__LINE__);
		framerates = 0;
	}

	for (int f=FRAMERATE_MAX; f>=FRAMERATE_MIN; f--) {
		if (framerates & (0x1<< (31-(f-FRAMERATE_MIN)))) {
			return f;
		}
	}
}
示例#2
0
bool linuxfwCamera::initCamera(int width, int height, bool colour) {
	
	if (cameraID < 0) return false;
	this->width = width;
	this->height = height;
	this->colour = colour;
	bytes = (colour?3:1);
	
	quadlet_t format;
	if (dc1394_query_supported_modes(handle, cameraID,FORMAT_VGA_NONCOMPRESSED,&format) !=DC1394_SUCCESS) {
		fprintf( stderr,"unable to query format\n");
	}
	
	image_mode_ = 0;
	if (colour) {	
		int yuv411 = 29;
		int rgb = 27;
		if	(format & (0x1<<yuv411)) image_mode_=MODE_640x480_YUV411;
		else if (format & (0x1<<rgb)) 	 image_mode_=MODE_640x480_RGB;
	} else {
		int mono = 26;
		int yuv411 = 29;
		if (format & (0x1<<mono))        image_mode_=MODE_640x480_MONO;
		else if	(format & (0x1<<yuv411)) image_mode_=MODE_640x480_YUV411;
	}
	if(!image_mode_) return false;
	quadlet_t frames;
	if (dc1394_query_supported_framerates(handle, cameraID,FORMAT_VGA_NONCOMPRESSED, image_mode_, &frames) !=DC1394_SUCCESS) {
		fprintf( stderr,"unable query frame rate\n");
	}
	
	fps = 60;
	while (fps>=15) {
		frame_rate_ = 0;
		int test_rate = 0;
		
		if (fps == 60)
		test_rate = FRAMERATE_60;
		else if (fps == 30)
		test_rate = FRAMERATE_30;
		else if (fps == 15)
		test_rate = FRAMERATE_15;    
		
		if ((frames & (0x1<<(31-(test_rate-FRAMERATE_MIN)))))
			frame_rate_=test_rate;
		
		if(!frame_rate_) {
			fps=fps/2;
		} else break;
	}
	if(!frame_rate_) return false;
	printf("framerate\n");  
	
	char videoDevice[24] = "";
	sprintf(videoDevice,"/dev/video1394/%d",dc1394_get_camera_port(handle));
	
	// setup capture
	if (dc1394_dma_setup_capture(handle,camera_nodes[cameraID],
				0, /* channel */ 
				FORMAT_VGA_NONCOMPRESSED,
				image_mode_,
				SPEED_400,
				frame_rate_,
				4,
				0,
				videoDevice,
				&camera)==DC1394_SUCCESS) {
		use_dma=true;
	} else if (dc1394_setup_capture(handle,camera_nodes[cameraID],
				0, /* channel */ 
				FORMAT_VGA_NONCOMPRESSED,
				image_mode_,
				SPEED_400,
				frame_rate_,
				&camera)==DC1394_SUCCESS) {
		use_dma=false;
	} else {
		fprintf( stderr,"unable to setup camera -\n"
			"make sure that the video mode,framerate and format are supported by your camera\n");
		dc1394_release_camera(handle,&camera);
		dc1394_destroy_handle(handle);
		dc1394_free_camera_nodes(camera_nodes);
		return false;
	}
	
	
	dc1394_camerainfo info;
	if (dc1394_get_camera_info(handle, cameraID, &info) !=DC1394_SUCCESS ) {
		//printf("could not read camera info\n");
		sprintf(cameraName,"unknown camera");
	} else {
		sprintf(cameraName,"%s, %s", info.vendor, info.model);
	}
	
	/*if (dc1394_set_video_framerate(handle,cameraID,frame_rate)!=DC1394_SUCCESS) {
		fprintf( stderr,"%i nope\n");
		dc1394_release_camera(handle,&camera);
		//dc1394_destroy_handle(handle);
		//sdc1394_free_camera_nodes(camera_nodes);
		return false;
	}*/
	
	dc1394_free_camera_nodes(camera_nodes);
	
	// set trigger mode
	/*if( dc1394_set_trigger_mode(handle, camera.node, TRIGGER_MODE_0)
	!= DC1394_SUCCESS)
	{
	//fprintf( stderr, "unable to set camera trigger mode\n");
	}*/
	
	buffer = new unsigned char[width*height*bytes];	
	return true;
}