In front of the use of USB camera to collect BMP pictures and YUV video, the display process is directly to the BMP picture in the LCD display on it. The general USB camera operation as in front of the same, not clear camera operation can go
http://blog.csdn.net/zhangdaxia2/article/details/72763847. Framebuffer operation is not difficult, as follows:
The Framebuffer device node is/DEV/FBX. Generally for/dev/fb0, a liquid crystal control node. Operation Steps:
1, open framebuffer.
int FD =-1;
FD = open ("/dev/fb0", O_RDWR);
2, IOCTL get LCD parameters.
static struct Fb_fix_screeninfo fixinfo;
static struct Fb_var_screeninfo varinfo;
RET = IOCTL (FB_FD, Fbioget_vscreeninfo, &varinfo);
RET = IOCTL (FB_FD, Fbioget_fscreeninfo, &fixinfo);
3, the MMAP memory address mapping, the kernel address mapping to user space, the user directly to the mapped address to write data, you can display the data on the LCD.
Fbmmap = (int*) mmap (NULL, Fixinfo.smem_len, Prot_read | Prot_write, map_shared,
fb_fd, 0);
if (NULL = = fbmmap) {
printf ("Mmap memeory error.\n");
Exit (0);
}
4, to map the address to write data, draw framebuffer.
void Fb_drawbmp (UINT height,uint width,unsigned char* pdata)
{uint x,y,cnt
;
UINT a = height*width*3;
UINT CNT1 = 0;
uint* p = fbmmap;
for (x=0 x
5, in the USB camera Operation Readfram (), will Fb_drawbmp () into the inside, the camera collected data into RGB, directly written to framebuffer, you can complete the LCD display camera image.
static int Readfram () {struct POLLFD pollfd;
int ret,i;
Char filename[50];
for (i =0 i<10; i++) {memset (&POLLFD, 0, sizeof (POLLFD));
POLLFD.FD = FD;
Pollfd.events = Pollin;
RET = Poll (&POLLFD, 1, 800);
if ( -1 = ret) {perror ("Vidioc_qbuf fail.\n");
return-1;
}else if (0 = ret) {printf ("poll Time out\n");
Continue
} if (Pollfd.revents & Pollin) {memset (&buf, 0, sizeof (BUF));
Buf.type = v4l2_buf_type_video_capture;
Buf.memory = V4l2_memory_mmap;
RET = IOCTL (FD, VIDIOC_DQBUF, &buf);
if (0!= ret) {perror ("Vidioc_qbuf fail.\n");
return-1;
}//v4l2_buffer//Direct-saved YUYV data//file *file = fopen (Yuyv_file, "WB");
ret = fwrite ((char*) Framebuf[buf.index].start, 1, buf.length, file);
fclose (file); RGB Format Data starter = (UnsigneD char*) Framebuf[buf.index].start;
Newbuf = (unsigned char*) calloc (unsigned int) (FRAMEBUF[BUF.INDEX].LENGTH*3/2), sizeof (unsigned char));
Yuv422_2_rgb ();
Write RGB data to framebuffer, display fb_drawbmp on LCD (height, width, newbuf);
RET = IOCTL (FD, VIDIOC_QBUF, &buf);
} return ret; }
Because Ubuntu and Android constantly refresh the screen, experimenting on these systems is not necessarily a thought. On the Linux Development Board you can always run the
, displaying the camera image. The complete code for the
including USB camera operations can be downloaded from the following URL:
https://github.com/zhangdalei/video_lcd_show