当前位置: 技术问答>linux和unix
100分求解。用V4L图像采集到buffer后如何处理
来源: 互联网 发布时间:2016-05-12
本文导语: 我希望从摄像头中采集到图片存到buffer后,能对buffer进行扫描,判断图像中是否有红色的区域。摄像头的信息: [root@axis /root]106# dmesg Linux video capture interface: v1.00 usb.c: registered new driver spca5xx spca_core.c: USB SPCA5X...
我希望从摄像头中采集到图片存到buffer后,能对buffer进行扫描,判断图像中是否有红色的区域。摄像头的信息:
[root@axis /root]106# dmesg
Linux video capture interface: v1.00
usb.c: registered new driver spca5xx
spca_core.c: USB SPCA5XX camera found. Type Labtec Webcam Pro Zc0302 + Hdcs2020
spca_core.c: spca5xx driver 00.57.06LE registered
我已经写好怎么采集数据后存到buffer里,后面对buffer的扫描操作就一点思路都没有。我使用video4linux即V4L,来获取摄像头数据到buffer,现在得问题是不知道buffer里存的数据倒底是什么格式的。是直接的RGB图形数据呢还是包含文件头、位图信息头、颜色信息和图形数据等,100分希望有大哥能帮忙解决
typedef struct _v4ldevice
{int fd;//设备号
struct video_capability capability;
struct video_channel channel[10];
struct video_picture picture;
struct video_clip clip;
struct video_window window;
struct video_capture capture;
struct video_buffer buffer;
struct video_mmap mmap;
struct video_mbuf mbuf;
struct video_unit unit;
unsigned char *map;//mmap方式获取数据时,数据的首地址
pthread_mutex_t mutex;
int frame;
int framestat[2];
int overlay;
}v4ldevice;
//获取图像信息
int v4lgetcapability(v4ldevice *vd)
{
if(ioctl(vd->fd, VIDIOCGCAP, &(vd->capability)) fd, VIDIOCGMBUF, &(vd->mbuf))fd = open(name,O_RDWR)) mmap.width = width;
vd->mmap.height = height;
vd->mmap.format = vd->picture.palette;
vd->frame = 0;
vd->framestat[0] = 0;
vd->framestat[1] = 0;
return 0;
}
//内存映射
int v4lmmap(v4ldevice *vd)
{
if(v4lgetmbuf(vd)map = mmap(0, vd->mbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED, vd->fd, 0)) mmap.frame = frame;
if(ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)) framestat[frame] = 1;
return 0;
}
//等待传完一帧
int v4lsync(v4ldevice *vd, int frame)
{
if(ioctl(vd->fd, VIDIOCSYNC, &frame) framestat[frame] = 0;
return 0;
}
//获取下一帧
int c4lcapture(v4ldevice *vd, int frame)
{
vd->mmap.frame = frame;
if(ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)) framestat[frame] = 1;
return 0;
}
//数据的地址
unsigned char *v4lgetaddress(v4ldevice *vd)
{
return (vd->map + vd->mbuf.offsets[vd->frame]);
}
/***********************************************************/
int main ()
{
//char* devicename="/dev/video0";
char* buffer;
v4ldevice device;
int width = 640;
int height = 480;
int frame = 0;
v4lopen("/dev/video0",&device);//打开设备
v4lgrabinit(&device,width,height);//初始化设备,定义获取的影像的大小
v4lmmap(&device);//内存映射
v4lgrabstart(&device,frame);//开始获取影像
v4lsync(&device,frame);//等待传完一帧
buffer = (char*)v4lgetaddress(&device);//得到这一帧的地址
//这里就是要解决的地方,怎么对buffer操作,扫描出红色区域
return 0;
}
[root@axis /root]106# dmesg
Linux video capture interface: v1.00
usb.c: registered new driver spca5xx
spca_core.c: USB SPCA5XX camera found. Type Labtec Webcam Pro Zc0302 + Hdcs2020
spca_core.c: spca5xx driver 00.57.06LE registered
我已经写好怎么采集数据后存到buffer里,后面对buffer的扫描操作就一点思路都没有。我使用video4linux即V4L,来获取摄像头数据到buffer,现在得问题是不知道buffer里存的数据倒底是什么格式的。是直接的RGB图形数据呢还是包含文件头、位图信息头、颜色信息和图形数据等,100分希望有大哥能帮忙解决
typedef struct _v4ldevice
{int fd;//设备号
struct video_capability capability;
struct video_channel channel[10];
struct video_picture picture;
struct video_clip clip;
struct video_window window;
struct video_capture capture;
struct video_buffer buffer;
struct video_mmap mmap;
struct video_mbuf mbuf;
struct video_unit unit;
unsigned char *map;//mmap方式获取数据时,数据的首地址
pthread_mutex_t mutex;
int frame;
int framestat[2];
int overlay;
}v4ldevice;
//获取图像信息
int v4lgetcapability(v4ldevice *vd)
{
if(ioctl(vd->fd, VIDIOCGCAP, &(vd->capability)) fd, VIDIOCGMBUF, &(vd->mbuf))fd = open(name,O_RDWR)) mmap.width = width;
vd->mmap.height = height;
vd->mmap.format = vd->picture.palette;
vd->frame = 0;
vd->framestat[0] = 0;
vd->framestat[1] = 0;
return 0;
}
//内存映射
int v4lmmap(v4ldevice *vd)
{
if(v4lgetmbuf(vd)map = mmap(0, vd->mbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED, vd->fd, 0)) mmap.frame = frame;
if(ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)) framestat[frame] = 1;
return 0;
}
//等待传完一帧
int v4lsync(v4ldevice *vd, int frame)
{
if(ioctl(vd->fd, VIDIOCSYNC, &frame) framestat[frame] = 0;
return 0;
}
//获取下一帧
int c4lcapture(v4ldevice *vd, int frame)
{
vd->mmap.frame = frame;
if(ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)) framestat[frame] = 1;
return 0;
}
//数据的地址
unsigned char *v4lgetaddress(v4ldevice *vd)
{
return (vd->map + vd->mbuf.offsets[vd->frame]);
}
/***********************************************************/
int main ()
{
//char* devicename="/dev/video0";
char* buffer;
v4ldevice device;
int width = 640;
int height = 480;
int frame = 0;
v4lopen("/dev/video0",&device);//打开设备
v4lgrabinit(&device,width,height);//初始化设备,定义获取的影像的大小
v4lmmap(&device);//内存映射
v4lgrabstart(&device,frame);//开始获取影像
v4lsync(&device,frame);//等待传完一帧
buffer = (char*)v4lgetaddress(&device);//得到这一帧的地址
//这里就是要解决的地方,怎么对buffer操作,扫描出红色区域
return 0;
}
|
struct video_picture picture;
vd->mmap.format = vd->picture.palette;
这个格式是什么?
采集出来的格式有YUYV,BMP,JPEG等,要看你设定的格式是什么
VIDEO_PALETTE_GREY Linear intensity grey scale (255 is brightest).
VIDEO_PALETTE_HI240 The BT848 8bit colour cube.
VIDEO_PALETTE_RGB565 RGB565 packed into 16 bit words.
VIDEO_PALETTE_RGB555 RGV555 packed into 16 bit words, top bit undefined.
VIDEO_PALETTE_RGB24 RGB888 packed into 24bit words.
VIDEO_PALETTE_RGB32 RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.
VIDEO_PALETTE_YUV422 Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V
VIDEO_PALETTE_YUYV Describe me
VIDEO_PALETTE_UYVY Describe me
VIDEO_PALETTE_YUV420 YUV420 capture
VIDEO_PALETTE_YUV411 YUV411 capture
VIDEO_PALETTE_RAW RAW capture (BT848)
VIDEO_PALETTE_YUV422P YUV 4:2:2 Planar
VIDEO_PALETTE_YUV411P YUV 4:1:1 Planar
驱动程序并不是每个格式都支持的,你看看驱动支持什么格式
vd->mmap.format = vd->picture.palette;
这个格式是什么?
采集出来的格式有YUYV,BMP,JPEG等,要看你设定的格式是什么
VIDEO_PALETTE_GREY Linear intensity grey scale (255 is brightest).
VIDEO_PALETTE_HI240 The BT848 8bit colour cube.
VIDEO_PALETTE_RGB565 RGB565 packed into 16 bit words.
VIDEO_PALETTE_RGB555 RGV555 packed into 16 bit words, top bit undefined.
VIDEO_PALETTE_RGB24 RGB888 packed into 24bit words.
VIDEO_PALETTE_RGB32 RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.
VIDEO_PALETTE_YUV422 Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V
VIDEO_PALETTE_YUYV Describe me
VIDEO_PALETTE_UYVY Describe me
VIDEO_PALETTE_YUV420 YUV420 capture
VIDEO_PALETTE_YUV411 YUV411 capture
VIDEO_PALETTE_RAW RAW capture (BT848)
VIDEO_PALETTE_YUV422P YUV 4:2:2 Planar
VIDEO_PALETTE_YUV411P YUV 4:1:1 Planar
驱动程序并不是每个格式都支持的,你看看驱动支持什么格式
|
还要看你的摄像头,有的摄像头采用了硬件编码,直接给编码成某种格式了,不过,都能通过ioctl来判断出是什么格式的。
|
需要现将Jpeg格式解码成RGB格式,再进行图像处理,spca_core中好像有Jpeg解码库,楼主可以找一下。
|
Type Labtec Webcam Pro Zc0302 中星微的摄像头吧,一般是Jpeg格式的