示例#1
0
文件: cam_host.c 项目: ajtag/oscar
/*********************************************************************//*!
 * @brief Host only: Crop a picture to the specified window.
 * 
 * The contents of the supplied OSC_PICTURE structure are cropped and
 * written to pDstBuffer. pPic is not changed.
 * 
 * Host only.
 * 
 * @param pDstBuffer The destination buffer where the cropped image
 * is written to.
 * @param dstBufferSize Size of above destination buffer.
 * @param pPic Picture to be cropped.
 * @param pCropWin Window to crop the picture to.
 * @return SUCCESS or an appropriate error code otherwise
 *//*********************************************************************/
static OSC_ERR OscCamCropPicture(uint8* pDstBuffer,
		const uint32 dstBufferSize,
		const struct OSC_PICTURE *pPic,
		const struct capture_window *pCropWin)
{
	uint8       *pTSrc, *pTDst;
	uint32      croppedSize;
	uint16      colorDepth, bytesPerPixel;
	uint32      y;
	uint32      lowY, highY;
	
	/* Input validation */
	if((pPic == NULL) || (pPic->data == NULL) || (pCropWin == NULL) ||
			(pDstBuffer == NULL) || (dstBufferSize == 0))
	{
		OscLog(ERROR, "%s(0x%x, %u, 0x%x, 0x%x): Invalid parameter!\n",
				__func__, pDstBuffer, dstBufferSize, pPic, pCropWin);
		return -EINVALID_PARAMETER;
	}
	if((pPic->width < (pCropWin->col_off + pCropWin->width)) ||
			pPic->height < (pCropWin->row_off + pCropWin->height))
	{
		OscLog(ERROR,
				"%s: Unable to crop image (%dx%d) to (%dx%d @ %d/%d).\n",
				__func__, pPic->width, pPic->height,
				pCropWin->width, pCropWin->height,
				pCropWin->col_off, pCropWin->row_off);
		return -EPICTURE_TOO_SMALL;
	}
	
	/* Allocate a temporary buffer for the cropped image */
	colorDepth = OSC_PICTURE_TYPE_COLOR_DEPTH(pPic->type);
	bytesPerPixel = colorDepth / 8;
	croppedSize = pCropWin->width *  pCropWin->height * bytesPerPixel;
	
	if(croppedSize > dstBufferSize)
	{
		OscLog(ERROR, "%s: Specified destination Buffer too small. \
				(%d < %d)\n", __func__, dstBufferSize, croppedSize);
		return -EBUFFER_TOO_SMALL;
	}
示例#2
0
/*********************************************************************//*!
 * @brief  The main program
 * 
 * Opens the camera and reads pictures as fast as possible
 * Makes a debayering of the image
 * Writes the debayered image to a buffer which can be read by
 * TCP clients on Port 8111. Several concurrent clients are allowed.
 * The simplest streaming video client looks like this:
 * 
 * nc 192.168.1.10 8111 | mplayer - -demuxer rawvideo -rawvideo w=376:h=240:format=bgr24:fps=100
 * 
 * Writes every 10th picture to a .jpg file in the Web Server Directory
 *//*********************************************************************/
int main(const int argc, const char * argv[])
{
	struct OSC_PICTURE calcPic;
	struct OSC_PICTURE rawPic;
	unsigned char *tmpbuf;
	int loops=0;	
	int numalarm=0;
	char filename[100];
	
	initSystem(&sys);

	ip_start_server();

	/* setup variables */
	rawPic.width = OSC_CAM_MAX_IMAGE_WIDTH;
	rawPic.height = OSC_CAM_MAX_IMAGE_HEIGHT;
	rawPic.type = OSC_PICTURE_GREYSCALE;

	/* calcPic width, height etc. are set in the debayering algos */
	calcPic.data = malloc(3 * OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT);
	if (calcPic.data == 0)
		fatalerror("Did not get memory\n");
	tmpbuf = malloc(500000);
	if (tmpbuf == 0)
		fatalerror("Did not get memory\n");

	
	#if defined(OSC_TARGET)
		/* Take a picture, first time slower ;-) */
		usleep(10000); OscGpioTriggerImage(); usleep(10000);
		OscLog(DEBUG,"Triggered CAM ");
	#endif

	while(true) {

		OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &rawPic.data, 0, 0);
		/* Take a picture */
		usleep(2000);
		OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); 

		#if defined(OSC_TARGET)
			OscGpioTriggerImage();
		#else
			usleep(10000);
		#endif

		if (is_alarm(&rawPic)) {
			OscGpioSetTestLed(TRUE);
			printf("alarm\n");
			sprintf(filename, "/home/httpd/alarm_pic%02i.jpg", numalarm%16);
			writeJPG(&calcPic, tmpbuf, filename);
			numalarm++;
		} else {
			OscGpioSetTestLed(FALSE);
		}

		fastdebayerBGR(rawPic, &calcPic, NULL);

		ip_send_all((char *)calcPic.data, calcPic.width*calcPic.height*
                        OSC_PICTURE_TYPE_COLOR_DEPTH(calcPic.type)/8);

		loops+=1;
		if (loops%20 == 0) {
			writeJPG(&calcPic, tmpbuf, "/home/httpd/liveimage.jpg");
		}


                ip_do_work();
	
	}

	ip_stop_server();

	cleanupSystem(&sys);

	return 0;
} /* main */
示例#3
0
int Camera::getDebayeredImageSize()
{
	return this->image->getWidth() * this->image->getHeight() * (OSC_PICTURE_TYPE_COLOR_DEPTH(this->debayer->getType())/8);	
}