Пример #1
0
NaoCamera::NaoCamera(const char* device, CameraInfo::Camera camera, int width, int height, bool flip,
                     const CameraSettings::CameraSettingsCollection& settings, const Matrix5uc& autoExposureWeightTable) :
  camera(camera),
  WIDTH(width),
  HEIGHT(height)
{
  VERIFY((fd = open(device, O_RDWR | O_NONBLOCK)) != -1);

  mapBuffers();
  queueBuffers();

  setImageFormat();
  setFrameRate(1, 30);

  checkSettingsAvailability();

  specialSettings.horizontalFlip.value = flip ? 1 : 0;
  setControlSetting(specialSettings.horizontalFlip);
  specialSettings.verticalFlip.value = flip ? 1 : 0;
  setControlSetting(specialSettings.verticalFlip);
  setSettings(settings, autoExposureWeightTable);
  writeCameraSettings();
  readCameraSettings();

  startCapturing();
}
Пример #2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void WriteImages::readFilterParameters(AbstractFilterParametersReader* reader, int index)
{
  reader->openFilterGroup(this, index);
  setImagePrefix( reader->readString("ImagePrefix", getImagePrefix()) );
  setFilePrefix( reader->readValue("FilePrefix", getFilePrefix()) );
  setOutputPath( reader->readString("OutputPath", getOutputPath()) );
  setColorsArrayPath( reader->readDataArrayPath("ColorsArrayPath", getColorsArrayPath()) );
  setImageFormat( reader->readValue("ImageFormat", getImageFormat()) );
  setPlane(reader->readValue("Plane", getPlane()));
  reader->closeFilterGroup();
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void WritePoleFigure::readFilterParameters(AbstractFilterParametersReader* reader, int index)
{
  reader->openFilterGroup(this, index);
  setGoodVoxelsArrayPath(reader->readDataArrayPath("GoodVoxelsArrayPath", getGoodVoxelsArrayPath() ) );
  setCrystalStructuresArrayPath(reader->readDataArrayPath("CrystalStructuresArrayPath", getCrystalStructuresArrayPath() ) );
  setCellPhasesArrayPath(reader->readDataArrayPath("CellPhasesArrayPath", getCellPhasesArrayPath() ) );
  setCellEulerAnglesArrayPath(reader->readDataArrayPath("CellEulerAnglesArrayPath", getCellEulerAnglesArrayPath() ) );
  setImagePrefix( reader->readString("ImagePrefix", getImagePrefix()));
  setOutputPath( reader->readString("OutputPath", getOutputPath()));
  setImageFormat( reader->readValue("ImageFormat", getImageFormat()));
  setImageLayout( reader->readValue("ImageLayout", getImageLayout()));
  setImageSize( reader->readValue("ImageSize", getImageSize()));
  setLambertSize( reader->readValue("LambertSize", getLambertSize()));
  reader->closeFilterGroup();
}
Пример #4
0
int main()
{
	const int WIDTH = 1280, HEIGHT = 960;

	if (!openCamera(0))
	{
		std::cout << "openCamera failed!" << std::endl;
		return true;
	}

	if (!initCamera())
	{
		std::cout << "initCamera failed!" << std::endl;
		return true;
	}

	bool autov;
	setImageFormat(WIDTH, HEIGHT, 1, IMG_RAW8);
	setValue(CONTROL_EXPOSURE, 400, true);
	setValue(CONTROL_GAIN, 35, false);

	//int exposure_us = getValue(CONTROL_EXPOSURE, &autov);
	//int gain = getValue(CONTROL_GAIN, &autov);
	//int max_gain = getMax(CONTROL_GAIN);
	//std::cout << exposure_us << ", " << gain << ", " << max_gain << std::endl;

	IplImage *buffer = cvCreateImage(cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1);
	startCapture();

	bool captured = false;
	do
	{
		std::chrono::milliseconds(10);
		captured = getImageData((unsigned char*)buffer->imageData, buffer->imageSize, -1);
	} while (!captured);

	cvSaveImage("sun_cam_2.jpg", buffer);
	stopCapture();
	closeCamera();

	return false;
}
  //---------------------------------------------------------------
  void
  Device1394::init(Miro::Server& _server, FilterParameters const * _params)
  {
    MIRO_DBG(VIDEO, LL_DEBUG, "Device1394::init()");

    if (_params)
        params_ = *(dynamic_cast<Device1394Parameters const *>(_params));

    initDevice();
    initSettings();
	
    setImageFormat();
    initCapture();

    control_ = new ControlImpl(this);
    Video::Control_var control = control_->_this();
    _server.addToNameService(control.in(), "VideoControl");

    Super::init(_server, _params);
  }
Пример #6
0
int  main()
{
	int width;
	char* bayer[] = {"RG","BG","GR","GB"};
	char* controls[MAX_CONTROL] = {"Exposure", "Gain", "Gamma", "WB_R", "WB_B", "Brightness", "USB Traffic"};

	int height;
	int i;
	char c;
	bool bresult;

	int time1,time2;
	int count=0;

	char buf[128]={0};

	int CamNum=0;
	
	///long exposure, exp_min, exp_max, exp_step, exp_flag, exp_default;
	//long gain, gain_min, gain_max,gain_step, gain_flag, gain_default;

	IplImage *pRgb;


	int numDevices = getNumberOfConnectedCameras();
	if(numDevices <= 0)
	{
		printf("no camera connected, press any key to exit\n");
		getchar();
		return -1;
	}
	else
		printf("attached cameras:\n");

	for(i = 0; i < numDevices; i++)
		printf("%d %s\n",i, getCameraModel(i));

	printf("\nselect one to privew\n");
	scanf("%d", &CamNum);


	bresult = openCamera(CamNum);
	if(!bresult)
	{
		printf("OpenCamera error,are you root?,press any key to exit\n");
		getchar();
		return -1;
	}

	printf("%s information\n",getCameraModel(CamNum));
	int iMaxWidth, iMaxHeight;
	iMaxWidth = getMaxWidth();
	iMaxHeight =  getMaxHeight();
	printf("resolution:%dX%d\n", iMaxWidth, iMaxHeight);
	if(isColorCam())
		printf("Color Camera: bayer pattern:%s\n",bayer[getColorBayer()]);
	else
		printf("Mono camera\n");
	
	for( i = 0; i < MAX_CONTROL; i++)
	{
			if(isAvailable((Control_TYPE)i))
				printf("%s support:Yes\n", controls[i]);
			else
				printf("%s support:No\n", controls[i]);
	}

	printf("\nPlease input the <width height bin image_type> with one space, ie. 640 480 2 0. use max resolution if input is 0. Press ESC when video window is focused to quit capture\n");
	int bin = 1, Image_type;
	scanf("%d %d %d %d", &width, &height, &bin, &Image_type);
	if(width == 0 || height == 0)
	{
		width = iMaxWidth;
		height = iMaxHeight;
	}

	initCamera(); //this must be called before camera operation. and it only need init once
	printf("sensor temperature:%02f\n", getSensorTemp());

//	IMG_TYPE image_type;
	
	while(!setImageFormat(width, height, bin, (IMG_TYPE)Image_type))//IMG_RAW8
	{
		printf("Set format error, please check the width and height\n ASI120's data size(width*height) must be integer multiple of 1024\n");
		printf("Please input the width and height again£¬ie. 640 480\n");
		scanf("%d %d %d %d", &width, &height, &bin, &Image_type);
	}
	printf("\nset image format %d %d %d %d success, start privew, press ESC to stop \n", width, height, bin, Image_type);

	
	if(Image_type == IMG_RAW16)
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1);
	else if(Image_type == IMG_RGB24)
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3);
	else
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1);

	setValue(CONTROL_EXPOSURE, 100*1000, false); //ms//auto
	setValue(CONTROL_GAIN,getMin(CONTROL_GAIN), false); 
	setValue(CONTROL_BANDWIDTHOVERLOAD, getMin(CONTROL_BANDWIDTHOVERLOAD), false); //low transfer speed

	setValue(CONTROL_WB_B, 90, false);
 	setValue(CONTROL_WB_R, 48, false);
  	setAutoPara(getMax(CONTROL_GAIN)/2,10,150); //max auto gain and exposure and target brightness
