Exemplo n.º 1
0
/*********************************************************************//*!
 * @brief Initialize framework and system parameters
 *
 * @param s Pointer to the system state 
 *//*********************************************************************/
void initSystem(struct SYSTEM *s)
{
	OscCreate(&s->hFramework);
	
	/******* Load the framework module dependencies. **********/
	OscLoadDependencies(s->hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));

	OscLogSetConsoleLogLevel(WARN);
	OscLogSetFileLogLevel(WARN);
	
	#if defined(OSC_HOST)
		/* Setup file name reader (for host compiled version); read constant image */
		OscFrdCreate(s->hFramework);
		OscFrdCreateConstantReader(&s->hFileNameReader, "EAN13Example.bmp");
		OscCamSetFileNameReader(s->hFileNameReader);
	#endif
	
	/* Configure camera */
	OscCamPresetRegs();
	/* Set AGC and AEC */
	OscCamSetRegisterValue(REG_AEC_AGC_ENABLE, 0x3);
        /* Turn on continuous capture for this application. */
        OscCamSetRegisterValue(CAM_REG_CHIP_CONTROL, 0x388);
        /* Set the undocumented reserved almighty Micron register to the
           "optimal" value. */
        OscCamSetRegisterValue(CAM_REG_RESERVED_0x20, 0x3d5);

	OscCamSetAreaOfInterest(0, 0, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
	OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_180DEG_ROTATE);

	OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT, s->frameBuffer1, TRUE); 
	OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT, s->frameBuffer2, TRUE); 

	s->doubleBufferIDs[0] = 0;
	s->doubleBufferIDs[1] = 1;
	OscCamCreateMultiBuffer(2, s->doubleBufferIDs); 

	OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); 

} /* initSystem */
Exemplo n.º 2
0
bool Camera::init(uint16 lowX, uint16 lowY, uint16 width, uint16 height, Debayer* debayer, uint8 bufferSize)
{
	this->initialized = false;
	
	// setting sane default values
	this->presetRegisters();
	this->setPerspective(ROTATE_180DEG);
	
	if(((lowX + width) <= Image::MAX_WIDTH) &&
		(lowY + height) <= Image::MAX_HEIGHT)
	{
		this->aoi.width = width;
		this->aoi.height = height;
		this->aoi.posX = lowX;
		this->aoi.posY = lowY;
	
		this->lastError = OscCamSetAreaOfInterest(lowX, lowY, width, height);
		
		if(this->lastError != SUCCESS)
		{
			return false;
		}
	}
	else
	{
		this->lastError = EINVALID_PARAMETER;
		return false;
	}
	
	//set debayer strategy
	this->debayer = debayer;
	
	// set type
	this->type = debayer->getType();
	
	if(bufferSize > 0)
	{
		// creating buffers
		if(!this->createBuffers(bufferSize))
		{
			return false;
		}
	}
	else
	{
		this->lastError = EINVALID_PARAMETER;
		
		return false;
	}
	
	// do not track fps by default
	this->trackFPS = false;
	
	// create an image
	this->image = debayer->getObject(width, height);
	this->rawImage = new RawImage(this->aoi.width, this->aoi.height);
		
	int mb = this->isMultiBuffered ? OSC_CAM_MULTI_BUFFER : 0;
	
	if(OscCamSetupCapture(mb) == SUCCESS)
	{
		usleep(10000);
		if(OscGpioTriggerImage() == SUCCESS)
		{
			usleep(10000);
			// finished initializing
			this->initialized = true;
		}
	}
	
	return true;
}
Exemplo n.º 3
0
Arquivo: cam.c Projeto: scs/tutorial
/*********************************************************************//*!
 * @brief Program entry.
 * 
 * @param argc Command line argument count.
 * @param argv Command line argument string.
 * @return 0 on success
 *//*********************************************************************/
int main(const int argc, const char * argv[])
{
	/* Handle to framework instance. */
	void *hFramework;
	
#if defined(OSC_HOST) || defined(OSC_SIM)
	/* Handle to file name reader, if compiled for host platform. */
	void *hFileNameReader;
#endif
	
	/* Camera parameters */
	uint32 shutterWidth;
	uint16 x, y, width, height;
	uint16 blackOffset;
	uint8 bufferIDs[2];
	
	/* Frame buffers. */
	uint8 frameBuffer0[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
	uint8 frameBuffer1[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
	
	/* Pointer to captured picture */
	void *pic;
	
	struct OSC_PICTURE p;
	
	OSC_ERR err = SUCCESS;
	
	/* Create framework */
	OscCreate(&hFramework);
	
	/* Load camera module */
	OscCamCreate(hFramework);

	/* Load GPIO module */
	OscGpioCreate(hFramework);

	p.width = OSC_CAM_MAX_IMAGE_WIDTH;
	p.height = OSC_CAM_MAX_IMAGE_HEIGHT;
	p.type = OSC_PICTURE_GREYSCALE;
	
	/* Get camera settings */
	OscCamGetShutterWidth(&shutterWidth);
	OscCamGetAreaOfInterest(&x, &y, &width, &height);
	OscCamGetBlackLevelOffset(&blackOffset);
	printf("ShutterWidth=%lu\n",shutterWidth);
	printf("AreaOfInterest: x=%u y=%u width=%u height=%u\n", x, y, width, height);
	printf("BlackLevelOffset=%u\n",blackOffset);
	
	/* Process settings */
	/* ---------------- */
	
	/* Set new camera settings */
	shutterWidth = 50000; /* set shutter to 50ms, 0 => automatic */
	OscCamSetShutterWidth(shutterWidth);
	OscCamSetAreaOfInterest(0,0,OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
	OscCamSetBlackLevelOffset(blackOffset);
	OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR);
	
#if defined(OSC_HOST) || defined(OSC_SIM)
	/* Setup file name reader if compiled for host platform */
	OscFrdCreateConstantReader(&hFileNameReader, "imgCapture.bmp");
	OscCamSetFileNameReader(hFileNameReader);
#endif
	
	/* Setup framebuffers - double buffering */
	OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer0, TRUE);
	OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer1, TRUE);
	bufferIDs[0] = 0;
	bufferIDs[1] = 1;
	OscCamCreateMultiBuffer(2, bufferIDs);
	
	/* Setup capture to first frame buffer */
	err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER);
	if(err != SUCCESS){
		printf("%s: Unable to setup initial capture (%d)!\n", __func__, err);
		return err;
	}

	/* Trigger image capturing */
	err = OscGpioTriggerImage();
	if(err != SUCCESS){
		printf("%s: Unable to trigger capture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Do something ... */
	/* ---------------- */
	
	/* Read Picture */
	err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0);
	if(err != SUCCESS){
		printf("%s: Unable to read picture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Process picture */
	/* --------------- */
	
	/* Capture picture to second frame buffer */
	err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER);
	if(err != SUCCESS){
		printf("%s: Unable to setup initial capture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Do something ... */
	/* ---------------- */
	
	err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0);
	if(err != SUCCESS){
		printf("%s: Unable to read picture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Process picture */
	/* --------------- */
	
	/* Unload camera module */
	OscCamDestroy(hFramework);

	/* Unload GPIO module */
	OscGpioDestroy(hFramework);
	
	/* Destroy framework */
	OscDestroy(hFramework);
	
	return 0;
}