资源简介
这时基于mini2440的USB视频采集程序,包括采集与显示程序,显示直接操作frambuffer,显示在lcd上
代码片段和文件信息
#include
#include
#include
#include
#include /* low-level i/o */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “v4l2.h“
#include “yuv422_rgb.h“
#include
//#define DEBUG_PTIME
#define DEBUG_GTIME
#define IMAGE_WIDTH 176
#define IMAGE_HEIGHT 144
#define WINDOW_W 176
#define WINDOW_H 144
#define WINDOW_X 40
#define WINDOW_Y 60
static void *fbbuf;
struct fb_var_screeninfo fbvar;
struct fb_fix_screeninfo finfo;
int fb_init(char *devname)
{
unsigned int bpp;
unsigned int screen_size;
int fd;
fd = open(devname O_RDWR);
if (ioctl(fd FBIOGET_VSCREENINFO &fbvar) < 0)
return -1;
bpp = fbvar.bits_per_pixel;
screen_size = fbvar.xres * fbvar.yres * bpp / 8;
fbbuf = mmap(0 screen_size PROT_READ | PROT_WRITE MAP_SHARED fd 0);
return fd;
}
static inline int make_pixel(unsigned int a unsigned int r unsigned int g unsigned int b)
{
return (unsigned int)(((r >> 3) << 11) | ((g >> 2) << 5 | (b >> 3)));
}
static void draw_image(unsigned short *pbuf unsigned char *buf)
{
unsigned int xy;
unsigned int pixel_num;
if (WINDOW_W <= 240) {
for (y = WINDOW_Y; y < WINDOW_Y + WINDOW_H; y++) {
for (x = WINDOW_X; x < WINDOW_X + WINDOW_W; x++) {
pixel_num = ((y - WINDOW_Y) * IMAGE_WIDTH + x - WINDOW_X) * 3;
pbuf[y * 240 + x] = make_pixel(0 (unsigned int)buf[pixel_num]
(unsigned int)buf[pixel_num + 1] (unsigned int)buf[pixel_num + 2]);
}
}
} else { /* reverse */
for (x = 0; x < WINDOW_W; x++) {
for (y = 0; y < WINDOW_H; y++) {
pixel_num = (y * IMAGE_WIDTH + x) * 3;
pbuf[x * 240 + y] = make_pixel(0 (unsigned int)buf[pixel_num]
(unsigned int)buf[pixel_num + 1] (unsigned int)buf[pixel_num + 2]);
}
}
}
}
void process_image (unsigned char *p struct camera *cam)
{
struct timeval tpstarttpend;
float timeuse;
#ifdef DEBUG_PTIME
gettimeofday(&tpstartNULL);
#endif
yuv422_rgb24(p cam->rgbbuf cam->width cam->height);
#ifdef DEBUG_PTIME
gettimeofday(&tpendNULL);
timeuse = 1000000 * (tpend.tv_sec - tpstart.tv_sec) + (tpend.tv_usec - tpstart.tv_usec);
timeuse /= 1000000;
printf(“Used Time:%10f s\n“timeuse);
#endif
}
int main(int argc const char* argv[])
{
int fp = 0;
unsigned int i;
/*
* init struct camera
*/
struct camera *cam;
struct timeval tpstarttpend;
float timeuse;
unsigned short *pbuf;
cam = malloc(sizeof(struct camera));
if (!cam) {
printf(“malloc camera failure!\n“);
exit(1);
}
cam->device_name = “/dev/video0“;
cam->buffers = NULL;
cam->width = IMAGE_WIDTH;
cam->height = IMAGE_HEIGHT;
cam->display_depth = 3; /* RGB24 */
cam->rgbbuf = malloc(cam->width * cam->height * cam->display_depth);
if (!cam->rgbbuf) {
printf(“malloc rgbbuf failure!\n“);
exit(1);
}
open_camera(cam);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2011-12-15 09:48 videolinux\
文件 3971 2011-12-15 09:48 videolinux\main.c
文件 1094 2011-12-13 07:37 videolinux\v4l2.h
文件 4372 2011-12-06 12:18 videolinux\main.c.backup
文件 25648 2011-12-15 09:48 videolinux\camera_test
文件 11986 2011-12-13 07:38 videolinux\v4l2.c
文件 2492 2011-11-21 08:45 videolinux\yuv422_rgb.c
文件 10672 2011-12-15 07:25 videolinux\v4l2.o
文件 431 2011-12-09 08:40 videolinux\Makefile
文件 110 2011-12-06 08:07 videolinux\yuv422_rgb.h
文件 2008 2011-12-15 07:25 videolinux\yuv422_rgb.o
文件 3580 2011-12-15 09:48 videolinux\main.o
- 上一篇:UC/OSII MINI2440移植
- 下一篇:几款常见的板载天线封装2.4G
评论
共有 条评论