//	EnableDarkSubtract("dark.bmp"); //dark subtract will be disabled when exposure set auto and exposure below 500ms
	startCapture(); //start privew


	

	bDisplay = 1;
#ifdef _LIN
	pthread_t thread_display;
	pthread_create(&thread_display, NULL, Display, (void*)pRgb);
#elif defined _WINDOWS
	HANDLE thread_setgainexp;
	thread_setgainexp = (HANDLE)_beginthread(Display,  NULL, (void*)pRgb);
#endif

	time1 = GetTickCount();
	int iStrLen = 0, iTextX = 40, iTextY = 60;
	void* retval;
//	int time0, iWaitMs = -1;
//	bool bGetImg;
	while(bMain)
	{

//		time0 = GetTickCount();
		getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, 200);

//		bGetImg = getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, iWaitMs);
		time2 = GetTickCount();
//		printf("waitMs%d, deltaMs%d, %d\n", iWaitMs, time2 - time0, bGetImg);
		count++;
		
		if(time2-time1 > 1000 )
		{
			sprintf(buf, "fps:%d dropped frames:%lu ImageType:%d",count, getDroppedFrames(), (int)getImgType());

			count = 0;
			time1=GetTickCount();	
			printf(buf);
			printf("\n");

		}
		if(Image_type != IMG_RGB24 && Image_type != IMG_RAW16)
		{
			iStrLen = strlen(buf);
			CvRect rect = cvRect(iTextX, iTextY - 15, iStrLen* 11, 20);
			cvSetImageROI(pRgb , rect);
			cvSet(pRgb, CV_RGB(180, 180, 180)); 
			cvResetImageROI(pRgb);
		}
		cvText(pRgb, buf, iTextX,iTextY );

		if(bChangeFormat)
		{
			bChangeFormat = 0;
			bDisplay = false;
			pthread_join(thread_display, &retval);
			cvReleaseImage(&pRgb);
			stopCapture();
			
			switch(change)
			{
				 case change_imagetype:
					Image_type++;
					if(Image_type > 3)
						Image_type = 0;
					
					break;
				case change_bin:
					if(bin == 1)
					{
						bin = 2;
						width/=2;
						height/=2;
					}
					else 
					{
						bin = 1;
						width*=2;
						height*=2;
					}
					break;
				case change_size_smaller:
					if(width > 320 && height > 240)
					{
						width/= 2;
						height/= 2;
					}
					break;
				
				case change_size_bigger:
				
					if(width*2*bin <= iMaxWidth && height*2*bin <= iMaxHeight)
					{
						width*= 2;
						height*= 2;
					}
					break;
			}
			setImageFormat(width, height, bin, (IMG_TYPE)Image_type);
			if(Image_type == IMG_RAW16)
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1);
			else if(Image_type == IMG_RGB24)
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3);
			else
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1);
			bDisplay = 1;
			pthread_create(&thread_display, NULL, Display, (void*)pRgb);
			startCapture(); //start privew
		}
	}
