资源简介

基于QT开发的V4L2摄像头视频采集,并使用QLable实现摄像头图像的刷新显示。

资源截图

代码片段和文件信息

#include “imagecamera.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define log_debug qDebug

void yuyv_to_rgb888(unsigned char* yuvunsigned char* rgb int imgWidth int imgHeight)
{
    unsigned int i;
    unsigned char* y0 = yuv + 0;
    unsigned char* u0 = yuv + 1;
    unsigned char* y1 = yuv + 2;
    unsigned char* v0 = yuv + 3;

    unsigned  char* r0 = rgb + 0;
    unsigned  char* g0 = rgb + 1;
    unsigned  char* b0 = rgb + 2;
    unsigned  char* r1 = rgb + 3;
    unsigned  char* g1 = rgb + 4;
    unsigned  char* b1 = rgb + 5;
    //DBG(“yuyv_to_rgb start\n“);
    float rt0 = 0 gt0 = 0 bt0 = 0 rt1 = 0 gt1 = 0 bt1 = 0;

    for(i = 0; i <= (imgWidth * imgHeight) / 2 ;i++)
    {
        bt0 = 1.164 * (*y0 - 16) + 2.018 * (*u0 - 128);
        gt0 = 1.164 * (*y0 - 16) - 0.813 * (*v0 - 128) - 0.394 * (*u0 - 128);
        rt0 = 1.164 * (*y0 - 16) + 1.596 * (*v0 - 128);

        bt1 = 1.164 * (*y1 - 16) + 2.018 * (*u0 - 128);
        gt1 = 1.164 * (*y1 - 16) - 0.813 * (*v0 - 128) - 0.394 * (*u0 - 128);
        rt1 = 1.164 * (*y1 - 16) + 1.596 * (*v0 - 128);

        if(rt0 > 250)   rt0 = 255;
        if(rt0 < 0)     rt0 = 0;

        if(gt0 > 250)  gt0 = 255;
        if(gt0 < 0) gt0 = 0;

        if(bt0 > 250) bt0 = 255;
        if(bt0 < 0) bt0 = 0;

        if(rt1 > 250) rt1 = 255;
        if(rt1 < 0) rt1 = 0;

        if(gt1 > 250) gt1 = 255;
        if(gt1 < 0) gt1 = 0;

        if(bt1 > 250) bt1 = 255;
        if(bt1 < 0) bt1 = 0;

        *r0 = (unsigned char)bt0;
        *g0 = (unsigned char)gt0;
        *b0 = (unsigned char)rt0;

        *r1 = (unsigned char)bt1;
        *g1 = (unsigned char)gt1;
        *b1 = (unsigned char)rt1;

        yuv = yuv + 4;
        rgb = rgb + 6;
        if(yuv == NULL)
          break;

        y0 = yuv;
        u0 = yuv + 1;
        y1 = yuv + 2;
        v0 = yuv + 3;

        r0 = rgb + 0;
        g0 = rgb + 1;
        b0 = rgb + 2;
        r1 = rgb + 3;
        g1 = rgb + 4;
        b1 = rgb + 5;
    }
}

ImageCamera::ImageCamera(QString c Qobject *parent) : QThread(parent)
{
    camera = c;
    err.clear();
    nWidth = 1280;
    nHeight = 960;
    nSize = nWidth * nHeight * 2;
    bKeep = false;
    memset(pix_format 0 sizeof(pix_format));

    cam_fd = -1;
    buffer_count = 1;   //5;       // count 指定根据图像占用空间大小申请的缓存区个数
    video_buffer_ptr = new u8*[buffer_count];
}

bool ImageCamera::initCamera()
{
    int index = 0;
    int ret = 0;

    if(camera.isEmpty())
    {
        err = QString(“设备节点位置为空“);
        return false;
    }

    if(cam_fd != -1)
    {
        close(cam_fd);
    }

    //  打开相机设备节点
    cam_fd = open(camera.toStdString().c_str() O_RDWR);
    if(cam_fd == -1)
    {
        err = QString(“打开相机节点失败“);
        retur

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      13136  2018-12-29 18:23  V4L2_Camera\imagecamera.cpp

     文件       1593  2018-12-29 13:20  V4L2_Camera\imagecamera.h

     文件        172  2018-12-29 19:42  V4L2_Camera\main.cpp

     文件       1181  2018-12-29 19:50  V4L2_Camera\mainwindow.cpp

     文件        399  2018-12-29 19:44  V4L2_Camera\mainwindow.h

     文件       1222  2018-12-29 19:48  V4L2_Camera\mainwindow.ui

     文件      49948  2018-12-29 19:48  V4L2_Camera\V4L2_Camera

     文件       1108  2018-12-29 19:48  V4L2_Camera\V4L2_Camera.pro

     目录          0  2018-12-29 19:53  V4L2_Camera

----------- ---------  ---------- -----  ----

                68759                    9


评论

共有 条评论