移植opencv到开发板,摄像头在开发板6410上的采集使用(2)

在虚拟机搭建好系统后,真正的使用才刚刚开始。

在使用摄像头的时候,首先看自己的摄像头插上去是显示jpeg的还是yuv的

yuv的要实现UVC转QImage转IplImage这样的流程才能使用,jpeg的好多人不会用说没用其实最好用了。一点不卡。yuv的有点卡。

 

我用的也是yuv以前朋友用的jpeg的摄像头。

代码是用的网上的一个代码修改的

1. [文件] videodevice.h ?


#ifndef VIDEODEVICE_H
#define VIDEODEVICE_H #include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
  #include <sys/ioctl.h>
#include <sys/mman.h> #include <asm/types.h>
#include <linux/videodev2.h> #include <QString>
#include <QObject> #define CLEAR(x) memset(&(x), 0, sizeof(x)) class VideoDevice : public QObject
{
     Q_OBJECT public :
     VideoDevice(QString dev_name);
     //VideoDevice();    int open_device();
     int close_device();
     int init_device();
     int start_capturing();
     int stop_capturing();
     int uninit_device();
     int get_frame( void **, size_t *);
     int unget_frame();
  private :
     int init_mmap();
  
     struct buffer
     {
         void * start;
         size_t length;
     };
     QString dev_name;
     int fd;
     buffer* buffers;
     unsigned int n_buffers;
     int index;
  
signals:
     void display_error(QString);
  
};
  #endif // VIDEODEVICE_H

2. [文件] videodevice.cpp 

 
#include "videodevice.h"
VideoDevice::VideoDevice(QString dev_name)
{
     this ->dev_name = dev_name;
     this ->fd = -1;
     this ->buffers = NULL;
     this ->n_buffers = 0;
     this ->index = -1;
  
}
  int VideoDevice::open_device()
{
     fd = open(dev_name.toStdString().c_str(), O_RDWR /*|O_NONBLOCK*/ , 0);
    // fd = open(dev_name.toStdString().c_str(), O_RDWR|O_NONBLOCK, 0);
     if (-1 == fd)
     {
         emit display_error(tr( "open: %1" ).arg(QString( strerror ( errno ))));
         return -1;
     }
     return 0;
}
  int VideoDevice::close_device()
{
     if (-1 == close(fd))
     {
         emit display_error(tr( "close: %1" ).arg(QString( strerror ( errno ))));
         return -1;
     }
     return 0;
}
  int VideoDevice::init_device()
{
     v4l2_capability cap;
     v4l2_cropcap cropcap;
     v4l2_crop crop;
     v4l2_format fmt;
  
     if (-1 == ioctl(fd, VIDIOC_QUERYCAP, &cap))
     {
         if (EINVAL == errno )
         {
             emit display_error(tr( "%1 is no V4l2 device" ).arg(dev_name));
         }
         else
         {
             emit display_error(tr( "VIDIOC_QUERYCAP: %1" ).arg(QString( strerror ( errno ))));
         }
         return -1;
     }
  
     if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
     {
         emit display_error(tr( "%1 is no video capture device" ).arg(dev_name));
         return -1;
     }
  
     if (!(cap.capabilities & V4L2_CAP_STREAMING))
     {
         emit display_error(tr( "%1 does not support streaming i/o" ).arg(dev_name));
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
QCopteMV 是一个机械视觉开发板,用来实现影像处理的装置,QCopterMV 搭配 MT9V034 ( 灰阶 / 彩色 ) 的摄像头模块,用以实现光流、特征辨识等算法,同时透过板子拉出来的 FMC 接口,可以外接 TFT 荧幕模块,实现照相机功能。 摄像头视觉开发板QCopteMV实物截图: 硬件资源: 控制器 : STM32F429ZG 144Pin 180MHz DSP FPU 传感器 : MT9V034,使用 DCMI 操作 储存纪录 : micro SD(SDIO)、SDRAM IS42S16400J 外接界面 : 1xUSB ( Micro )、1xSPI ( FFC16 )、1xFSMC、7xPWM PCB 尺寸 : 38.1 x 38.1 mm 设计软件 Altium Designer 16 ( PcbLib use AD PcbLib v2.7 ) 说明: 这次新设计的 QCopterMV 另外制作了两个扩充板和两个摄像头板子,第一个扩充板是为结合 TFT 荧幕开发而设计的,将读取到的影像经过扩充板输出到荧幕上,不需要再跳线连接,并可以直接看到结果 另一个扩充板则是结合面包板来作实验,把扩充埠的 I/O 都拉出来,可以直接插在面包板上,并将开发板摄像头立起来,觉得实际安装的效果很不错,如果值之后实现将影像传到计算机上的部份的话,整体的开发应该会变得方便许多 再来是摄像头的部份,这部份设计了两种版本,第一种版本是直接透过 1.27 mm 的排针来连接自己设计的摄像头模块,目前只有 MT9V034 的版本,并且还在测试中,另一个版本则是为了兼容市面上的摄像头模块的 2.54 mm 连接脚位而设计的,可以让开发者自行选择摄像头来做连接与开发 整体来说对新版本 QCopterMV 的实体还蛮满意的,功能都还算齐全,体积也不大,加上扩充板也让开发变的更便利,目前会优先完善将影像传至计算机的部份以及影像结合 IMU 传感器的部份! 附件资料截图:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值