END:
	
	if(bDisplay)
	{
		bDisplay = 0;
#ifdef _LIN
   		pthread_join(thread_display, &retval);
#elif defined _WINDOWS
		Sleep(50);
#endif
	}
	
	stopCapture();
	closeCamera();
	cvReleaseImage(&pRgb);
	printf("main function over\n");
	return 1;
}
Пример #7
0
//
// Reads the image
//
void PNGReader::read(ImageFile * image)
{
	volatile unsigned char ** volatile rowPointers = NULL;
	png_struct * pngPtr = NULL;
	png_info * infoPtr = NULL;
	byte * data = NULL;

	try
	{
		int colorType, bitDepth;
		bool hasAlpha = false;
		uint bytesPerElement;
		ImageFormat format;
		unsigned long w, h;
		unsigned rowbytes;

		// Initialize the PNG library
		pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngErrorFunc, pngWarningFunc);
		if (unlikely(!pngPtr))
			throw Exception(QString("%1: png_create_read_struct() failed").arg(m_File.fileName()));

		// Initialize the PNG info struct
		infoPtr = png_create_info_struct(pngPtr);
		if (unlikely(!infoPtr))
			throw Exception(QString("%1: png_create_info_struct() failed").arg(m_File.fileName()));

		// Setup error handler
		if (unlikely(setjmp(png_jmpbuf(pngPtr)) != 0))
			throw Exception(QString("%1: PNG decompression failed").arg(m_File.fileName()));

		// Setup file reading
		png_set_read_fn(pngPtr, &m_File, pngReadFunc);
		png_set_sig_bytes(pngPtr, 8);
		png_read_info(pngPtr, infoPtr);
		png_get_IHDR(pngPtr, infoPtr, &w, &h, &bitDepth, &colorType, NULL, NULL, NULL);

		// Setup 16 bit -> 8 bit conversion
		if (bitDepth > 8) 
			png_set_strip_16(pngPtr);

		// Translate transparency to alpha channel
  		if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS))
		{
			png_set_tRNS_to_alpha(pngPtr);
			hasAlpha = true;
		}

		// Setup gamma correction
		double gamma;
		if (png_get_gAMA(pngPtr, infoPtr, &gamma))
			png_set_gamma(pngPtr, 2.2, gamma);
		else
			png_set_gamma(pngPtr, 2.2, 0.45455);

		// We want at least 8-bit
		if (bitDepth < 8)
		{
			if ((colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA))
				png_set_gray_1_2_4_to_8(pngPtr);
			else
				png_set_packing(pngPtr);
		}

		// Convert paletted images to RGB
		if (colorType == PNG_COLOR_TYPE_PALETTE)
		{
			png_set_palette_to_rgb(pngPtr);
			colorType = hasAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB;
		}

		// Convert gray/alpha images to RGB
		if (colorType == PNG_COLOR_TYPE_GRAY_ALPHA ||
			(colorType == PNG_COLOR_TYPE_GRAY && hasAlpha))
		{
			png_set_gray_to_rgb(pngPtr);
			colorType = PNG_COLOR_TYPE_RGB_ALPHA;
		}

		// Add dummy alpha channel for RGB images
		if (colorType == PNG_COLOR_TYPE_RGB && !hasAlpha)
		{
			png_set_filler(pngPtr, 0xFF, PNG_FILLER_BEFORE);
			hasAlpha = true;
		}
		else if (colorType == PNG_COLOR_TYPE_RGB_ALPHA)
			hasAlpha = true;

		// Select pixel format
		switch (colorType)
		{
		case PNG_COLOR_TYPE_PALETTE:
		case PNG_COLOR_TYPE_GRAY_ALPHA:
			Q_ASSERT(false);	// Should be handled in the code above
			break;

		case PNG_COLOR_TYPE_GRAY:
			bytesPerElement = 1;
			format = R8_UNORM;
			break;

		default:
			Q_ASSERT(hasAlpha);	// Should be handled in the code above
			bytesPerElement = 4;
			format = RGBA8_UNORM;
			break;
		}

		// Re-configure PNG reading to include configured conversions
		png_read_update_info(pngPtr, infoPtr);
		rowbytes = png_get_rowbytes(pngPtr, infoPtr);

		// Set basic image info
		setImageSize(image, w, h);
		setImageDepth(image, 0);
		setImageMipLevels(image, 1);
		setImageFaces(image, 0);
		setImageFormat(image, format);
		setImageElementSize(image, bytesPerElement);

		// Allocate memory for image data
		data = new byte[w * h * bytesPerElement];
		if (unlikely(!data))
			throw Exception("Out of memory.");

		// Allocate array of row pointers
		rowPointers = new volatile unsigned char * [h];
		for (unsigned j = 0; j < h; j++)
			rowPointers[j] = data + j * rowbytes;

		// Read the image
		png_read_image(pngPtr, (png_byte **)rowPointers);

		// Store image information
		appendImageLevelData(image, data);
		data = NULL;

		// Free memory
		png_destroy_read_struct(&pngPtr, &infoPtr, NULL);
		pngPtr = NULL;
	}
	catch (...)
	{
		delete[] rowPointers;
		delete[] data;

		if (pngPtr)
		{
			if (infoPtr)
				png_destroy_read_struct(&pngPtr, &infoPtr, NULL);
			else
				png_destroy_read_struct(&pngPtr, NULL, NULL);
		}	

		throw;
	}

	delete[] rowPointers;
}