-
运行Linux的一个摄像头采集的程序,为什么我摄像头采集的图像只有灰度信息,而且分辨率什么的还有问题,大神们帮忙看一下~我刚学V4l2……10
谁来帮我看下 为什么我采集到的图像还是这样啊。。。
只有灰度信息?
是程序问题还是我的参数问题啊]
还有我发现 我在程序里面设定的分辨率是640*480的,当以640*480显示的时候是上面那张图用1280*720的时候是下面这张图
很明显横着的是连续的,竖着的图像没有了 求解啊~程序如下,就是书上的一个示例代码/* * V4L2 video capture example * * This program can be used and distributed without restrictions. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <getopt.h> /* getopt_long() */ #include <fcntl.h> /* low-level i/o */ #include <unistd.h> /*getpid()*/ #include <error.h> #include <errno.h> #include <malloc.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/time.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <asm/types.h> /* for videodev2.h */ #include <linux/videodev2.h> #define CLEAR(x) memset(&(x), 0, sizeof (x)) typedef enum { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR, } io_method; struct buffer { void *start; size_t length; }; static char * dev_name = NULL; static io_method io = IO_METHOD_MMAP; static int fd = -1; struct buffer * buffers = NULL; static unsigned int n_buffers = 0; static void errno_exit(const char *s) { fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno)); exit(EXIT_FAILURE); } static int xioctl(int fd,int request,void *arg) { int r; do r = ioctl(fd, request, arg); while (-1 == r && EINTR == errno); return r; } static void process_image(const void *p) { FILE* fp; fp = fopen("test","w+"); fputs(p, fp); fclose(fp); // fflush(stdout); } static int read_frame(void) { struct v4l2_buffer buf; unsigned int i; switch (io) { case IO_METHOD_READ: if (-1 == read(fd, buffers[0].start, buffers[0].length)) { switch (errno) { case EAGAIN: return 0; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ default: errno_exit("read"); } } process_image(buffers[0].start); break; case IO_METHOD_MMAP: CLEAR (buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) { switch (errno) { case EAGAIN: return 0; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ default: errno_exit("VIDIOC_DQBUF"); } } assert(buf.index < n_buffers); process_image(buffers[buf.index].start); if (-1 == xioctl(fd, VIDIOC_QBUF, &buf)) errno_exit("VIDIOC_QBUF"); break; case IO_METHOD_USERPTR: CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_USERPTR; if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) { switch (errno) { case EAGAIN: return 0; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ default: errno_exit("VIDIOC_DQBUF"); } } for (i = 0; i < n_buffers; ++i) if (buf.m.userptr == (unsigned long) buffers[i].start && buf.length == buffers[i].length) break; assert(i < n_buffers); process_image((void *) buf.m.userptr); if (-1 == xioctl(fd, VIDIOC_QBUF, &buf)) errno_exit("VIDIOC_QBUF"); break; } return 1; } static void mainloop(void) { unsigned int count; count = 100; while (count-- > 0) { for (;;) { fd_set fds; struct timeval tv; int r; FD_ZERO(&fds); FD_SET(fd, &fds); /* Timeout. */ tv.tv_sec = 2; tv.tv_usec = 0; r = select (fd + 1, &fds, NULL, NULL, &tv); if (-1 == r) { if (EINTR == errno) continue; errno_exit("select"); } if (0 == r) { fprintf(stderr, "select timeout\n"); exit(EXIT_FAILURE); } if (read_frame()) break; /* EAGAIN - continue select loop. */ } } } static void stop_capturing(void) { enum v4l2_buf_type type; switch (io) { case IO_METHOD_READ: /* Nothing to do. */ break; case IO_METHOD_MMAP: case IO_METHOD_USERPTR: type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &type)) errno_exit("VIDIOC_STREAMOFF"); break; } } static void start_capturing(void) { unsigned int i; enum v4l2_buf_type type; switch (io) { case IO_METHOD_READ: /* Nothing to do. */ break; case IO_METHOD_MMAP: for (i = 0; i < n_buffers; ++i) { struct v4l2_buffer buf; CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (-1 == xioctl(fd, VIDIOC_QBUF, &buf)) errno_exit("VIDIOC_QBUF"); } type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl(fd, VIDIOC_STREAMON, &type)) errno_exit("VIDIOC_STREAMON"); break; case IO_METHOD_USERPTR: for (i = 0; i < n_buffers; ++i) { struct v4l2_buffer buf; CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_USERPTR; buf.index = i; buf.m.userptr = (unsigned long) buffers[i].start; buf.length = buffers[i].length; if (-1 == xioctl(fd, VIDIOC_QBUF, &buf)) errno_exit("VIDIOC_QBUF"); } type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl(fd, VIDIOC_STREAMON, &type)) errno_exit("VIDIOC_STREAMON"); break; } } static void uninit_device(void) { unsigned int i; switch (io) { case IO_METHOD_READ: free(buffers[0].start); break; case IO_METHOD_MMAP: for (i = 0; i < n_buffers; ++i) if (-1 == munmap(buffers[i].start, buffers[i].length)) errno_exit("munmap"); break; case IO_METHOD_USERPTR: for (i = 0; i < n_buffers; ++i) free(buffers[i].start); break; } free(buffers); } static void init_read(unsigned int buffer_size) { buffers = calloc(1, sizeof (*buffers)); if (!buffers) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } buffers[0].length = buffer_size; buffers[0].start = malloc(buffer_size); if (!buffers[0].start) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } } static void init_mmap(void) { struct v4l2_requestbuffers req; CLEAR(req); req.count = 4; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) { if (EINVAL == errno) { fprintf(stderr, "%s does not support " "memory mapping\n", dev_name); exit(EXIT_FAILURE); } else { errno_exit("VIDIOC_REQBUFS"); } } if (req.count < 2) { fprintf(stderr, "Insufficient buffer memory on %s\n", dev_name); exit(EXIT_FAILURE); } buffers = calloc(req.count, sizeof (*buffers)); if (!buffers) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } for (n_buffers = 0; n_buffers < req.count; ++n_buffers) { struct v4l2_buffer buf; CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = n_buffers; if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf)) errno_exit("VIDIOC_QUERYBUF"); buffers[n_buffers].length = buf.length; buffers[n_buffers].start = mmap(NULL /* start anywhere */, buf.length, PROT_READ | PROT_WRITE /* required */, MAP_SHARED /* recommended */, fd, buf.m.offset); if (MAP_FAILED == buffers[n_buffers].start) errno_exit("mmap"); } } static void init_userp(unsigned int buffer_size) { struct v4l2_requestbuffers req; unsigned int page_size; page_size = getpagesize(); buffer_size = (buffer_size + page_size - 1) & ~(page_size - 1); CLEAR(req); req.count = 4; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_USERPTR; if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) { if (EINVAL == errno) { fprintf(stderr, "%s does not support " "user pointer i/o\n", dev_name); exit(EXIT_FAILURE); } else { errno_exit("VIDIOC_REQBUFS"); } } buffers = calloc(4, sizeof(*buffers)); if (!buffers) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } for (n_buffers = 0; n_buffers < 4; ++n_buffers) { buffers[n_buffers].length = buffer_size; buffers[n_buffers].start = memalign (/* boundary */ page_size, buffer_size); if (!buffers[n_buffers].start) { fprintf(stderr, "Out of memory\n"); exit(EXIT_FAILURE); } } } static void init_device(void) { struct v4l2_capability cap; struct v4l2_cropcap cropcap; struct v4l2_crop crop; struct v4l2_format fmt; unsigned int min; if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) { if (EINVAL == errno) { fprintf(stderr, "%s is no V4L2 device\n", dev_name); exit(EXIT_FAILURE); } else { errno_exit("VIDIOC_QUERYCAP"); } } if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { fprintf(stderr, "%s is no video capture device\n", dev_name); exit(EXIT_FAILURE); } switch (io) { case IO_METHOD_READ: if (!(cap.capabilities & V4L2_CAP_READWRITE)) { fprintf(stderr, "%s does not support read i/o\n", dev_name); exit(EXIT_FAILURE); } break; case IO_METHOD_MMAP: case IO_METHOD_USERPTR: if (!(cap.capabilities & V4L2_CAP_STREAMING)) { fprintf(stderr, "%s does not support streaming i/o\n", dev_name); exit(EXIT_FAILURE); } break; } /* Select video input, video standard and tune here. */ CLEAR(cropcap); cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) { crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; crop.c = cropcap.defrect; /* reset to default */ if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) { switch (errno) { case EINVAL: /* Cropping not supported. */ break; default: /* Errors ignored. */ break; } } } else { /* Errors ignored. */ } CLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = 640; fmt.fmt.pix.height = 480; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt)) errno_exit("VIDIOC_S_FMT"); /* Note VIDIOC_S_FMT may change width and height. */ /* Buggy driver paranoia. */ min = fmt.fmt.pix.width * 2; if (fmt.fmt.pix.bytesperline < min) fmt.fmt.pix.bytesperline = min; min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height; if (fmt.fmt.pix.sizeimage < min) fmt.fmt.pix.sizeimage = min; switch (io) { case IO_METHOD_READ: init_read(fmt.fmt.pix.sizeimage); break; case IO_METHOD_MMAP: init_mmap(); break; case IO_METHOD_USERPTR: init_userp(fmt.fmt.pix.sizeimage); break; } } static void close_device(void) { if (-1 == close(fd)) errno_exit("close"); fd = -1; } static void open_device(void) { struct stat st; if (-1 == stat(dev_name, &st)) { fprintf(stderr, "Cannot identify '%s': %d, %s\n", dev_name, errno, strerror (errno)); exit(EXIT_FAILURE); } if (!S_ISCHR(st.st_mode)) { fprintf(stderr, "%s is no device\n", dev_name); exit(EXIT_FAILURE); } fd = open(dev_name, O_RDWR /* | O_NONBLOCK*/, 0); if (-1 == fd) { fprintf(stderr, "Cannot open '%s': %d, %s\n", dev_name, errno, strerror (errno)); exit(EXIT_FAILURE); } } static void usage(FILE *fp,int argc,char **argv) { fprintf(fp, "Usage: %s [options]\n\n" "Options:\n" "-d | --device name Video device name [/dev/video]\n" "-h | --help Print this message\n" "-m | --mmap Use memory mapped buffers\n" "-r | --read Use read() calls\n" "-u | --userp Use application allocated buffers\n" "", argv[0]); } static const char short_options [] = "d:hmru"; static const struct option long_options [] = { { "device", required_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "mmap", no_argument, NULL, 'm' }, { "read", no_argument, NULL, 'r' }, { "userp", no_argument, NULL, 'u' }, { 0, 0, 0, 0 } }; int main(int argc,char **argv) { dev_name = "/dev/video0"; for (;;) { int index; int c; c = getopt_long(argc, argv, short_options, long_options, &index); if (-1 == c) break; switch (c) { case 0: /* getopt_long() flag */ break; case 'd': dev_name = optarg; break; case 'h': usage(stdout, argc, argv); exit(EXIT_SUCCESS); case 'm': io = IO_METHOD_MMAP; break; case 'r': io = IO_METHOD_READ; break; case 'u': io = IO_METHOD_USERPTR; break; default: usage(stderr, argc, argv); exit(EXIT_FAILURE); } } open_device(); init_device(); start_capturing(); mainloop(); stop_capturing(); uninit_device(); close_device(); exit(EXIT_SUCCESS); return 0; }
2012年10月28日 00:05
目前还没有答案
相关推荐
在这个特定的“LabVIEW双目采集程序”中,它被用来实现一项关键功能:从两个摄像头(左眼和右眼)捕获图像,然后将它们合成一个立体图像。这个过程涉及到多个图像处理步骤,包括图像灰度化、灰度均值化和中值滤波,...
通过本章节的介绍,我们不仅学习了摄像头图像采集及处理的理论知识,还了解了实际工程应用中软件编程与硬件设计是如何相结合,共同完成一个复杂的图像采集及处理系统。这一系统不仅为智能车的导航定位提供了技术支撑...
总的来说,"labVIEW摄像头采集程序"是一个实用的工具有,通过LabVIEW的VISION工具包,用户可以高效地搭建起一个摄像头图像采集系统,进行定制化的图像处理和存储,满足各种实际需求。理解并掌握这个过程,对于提升在...
灰度显示是将彩色图像转化为单色,每个像素只有一个亮度值,简化了显示处理。 6. **Verilog HDL驱动**: 在这里,"驱动"指的是用Verilog HDL编写的控制逻辑,它负责协调FPGA内部资源与外部设备(OV5640和HDMI接口...
总的来说,这个源码包提供了一个嵌入式Linux下基于QT的Camera视频采集的完整实例,涵盖了从摄像头初始化、视频流显示到图像捕获等一系列关键功能。对于想要学习QT在嵌入式系统中进行摄像头应用开发的工程师来说,这...
综上所述,"摄像头图像采集及处理vc程序"是一个综合性的项目,涵盖了硬件访问、图像处理、用户界面设计、文件操作等多个方面的技术,对于理解和实践C++及计算机视觉技术具有很高的价值。在实际开发过程中,开发者...
3. **摄像头设备的访问**:通过API函数`capCreateCaptureWindowA`,可以在VB程序中创建一个与摄像头关联的窗口,然后利用`capSetCaptureProperty`等函数来调整摄像头参数,如亮度、对比度等。 4. **图像采集**:...
在“labview USB摄像头采集”这个主题中,我们主要探讨如何利用LabVIEW来实现USB摄像头的数据采集、图像处理功能,包括灰度化和二值化。 首先,我们需要理解USB摄像头的工作原理。USB摄像头通过USB接口与计算机通信...
总的来说,“摄像头视频采集监控系统DELPHI程序”是一个综合性的应用,涵盖了硬件交互、图像处理、视频编码、网络传输等多个领域的技术。通过熟练运用DELPHI,开发者可以构建出高效、稳定的监控解决方案,满足各种...
LabVIEW2010开发,打开摄像头,灰度变化,灰度反色,可连续采集,可兼容高版本
标题中的“摄像头采集测试C#程序”指的是一个使用C#编程语言开发的软件应用,它的主要功能是捕获和处理来自摄像头的视频流。在计算机视觉、监控系统、在线会议软件以及许多其他领域,摄像头采集功能是至关重要的。C#...
V4L2是Linux的一个接口,它允许用户空间程序与视频设备(如USB摄像头)进行交互,实现视频捕获、编码、解码等功能。在Linux 2.6.32.2这个内核版本中,已经包含了对USB摄像头的支持,因此我们可以直接利用V4L2 API来...
在智能车领域,模拟摄像头作为主要的视觉传感器之一,其图像采集技术对于实现自主导航与环境感知有着至关重要的作用。本文将详细介绍如何对模拟摄像头进行图像采集,特别是针对PAL制式摄像头的具体实现方法。对于...
需要注意的是,由于单片机速度的限制,通常会采用旋转90度的方式来平衡图像采集的分辨率和时间延迟问题。 #### 三、PAL信号格式 了解PAL信号格式对于图像采集至关重要。PAL制式模拟信号主要包括以下几个部分: 1....
这个程序负责处理CCD摄像头捕获的原始数据,将其转化为可处理的图像信息,并通过单片机进行进一步的计算和决策。单片机是智能车的核心处理器,它接收来自CCD的图像信息,执行算法来分析路况,然后控制车辆的行驶方向...
通过学习和实践这个“LabVIEW采集摄像头视频数据”的项目,开发者可以掌握LabVIEW与摄像头交互的基本技能,并为进一步的图像处理和分析项目打下坚实的基础。项目的源代码和配置文件(如LabVIEW VI)将帮助初学者快速...
总之,"摄像头采集C_S架构"是利用OpenCV进行图像采集和处理,通过网络套接字实现实时图像传输,构建了一个高效、可靠的远程视频监控系统。这样的系统在安防、交通、零售等领域有广泛的应用价值。
在本文中,我们将深入探讨如何在STM32微控制器平台上配置OV7620摄像头模块,以及如何采集和处理摄像头的灰度信号。STM32是意法半导体(STMicroelectronics)推出的一系列高性能、低功耗的32位微控制器,而OV7620是一...
在这个基于LabVIEW的项目中,我们关注的是“通过USB摄像头采集图像子VI”,这是一个专门用于从连接到计算机的USB摄像头获取图像的虚拟仪器。 在LabVIEW中,VI(Virtual Instrument)代表一个完整的程序或功能模块,...