Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3646593
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

2011-05-04 21:32:12

本文的copyright归yuweixian4230@163.com 所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。
作者:yuweixian4230@163.com
博客:
yuweixian4230.blog.chinaunix.net 


这里贴上 主程序:  v-3.0.rar  

  1. /***************************************/
  2. /*
  3. author: yuweixian
  4. blog: http://blog.chinaunix.net/space.php?uid=22666248
  5. date: 2011.5.4

  6. function: display usb-camera video on lcd by framebuffer
  7. compile : arm-linux-gcc capture.c -ljpeg -o capture
  8. how to use: ./capture

  9.       ok..enjoy it
  10.                                       */
  11. /**************************************/
  12. #include "v4l2.h"
  13. #include "frame_jpeg.h"

  14. int main(int argc,char **argv)
  15. {     
  16.         FRAME_DEV frame_dev; //framebufrer 结构体
  17.     JPEG_DEV jpeg_dev; // jpeg 解码 结构体

  18.     init_framebuffer(&frame_dev); //初始化 framebuffer 设备

  19.         open_v4l2_device (); //打开 v4l2 设备
  20.         init_v4l2_device (); //初始化 设备
  21.         start_capturing (); //开始捕获 视频图片
  22.     
  23.     for (;;)
  24.     {
  25.                 fd_set fds;
  26.                 struct timeval tv;
  27.                 int r;

  28.                 FD_ZERO (&fds);
  29.                 FD_SET (fd, &fds);

  30.                 /* Timeout. */
  31.                 tv.tv_sec = 2;
  32.                 tv.tv_usec = 0;

  33.                 r = select (fd + 1, &fds, NULL, NULL, &tv);

  34.                 if (-1 == r)
  35.         {
  36.                         if (EINTR == errno)
  37.                                 continue;
  38.             v4l2_errno_exit ("select");
  39.                 }

  40.                 if (0 == r)
  41.         {
  42.                         fprintf (stderr, "select timeout\n");
  43.                         exit (EXIT_FAILURE);
  44.                 }

  45.         
  46.         
  47.         while(1)
  48.         {
  49.             read_frame(); //读图片
  50.             if((jpeg_dev.infile=fopen("mmap.jpg","rb"))==NULL) //打开 解码图片
  51.             {
  52.             fprintf(stderr,"open %s failed \n",argv[1]);
  53.             exit(-1);
  54.             }

  55.             init_jpeg(&jpeg_dev); //图片 初始化

  56.             judge_large_picture(&frame_dev,&jpeg_dev); //if picture is too large ,return -1;
  57.                                                 
  58.         //申请 动态空间
  59.     jpeg_dev.buffer=(unsigned char *)malloc(jpeg_dev.cinfo.output_width*jpeg_dev.cinfo.output_components);


  60.             dispaly_picture(&frame_dev,&jpeg_dev); //显示图片到 lcd上

  61.             close_jpeg(&jpeg_dev); // 关闭 这张 图片 结构体
  62.     //close_framebuffer(&frame_dev);
  63.             
  64.         }
  65.             
  66.     }

  67.     close_framebuffer(&frame_dev);
  68.     
  69.     uninit_v4l2_device ();
  70.         close_v4l2_device ();
  71.         exit (EXIT_SUCCESS);

  72.         return 0;
  73. }


开发板上的操作

  1. [root@yuweixian yu]# ./capture
  2. the framebuffer device was opended successfully.
  3. init_dev successfully.
  4. zc3xx: probe 2wr ov vga 0x0000
  5. ^C
  6. [root@yuweixian yu]# ./capture &
  7. [root@yuweixian yu]# the framebuffer device was opended successfully.
  8. init_dev successfully.
  9. zc3xx: probe 2wr ov vga 0x0000

  10. [root@yuweixian yu]# gsnap t1.jpg /dev/fb0
  11. ---------------framebuffer---------------
  12. /dev/fb0:
  13.   width : 320
  14.   height: 240
  15.   bpp : 2
  16.   r(11, 5)
  17.   g( 5, 6)
  18.   b( 0, 5)
  19. -----------------------------------------
  20. [root@yuweixian yu]# gsnap t2.jpg /dev/fb0
  21. ---------------framebuffer---------------
  22. /dev/fb0:
  23.   width : 320
  24.   height: 240
  25.   bpp : 2
  26.   r(11, 5)
  27.   g( 5, 6)
  28.   b( 0, 5)
  29. -----------------------------------------
  30. [root@yuweixian yu]# ps


截图看看











阅读(1816) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

kangear2012-11-14 23:38:02

VIDIOC_S_FMT error 22, Invalid argument
用的是zc3xx摄像头,出这样的错误。。。

kangear2012-11-14 23:10:04

[root@localhost v-3.0]# gcc capture.c -o capture -ljpeg
这样就没有问题了。。。。

kangear2012-11-14 23:07:32

[root@localhost v4l2]# cd v-3.0/
[root@localhost v-3.0]# ls
capture.c  frame_jpeg.h  v4l2.h
[root@localhost v-3.0]# arm-linux-gcc capture.c -o capture
/tmp/cc8w50SR.o: In function `init_jpeg':
capture.c:(.text+0xa2c): undefined reference to `jpeg_std_error'
capture.c:(.text+0xa4c): undefined reference to `jpeg_CreateDecompress'
capture.c:(.text+0xa64): undefined reference to `jpeg_stdio_src'
capture.c:(.text+0xa74): unde

kangear2012-11-14 22:43:10

学习了,终于找到了。下载下来看看先。