精华内容
下载资源
问答
  • QT 海康威视
    千次阅读
    2021-04-04 15:46:13

    *qt环境:qt 5.12(这里需要强调的是如果是在windows系统下必须使用32的编译器,因为qtcreater在windows下只有32位的所以版本要匹配)

    qt调用海康威视相机使用官方文档内程序即可调用,若出现问题去卡看编译器是否是32 位的 以及下载的海康SDK是不是32位的。

    整个调用流程如下,按照官方文档照抄即可;

    下面程序中的capture0();与capture1();分别是从设备与视频流读取图片的方式;

    void camera::log(QString a,QString b);这一块是传入的 相机IP与密码

    
    
    // An highlighted block
    #include "camera.h"
    
    camera::camera()
    {
      lUserID=-1;
      lRealPlayHandle=-1;
    }
    
    camera::~camera()
    {
    
    }
    
    void camera::init()
    {
        NET_DVR_Init();
    }
    
    void camera::StopPreview(){
        NET_DVR_StopRealPlay(lRealPlayHandle);
        if(lRealPlayHandle < 0)
        {
            if(NET_DVR_StopRealPlay(lRealPlayHandle))
            {
                qDebug("NET_DVR_RealPlay_V40 successfully!");
                lRealPlayHandle = -1;
            }
            else
            {
                qDebug("NET_DVR_RealPlay_V40 failed!");
            }
        }
    }
    
    void camera::logout0()
    {
     NET_DVR_Logout(lUserID);
        if(lUserID!=-1)
        {
             if(NET_DVR_Logout(lUserID)==false)
             {
                qDebug() << "NET_DVR_Logout error;" << "error number is " << NET_DVR_GetLastError();
                return;
             }
             lUserID=-1;
             qDebug() <<"Logout Success!"<<endl;
        }
    }
    
    LONG camera::play0(HWND hwnd,NET_DVR_PREVIEWINFO struPlayInfo)
    {
        struPlayInfo={0};
        struPlayInfo.hPlayWnd = hwnd;         //需要SDK解码时句柄设为有效值,仅取流不解码时可设为空
        struPlayInfo.lChannel     = 1;       //预览通道号
        struPlayInfo.dwStreamType = 0;       //0-主码流,1-子码流,2-码流3,3-码流4,以此类推
        struPlayInfo.dwLinkMode   = 0;       //0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
        struPlayInfo.bBlocked     = 0;
        lRealPlayHandle = NET_DVR_RealPlay_V40(lUserID, &struPlayInfo, nullptr, nullptr);
         if (lRealPlayHandle < 0)
         {
             printf("NET_DVR_RealPlay_V40 error\n");
             return -1;
         }
         return lRealPlayHandle;
    }
    
    void camera::log(QString a,QString b)
    {
        NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
        struLoginInfo.bUseAsynLogin = 0; //同步登录方式
        strcpy(struLoginInfo.sDeviceAddress, const_cast<char *>( qPrintable(a) )); //设备IP地址
        struLoginInfo.wPort = 8000; //设备服务端口
        strcpy(struLoginInfo.sUserName, "admin"); //设备登录用户名
        strcpy(struLoginInfo.sPassword, const_cast<char *>( qPrintable(b) )); //设备登录密码
        //设备信息, 输出参数
        NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
        lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
    }
    
    void camera::capture0(QString m)
    {
        if(lUserID!=-1){
            NET_DVR_JPEGPARA IpJpegPara2;
            IpJpegPara2.wPicQuality=0;
            IpJpegPara2.wPicSize=0xff;
            QDateTime current_date_time =QDateTime::currentDateTime();
            QString current_date =current_date_time.toString("yyyy-MM-dd-hh-mm-ss");
            current_date=m+current_date+".jpg";
            char*  fileName;
            QByteArray ba = current_date.toLatin1(); // must
            fileName=ba.data();
            if(NET_DVR_CaptureJPEGPicture(lUserID,1,&IpJpegPara2,fileName)==false)
            {
                 qDebug() << "NET_DVR_CaptureJPEGPicture error;" << "error number is " << NET_DVR_GetLastError();
            }
             return;
        }
    }
    
    void camera::capture1( Mat &img)
    {
            NET_DVR_JPEGPARA IpJpegPara3;
            IpJpegPara3.wPicQuality=0;
            IpJpegPara3.wPicSize=0xff;
    
            char*  fileNamenew =new char[2560*1440];
            DWORD len = 2560*1440;
            LPDWORD Ret = 0;
            vector<char>data(2560*1440);
            bool capture = NET_DVR_CaptureJPEGPicture_NEW(lUserID,1,&IpJpegPara3,fileNamenew,len,Ret);
            for(int i=0;i<2560*1440;i++){
                data[i] = fileNamenew[i];
            }
            Mat img1 = imdecode(Mat(data),1);
            img1.resize(640,360);
            img=img1;
            delete[] fileNamenew;
            img1.release();
            data.clear();
    }
    
    void camera::unit()
    {
        NET_DVR_StopRealPlay(lRealPlayHandle);
        //注销用户
        NET_DVR_Logout(lUserID);
        //释放SDK资源
        NET_DVR_Cleanup();
    }
    
    
    更多相关内容
  • Qt开发海康威视网络摄像头SDK,网络摄像头的注册与预览,相关函数的用法与示例。 Qt开发海康威视网络摄像头SDK,网络摄像头的注册与预览,相关函数的用法与示例。
  • Qt开发海康威视网络摄像头SDK,网络摄像头的注册与预览,相关函数的用法与示例 之前找了很久才找到了,传上来更大家共享下,希望对大家有帮助,欢迎下载或者永久保存。
  • 使用Qt调用海康威视SDK实现登陆、预览、抓图,包括源代码和可执行文件,可以作为服务端自动抓图、客户端预览等,可执行文件的依赖项已经全部打包。
  • 本代码是用Qt基于海康威视摄像头sdk开发的监控程序实例,比较简单,适用于新手使用,主要包括Qt海康威视摄像头sdk环境的搭建,api的调用等
  • 多说无意义 直接看图 下面有下载链接 环境是VS2013+Qt5.6.2 CSDN点击下载 GitHub CSDN 完整开发包和海康的库 GitHub只有代码 okjokull@gmail.com

    多说无意义
    直接看图
    下面有下载链接
    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    在原有基础上增加了录像与停止录像功能
    在这里插入图片描述

    环境是VS2013+Qt5.6.2

    CSDN下载链接

    CSDN 完整开发包和海康的库

    okjokull@gmail.com

    增加新功能后的链接
    https://download.csdn.net/download/weixin_39276851/21516016?spm=1001.2014.3001.5501

    展开全文
  • QT5.9 海康威视 自带Opencv,在显示中使用多线程技术,并附有详细的注释,就这样
  • 基于QT海康威视相机的二次开发,其中涉及到相机的标定,矫正,测量面积和周长

    工程链接:

            链接:https://pan.baidu.com/s/1SZFH9F8oVYtAEp8NQDGoRA?pwd=6pep 
    提取码:6pep

            注意将MVS目录下的Development下的include和libraries文件复制粘贴以后替换该工程下的同名文件

    1. 工程的总体构成介绍

    图1  工程构成

    如图一所示,主要由三个类来实现完整的功能,分别是mycamera,thread,widget类,mycamera类主要实现海康威视摄像头的打开,读取一帧图像,获取摄像头参数,关闭设备的功能,负责最初始的采集图像。Thread类主要是实现多线程抓取图像的功能。而widget类主要涉及到很多信号与槽函数的实现,其功能如图二和图三。

    图一

                                        图二                                                                                图三

    这些函数目的是要实现一下ui界面的功能。(如图四)

    (图四)

    2.功能效果演示

    2.1打开摄像头

    2.2获取摄像头截图

    2.3开始标定

    2.4矫正图像

    2.5测量面积

    6

    2.6测量周长

    3功能函数原理解析

    3.1打开摄像头

           //打开摄像头

        connect(ui->btnOpencamera,&QPushButton::clicked,this,&Widget::on_opencamera_clicked);

           先列举电脑上的USB设备,结合MVS的库文件函数,即封装在mycamera类中的EnumDevices函数可以搜寻到MVS海康威视相机。然后创建mycamera类,调用其中封装的打开摄像机函数,若打开成功则m_bOpenDevice设为true且检测到的摄像头指不设为空指针,这两个标识主要用于后期截取摄像头图片时的启动条件。此时由于截取图像和打开摄像头都需要显示图片,所以这里又设置了一个connect,将其连接到显示QImage图像函数slotDisImg,其中涉及到将opencv图像转换为QImage图像,并显示到label中。

    3.2截取摄像头图片

           //保存截图

    connect(ui->btnsaveImg,&QPushButton::clicked,this,&Widget::slotBtnsaveImg);

    若点击获取截图按钮,则将m_saveImage保存表示设位真,并利用QFileDialog::getSaveFileName句柄可选择路径保存图片。

    3.3开始标定

           //点击“开始检测”,显示角点的亚像素

    connect(ui->btnStartDetect,&QPushButton::clicked,this,&Widget::slotBtnStartDetect);

    先将图像转为灰度图,然后寻找角点,再然后便利寻找到的角点并画圆以显示角点。

    3.4矫正图片

           //显示校正后的结果

    connect(ui->btnShowResult,&QPushButton::clicked,this,&Widget::slotBtnShowResult);

    下图是

    先用matlab标定以后得到相机参数和畸变系数,然后手动输入相机参数和畸变系数,用opencv中的undistort矫正图片(图五是用matlab标定相机以后导出的.xml文件图片)。由于矫正的图像是极有价值的,所以这里默认保存矫正后的图片,有QT中自带的句柄选择矫正图片的保存路径。

                 

    3.5测量面积

               //检测面积

        connect(ui->btnArea,&QPushButton::clicked,this,&Widget::slotBtnArea);

           先对图像进行预处理,预处理如下:高斯滤波进行降噪,然后对图像进行二值化,在对图像进行形态学操作以后,使用阈值分割,再使用findContours找到轮廓,然后对轮廓求面积,其中要遍历所有轮廓,找到最大轮廓的面积。

    3.6测量周长

               //检测周长

        connect(ui->btnPerimeter,&QPushButton::clicked,this,&Widget::slotBtnPerimeter);

           操作步骤如5.5一致,只是计算轮廓周长和计算轮廓面积的函数不同罢了。

    3.7关闭摄像头

               //关闭摄像头

    connect(ui->btnCloseCamera,&QPushButton::clicked,this,&Widget::on_closecamera_clicked);

    主要是调用mycamera类中关闭相机的函数,再将打开摄像头时的m_pMvCamera设为空指针,将m_bOpenDevice设为false,这两步主要是为下一次开启摄像头做准备.

    4

    .关键函数一览

    展开全文
  • 使用QT5.9.3,MSVC2015 64位编译器(替换QT版本和编译器时,应替换对应的库文件等) 实现功能: 1、实时预览 2、抓图 3、录制视频 4、监听告警信号
  • 与上一篇不同的是,本篇注重于实现相机...提取码:lvu4环境配置:opencv开源库,Matlab,vs2017,qt以及海康相机配套的mvs软件,这是各个软件的安装包以及安装教程(先装vs2017,再安装qt)mvcamera.h: mvcamera.cpp:

    与上一篇不同的是,本篇注重于实现相机的一键开启,注重相机采集过程中调整曝光量和伽马矫正等。(代码来自短学期实践时五位老师提供的,上传以供大家学习借鉴)

    代码资源:

    链接:https://pan.baidu.com/s/19oeR5lgsF-FjJEd0EKpFrw?pwd=lvu4 
    提取码:lvu4

    环境配置:

    opencv开源库,Matlab,vs2017,qt以及海康相机配套的mvs软件,这是各个软件的安装包以及安装教程(先装vs2017,再安装qt)

    mvcamera.h:

    #ifndef MVCAMERA_H
    #define MVCAMERA_H
    
    #include <QObject>
    #include "string.h"
    #include "MvCameraControl.h"
    
    #ifndef MV_NULL
    #define MV_NULL    0
    #endif
    
    class MvCamera
    {
    public:
        MvCamera();
        ~MvCamera();
    
        // ch:枚举设备 | en:Enumerate Device
        static int EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST* pstDevList);
    
    
        /// ch:打开设备 | en:Open Device
        int Open(MV_CC_DEVICE_INFO* pstDeviceInfo);
    
        /// ch:关闭设备 | en:Close Device
        int Close();
    
        /// ch:注册图像数据回调 | en:Register Image Data CallBack
        int RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), void* pUser);
    
        /// ch:开启抓图 | en:Start Grabbing
        int StartGrabbing();
    
        /// ch:停止抓图 | en:Stop Grabbing
        int StopGrabbing();
    
        /// ch:主动获取一帧图像数据 | en:Get one frame initiatively
        int GetImageBuffer(MV_FRAME_OUT* pFrame, int nMsec);
    
        /// ch:释放图像缓存 | en:Free image buffer
        int FreeImageBuffer(MV_FRAME_OUT* pFrame);
    
        /// ch:显示一帧图像 | en:Display one frame image
        int DisplayOneFrame(MV_DISPLAY_FRAME_INFO* pDisplayInfo);
    
        /// ch:获取设备信息 | en:Get device information
        int GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo);
    
        // ch:获取和设置Enum型参数,如 PixelFormat,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
        // en:Get Enum type parameters, such as PixelFormat, for details please refer to MvCameraNode.xlsx file under SDK installation directory
        int GetEnumValue(IN const char* strKey, OUT MVCC_ENUMVALUE *pEnumValue);
        int SetEnumValue(IN const char* strKey, IN unsigned int nValue);
        int SetEnumValueByString(IN const char* strKey, IN const char* sValue);
    
        // ch:获取和设置Float型参数,如 ExposureTime和Gain,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
        // en:Get Float type parameters, such as ExposureTime and Gain, for details please refer to MvCameraNode.xlsx file under SDK installation directory
        int GetFloatValue(IN const char* strKey, OUT MVCC_FLOATVALUE *pFloatValue);
        int SetFloatValue(IN const char* strKey, IN float fValue);
    
        // ch:获取和设置Bool型参数,如 ReverseX,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
        // en:Get Bool type parameters, such as ReverseX, for details please refer to MvCameraNode.xlsx file under SDK installation directory
        int GetBoolValue(IN const char* strKey, OUT bool *pbValue);
        int SetBoolValue(IN const char* strKey, IN bool bValue);
    
    private:
    
        void*  m_hDevHandle;
    };
    
    #endif // MVCAMERA_H
    

    mvcamera.cpp:

    #include "mvcamera.h"
    
    MvCamera::MvCamera()
    {
        m_hDevHandle = MV_NULL;
    }
    
    MvCamera::~MvCamera()
    {
        if (m_hDevHandle)
        {
            MV_CC_DestroyHandle(m_hDevHandle);
            m_hDevHandle    = MV_NULL;
        }
    }
    
    int MvCamera::EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST *pstDevList)
    {
        return MV_CC_EnumDevices(nTLayerType, pstDevList);
    }
    
    int MvCamera::Open(MV_CC_DEVICE_INFO *pstDeviceInfo)
    {
        if (MV_NULL == pstDeviceInfo)
        {
            return MV_E_PARAMETER;
        }
    
        if (m_hDevHandle)
        {
            return MV_E_CALLORDER;
        }
    
        int nRet  = MV_CC_CreateHandle(&m_hDevHandle, pstDeviceInfo);
        if (MV_OK != nRet)
        {
            return nRet;
        }
    
        nRet = MV_CC_OpenDevice(m_hDevHandle);
        if (MV_OK != nRet)
        {
            MV_CC_DestroyHandle(m_hDevHandle);
            m_hDevHandle = MV_NULL;
        }
    
        return nRet;
    }
    
    int MvCamera::Close()
    {
        if (MV_NULL == m_hDevHandle)
        {
            return MV_E_HANDLE;
        }
    
        MV_CC_CloseDevice(m_hDevHandle);
    
        int nRet = MV_CC_DestroyHandle(m_hDevHandle);
        m_hDevHandle = MV_NULL;
    
        return nRet;
    }
    
    int MvCamera::RegisterImageCallBack(void (*cbOutput)(unsigned char *, MV_FRAME_OUT_INFO_EX *, void *), void *pUser)
    {
        return MV_CC_RegisterImageCallBackEx(m_hDevHandle, cbOutput, pUser);
    }
    
    int MvCamera::StartGrabbing()
    {
        return MV_CC_StartGrabbing(m_hDevHandle);
    }
    
    int MvCamera::StopGrabbing()
    {
        return MV_CC_StopGrabbing(m_hDevHandle);
    }
    
    int MvCamera::GetImageBuffer(MV_FRAME_OUT *pFrame, int nMsec)
    {
        return MV_CC_GetImageBuffer(m_hDevHandle, pFrame, nMsec);
    }
    
    int MvCamera::FreeImageBuffer(MV_FRAME_OUT *pFrame)
    {
        return MV_CC_FreeImageBuffer(m_hDevHandle, pFrame);
    }
    
    int MvCamera::DisplayOneFrame(MV_DISPLAY_FRAME_INFO *pDisplayInfo)
    {
        return MV_CC_DisplayOneFrame(m_hDevHandle, pDisplayInfo);
    }
    
    int MvCamera::GetDeviceInfo(MV_CC_DEVICE_INFO *pstDevInfo)
    {
        return MV_CC_GetDeviceInfo(m_hDevHandle, pstDevInfo);
    }
    
    int MvCamera::SetEnumValue(const char *strKey, unsigned int nValue)
    {
        return MV_CC_SetEnumValue(m_hDevHandle, strKey, nValue);
    }
    
    int MvCamera::GetFloatValue(const char *strKey, MVCC_FLOATVALUE *pFloatValue)
    {
        return MV_CC_GetFloatValue(m_hDevHandle, strKey, pFloatValue);
    }
    
    int MvCamera::SetFloatValue(const char *strKey, float fValue)
    {
        return MV_CC_SetFloatValue(m_hDevHandle, strKey, fValue);
    }
    
    int MvCamera::SetBoolValue(const char *strKey, bool bValue)
    {
        return MV_CC_SetBoolValue(m_hDevHandle, strKey, bValue);
    }
    

    grabthread.h:

    #ifndef GRABTHREAD_H
    #define GRABTHREAD_H
    
    #include <QObject>
    #include <QThread>
    #include <QDebug>
    #include "mvcamera.h"
    #include <QImage>
    #include "opencv2/opencv.hpp"
    #include "opencv2/core.hpp"
    #include "algorithm.h"
    
    class Algorithm;
    class GrabThread
            :public QThread
    {
        Q_OBJECT
    public:
        GrabThread(MvCamera *pMvCamera);
        ~GrabThread();
        virtual void run();
    
        inline void setThreadState(bool ret) {m_bThreadState = ret;}
    signals:
        void grabImg(QImage& img);
    
    private:
        MvCamera* m_pMvCamera;
        bool m_bThreadState;
    };
    
    #endif // GRABTHREAD_H
    

    grabthread.cpp:

    #include "grabthread.h"
    
    GrabThread::GrabThread(MvCamera *pMvCamera)
        :m_bThreadState(false)
    {
        m_pMvCamera = pMvCamera;
    
        qRegisterMetaType<QImage>(" QImage&");
    }
    
    GrabThread::~GrabThread()
    {
    //    delete m_pMvCamera;
    //    m_pMvCamera = nullptr;
    }
    
    void GrabThread::run()
    {
        MV_FRAME_OUT stImageInfo = {0};
        int nRet = MV_OK;
        while(m_bThreadState)
        {
            qDebug()<<m_bThreadState;
            nRet = m_pMvCamera->GetImageBuffer(&stImageInfo, 1000);
            if(nRet == MV_OK)
            {
                void* buff = stImageInfo.pBufAddr;
                int width = stImageInfo.stFrameInfo.nWidth;
                int height = stImageInfo.stFrameInfo.nHeight;
    
                m_pMvCamera->FreeImageBuffer(&stImageInfo);
                cv::Mat Mat_img = cv::Mat(height,width,CV_8UC3,(uchar*)buff);
                cv::cvtColor(Mat_img,Mat_img,cv::COLOR_BGR2RGB);
    
                Algorithm alg;
                QImage img = alg.Mat2QImage(Mat_img);
    //            QImage img = QImage(buff,width,height,QImage::Format_RGB888);
    //            cvtColor(image,rgb,CV_BGR2RGB);
    
    //            QImage img;
    //            try
    //            {
    //                cv::Mat matImg;
    //                matImg = cv::Mat(height,width,CV_8UC3,buff);
                    cv::cvtColor(matImg,matImg,cv::COLOR_BGR2RGB);
    //                Algorithm alg;
    //                img = alg.Mat2QImage(matImg);
    //            }
    //            catch(cv::Exception& e)
    //            {
    //                qDebug()<<"error";
    //            }
    //            QImage img(width,height,QImage::Format_Indexed8);
    //            {
    //                img.setColorCount(256);
    //                for(int i=0;i<256;i++)
    //                    img.setColor(i,qRgb(i,i,i));
    //                uchar *pSrc = reinterpret_cast<uchar*>(buff);
    //                for(int row = 0; row<height;row ++)
    //                {
    //                    uchar *pDest =  img.scanLine(row);
    //                    memcpy(pDest,pSrc,static_cast<size_t>(width));
    //                    pSrc += width;
    //                }
    //            }
    
                emit grabImg(img);
    
    
            }
    
    
        }
    }
    
    algorithm.h:
    #ifndef ALGORITHM_H
    #define ALGORITHM_H
    
    #include "opencv2/opencv.hpp"
    #include "opencv2/core.hpp"
    #include "qimage.h"
    #include "QDebug"
    
    class Algorithm
    {
    public:
        Algorithm();
        QImage Mat2QImage(const cv::Mat& mat);
        cv::Mat QImage2cvMat(QImage image);
    };
    
    #endif // ALGORITHM_H
    
    algorithm.cpp:
    #include "algorithm.h"
    
    Algorithm::Algorithm()
    {
    }
    
    cv::Mat Algorithm::QImage2cvMat(QImage image)
    {
        cv::Mat mat;
       // qDebug() << image.format();
        switch(image.format())
        {
        case QImage::Format_ARGB32:
        case QImage::Format_RGB32:
        case QImage::Format_ARGB32_Premultiplied:
            mat = cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine());
            break;
        case QImage::Format_RGB888:
            mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.constBits(), image.bytesPerLine());
            cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB);
            break;
        case QImage::Format_Indexed8:
            mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine());
            break;
        }
        return mat;
    }
    
    QImage Algorithm::Mat2QImage(const cv::Mat& mat)
    
    {
        // 8-bits unsigned, NO. OF CHANNELS = 1
        if(mat.type() == CV_8UC1)
        {
            QImage image(mat.cols, mat.rows, QImage::Format_Indexed8);
            // Set the color table (used to translate colour indexes to qRgb values)
            image.setColorCount(256);
            for(int i = 0; i < 256; i++)
            {
                image.setColor(i, qRgb(i, i, i));
            }
            // Copy input Mat
            uchar *pSrc = mat.data;
            for(int row = 0; row < mat.rows; row ++)
            {
                uchar *pDest = image.scanLine(row);
                memcpy(pDest, pSrc, mat.cols);
                pSrc += mat.step;
            }
            return image;
        }
        // 8-bits unsigned, NO. OF CHANNELS = 3
        else if(mat.type() == CV_8UC3)
        {
            // Copy input Mat
            const uchar *pSrc = (const uchar*)mat.data;
            // Create QImage with same dimensions as input Mat
            QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
            return image.rgbSwapped();
        }
        else if(mat.type() == CV_8UC4)
        {
            qDebug() << "CV_8UC4";
            // Copy input Mat
            const uchar *pSrc = (const uchar*)mat.data;
            // Create QImage with same dimensions as input Mat
            QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_ARGB32);
            return image.copy();
        }
        else
        {
            qDebug() << "ERROR: Mat could not be converted to QImage.";
            return QImage();
        }
    
    
    }
    
    
    widget.h:
    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    #include "mvcamera.h"
    #include "QDebug"
    #include "grabthread.h"
    #include <QMessageBox>
    #include "algorithm.h"
    #include "string.h"
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class Widget; }
    QT_END_NAMESPACE
    
    typedef enum
    {
        GrabState_OpenGrab,
        GrabState_CloseGrab,
    }GrabState;
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = nullptr);
        ~Widget();
    public slots:
        // 打开,关闭设备槽函数
        void slotBtnOpenDevice();
        void slotBtnCloseDevice();
        // 开始停止抓取图像槽函数
        void slotBtnStartGrab();
        void slotBtnStopGrab();
        // 显示图像槽函数
        void slotDisImg(QImage &img);
    
        // 保存图像槽函数
        void slotBtnSaveBMP();
        void slotBtnSaveJPG();
        void slotBtnSaveTIFF();
        void slotBtnSavePNG();
    
        // 相机参数相关槽函数
        void slotBtnGetParam();
        void slotBtnSetParam();
    
        // g伽马校正相关槽函数
        void slotBtnGetGamma();
        void slotBtnSetGamma();
    
    private:
        void updateState(GrabState ret);
    
    private:
        bool m_bOpenDevice;
    private:
        double m_dExposureEdit;  // 曝光时间
        double m_dGainEdit;      // 增益
        double m_dFrameRateEdit; // 帧率
        double m_dGammaEdit; // 伽马值
    
        int GetExposureTime(); // ch:设置曝光时间 | en:Set Exposure Time
        int SetExposureTime();
        int GetGain();         // ch:设置增益 | en:Set Gain
        int SetGain();
        int GetFrameRate();    // ch:设置帧率 | en:Set Frame Rate
        int SetFrameRate();
        int GetGamma();    // ch:伽马矫正 | en:Set Gamma
        int SetGamma();
    
    
    private:
        bool m_bSaveImgBMP;
        bool m_bSaveImgJPG;
        bool m_bSaveImgTIFF;
        bool m_bSaveImgPNG;
        bool m_bUpdateData;
    
        MvCamera* m_pMvCamera;
        GrabThread* m_pGrabThread;
        Ui::Widget *ui;
    };
    #endif // WIDGET_H
    
    widget.cpp:
    #include "widget.h"
    #include "ui_widget.h"
    #include <QFileDialog>
    #include "string.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , m_bOpenDevice(false)
        , m_pMvCamera(nullptr)
        , m_pGrabThread(nullptr)
        , ui(new Ui::Widget)
        , m_bSaveImgBMP(false)
        , m_bSaveImgJPG(false)
        , m_bSaveImgTIFF(false)
        , m_bSaveImgPNG(false)
        , m_bUpdateData(false)
    
        , m_dExposureEdit(0)
        , m_dGainEdit(0)
        , m_dFrameRateEdit(0)
        , m_dGammaEdit(0)
    
    {
        ui->setupUi(this);
    
        // 点击“开始抓图”, 开始抓取图像
        connect(ui->btnStartGrab,&QPushButton::clicked,this,&Widget::slotBtnStartGrab);
        // 点击“停止抓图”, 停止抓取图像
        connect(ui->btnStopGrab,&QPushButton::clicked,this,&Widget::slotBtnStopGrab);
    
        // 点击“保存图像”,开始保存图像
        connect(ui->btnSaveBMP,&QPushButton::clicked,this,&Widget::slotBtnSaveBMP);
        connect(ui->btnSaveJPG,&QPushButton::clicked,this,&Widget::slotBtnSaveJPG);
        connect(ui->btnSaveTIFF,&QPushButton::clicked,this,&Widget::slotBtnSaveTIFF);
        connect(ui->btnSavePNG,&QPushButton::clicked,this,&Widget::slotBtnSavePNG);
    
        connect(ui->btnCloseWin,&QPushButton::clicked,this,&Widget::close);
    
        // 点击“参数获取”,获取相机参数
        connect(ui->B_getParam,&QPushButton::clicked,this,&Widget::slotBtnGetParam);
        // 点击“参数设置”,设置相机参数
        connect(ui->B_setParam,&QPushButton::clicked,this,&Widget::slotBtnSetParam);
    
        // 点击“参数获取”,获取gamma值
        connect(ui->B_getGamma,&QPushButton::clicked,this,&Widget::slotBtnGetGamma);
        // 点击“伽马校正”,进行伽马校正
        connect(ui->B_setGamma,&QPushButton::clicked,this,&Widget::slotBtnSetGamma);
    
        updateState(GrabState_CloseGrab);
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::slotBtnOpenDevice()
    {
    
        if(true == m_bOpenDevice || m_pMvCamera != nullptr)
        {
            qDebug()<<"is open Device";
            return;
        }
    
    
        // get current link camera
        MV_CC_DEVICE_INFO_LIST  m_stDevList;
        int nRet = MvCamera::EnumDevices(MV_GIGE_DEVICE , &m_stDevList);
        if (MV_OK != nRet)
        {
            qDebug()<<"get Camera Error";
            return;
        }
    
        m_pMvCamera = new MvCamera;
        if(nullptr == m_pMvCamera)
            return;
    
        nRet = m_pMvCamera->Open(m_stDevList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            delete m_pMvCamera;
            m_pMvCamera = nullptr;
            qDebug()<<"Open Fail";
            return;
        }
    
        qDebug()<<"Open success";
        m_bOpenDevice = true;
    }
    
    void Widget::slotBtnCloseDevice()
    {
        if(m_pMvCamera != nullptr)
        {
            m_pMvCamera->Close();
    
            delete m_pMvCamera;
            m_pMvCamera = nullptr;
            qDebug()<<"close success";
            m_bOpenDevice = false;
        }
        else
           qDebug()<<"device is not create";
    }
    
    void Widget::slotBtnStartGrab()
    {
        slotBtnOpenDevice();
        QThread::msleep(500);
        if(!m_bOpenDevice )
        {
            QMessageBox::information(this,"error","device is not open");
            return;
        }
    
        m_pGrabThread = new GrabThread(m_pMvCamera);
    
        connect(m_pGrabThread,&GrabThread::grabImg,this,&Widget::slotDisImg);
    
        int nRet = m_pMvCamera->StartGrabbing();
    
        if (MV_OK != nRet)
        {
            qDebug()<<"Start grabbing fail : "<< nRet;
            return;
        }
        qDebug()<<"Start grabbing sussess";
    
        m_pGrabThread->setThreadState(true);
        m_pGrabThread->start();
    
        updateState(GrabState_OpenGrab);
    
    
    }
    
    void Widget::slotBtnStopGrab()
    {
        if(true != m_bOpenDevice || m_pMvCamera == nullptr|| m_pGrabThread == nullptr)
        {
            return;
        }
    
        m_pGrabThread->setThreadState(false);
        m_pGrabThread->wait();
        m_pGrabThread->quit();
        disconnect(m_pGrabThread,&GrabThread::grabImg,this,&Widget::slotDisImg);
    
        int nRet = m_pMvCamera->StopGrabbing();
    
        delete m_pGrabThread;
    //    m_pGrabThread->deleteLater();
        m_pGrabThread = nullptr;
    
        if (MV_OK != nRet)
        {
            qDebug()<<"Stop grabbing fail";
            return;
        }
        qDebug()<<"Stop grabbing sussess";
    
        QThread::msleep(500);
    
        slotBtnCloseDevice();
    
        updateState(GrabState_CloseGrab);
    
    }
    
    void Widget::slotDisImg(QImage &img)
    {
        qDebug()<<"slot frame";
        ui->label->clear();
    //    img = img.scaled(ui->label->width(), ui->label->height());
        img = img.scaled(ui->label->size(),Qt::IgnoreAspectRatio);
        ui->label->setScaledContents(true);
    
        Algorithm alg;
        cv::Mat matImg = alg.QImage2cvMat(img);
    
    //    cv::threshold(matImg,matImg,128,255,1);
    
        QImage retImg = alg.Mat2QImage(matImg);
    
    //    QImage retImg =  img;
        ui->label->setPixmap(QPixmap::fromImage(retImg));
    
        if(m_bSaveImgBMP == true)
        {
            m_bSaveImgBMP = false;
            // add code to save img
            QString filename = QFileDialog::getSaveFileName(NULL, tr("Save Image"), "", tr("Images (*.bmp)"));
            cv::imwrite(filename.toStdString(), matImg);
        }
        if(m_bSaveImgJPG == true)
        {
            m_bSaveImgJPG = false;
            // add code to save img
            QString filename = QFileDialog::getSaveFileName(NULL, tr("Save Image"), "", tr("Images (*.jpg)"));
            cv::imwrite(filename.toStdString(), matImg);
        }
        if(m_bSaveImgTIFF == true)
        {
            m_bSaveImgTIFF = false;
            // add code to save img
            QString filename = QFileDialog::getSaveFileName(NULL, tr("Save Image"), "", tr("Images (*.tiff)"));
            cv::imwrite(filename.toStdString(), matImg);
        }
        if(m_bSaveImgPNG == true)
        {
            m_bSaveImgPNG = false;
            // add code to save img
            QString filename = QFileDialog::getSaveFileName(NULL, tr("Save Image"), "", tr("Images (*.png)"));
            cv::imwrite(filename.toStdString(), matImg);
        }
    
    }
    
    void Widget::slotBtnSaveBMP()
    {
        m_bSaveImgBMP = true;
    }
    
    void Widget::slotBtnSaveJPG()
    {
        m_bSaveImgJPG = true;
    }
    void Widget::slotBtnSaveTIFF()
    {
        m_bSaveImgTIFF = true;
    }
    void Widget::slotBtnSavePNG()
    {
        m_bSaveImgPNG= true;
    }
    
    void Widget::slotBtnGetParam()
    {
        int nRet = GetExposureTime();
            if (nRet != MV_OK)
            {
                QMessageBox::information(this,"error","Get Exposure Time Fail");
    
            }
    
            nRet = GetGain();
            if (nRet != MV_OK)
            {
                QMessageBox::information(this,"error","Get Gain Fail");
            }
    
            nRet = GetFrameRate();
            if (nRet != MV_OK)
            {
                QMessageBox::information(this,"error","Get Frame Rate Fail");
            }
    
            m_bUpdateData = false;
    }
    
    void Widget::slotBtnSetParam()
    {
        m_bUpdateData = true;
    
            bool bIsSetSucceed = true;
            int nRet = SetExposureTime();
            if (nRet != MV_OK)
            {
                bIsSetSucceed = false;
                QMessageBox::information(this,"error","Set Exposure Time Fail");
    
            }
            nRet = SetGain();
            if (nRet != MV_OK)
            {
                bIsSetSucceed = false;
                QMessageBox::information(this,"error","设置增益失败,增益范围:0~15.0062");
            }
            nRet = SetFrameRate();
            if (nRet != MV_OK)
            {
                bIsSetSucceed = false;
                QMessageBox::information(this,"error","Set Frame Rate Fail");
            }
    
            if (true == bIsSetSucceed)
            {
                QMessageBox::information(this,"Succeed","Set Parameter Succeed");
            }
    }
    
    void Widget::updateState(GrabState ret)
    {
        if(ret == GrabState_OpenGrab)
        {
            ui->btnCloseWin->setEnabled(false);
            ui->B_getParam->setEnabled(true);
            ui->B_setParam->setEnabled(true);
            ui->B_getGamma->setEnabled(true);
            ui->B_setGamma->setEnabled(true);
            ui->btnSaveBMP->setEnabled(true);
            ui->btnSaveJPG->setEnabled(true);
            ui->btnSaveTIFF->setEnabled(true);
            ui->btnSavePNG->setEnabled(true);
        }
        else
        {
            ui->btnCloseWin->setEnabled(true);
            ui->B_getParam->setEnabled(false);
            ui->B_setParam->setEnabled(false);
            ui->B_getGamma->setEnabled(false);
            ui->B_setGamma->setEnabled(false);
            ui->btnSaveBMP->setEnabled(false);
            ui->btnSaveJPG->setEnabled(false);
            ui->btnSaveTIFF->setEnabled(false);
            ui->btnSavePNG->setEnabled(false);
        }
    }
    
    
    
    // 设置相机参数
    int Widget::GetExposureTime()
    {
        MVCC_FLOATVALUE stFloatValue = {0};
    
            int nRet = m_pMvCamera->GetFloatValue("ExposureTime", &stFloatValue);
            if (MV_OK != nRet)
            {
                return nRet;
            }
    
            m_dExposureEdit = stFloatValue.fCurValue;
            QString exposure_str = QString::number(m_dExposureEdit, 'f', 2);
            ui->B__expose->setPlainText(exposure_str);
            return MV_OK;
    }
    
    int Widget::SetExposureTime()
    {
        // ch:调节这两个曝光模式,才能让曝光时间生效
            int nRet = m_pMvCamera->SetEnumValue("ExposureMode", MV_EXPOSURE_MODE_TIMED);
            if (MV_OK != nRet)
            {
                return nRet;
            }
    
            m_pMvCamera->SetEnumValue("ExposureAuto", MV_EXPOSURE_AUTO_MODE_OFF);
            m_dExposureEdit = ui->B__expose->toPlainText().toDouble();
            return m_pMvCamera->SetFloatValue("ExposureTime", (float)m_dExposureEdit);
    }
    
    int Widget::GetGain()
    {
        MVCC_FLOATVALUE stFloatValue = {0};
            int nRet = m_pMvCamera->GetFloatValue("Gain", &stFloatValue);
            if (MV_OK != nRet)
            {
                return nRet;
            }
            m_dGainEdit = stFloatValue.fCurValue;
            QString gain_str = QString::number(m_dGainEdit, 'f', 2);
            ui->B__gamma_2->setPlainText(gain_str);
            return MV_OK;
    }
    
    int Widget::SetGain()
    {
        // ch:设置增益前先把自动增益关闭,失败无需返回
            m_pMvCamera->SetEnumValue("GainAuto", 100);
            m_dGainEdit = ui->B__gamma_2->toPlainText().toDouble();
            return m_pMvCamera->SetFloatValue("Gain", (float)m_dGainEdit);
    }
    
    int Widget::GetFrameRate()
    {
        MVCC_FLOATVALUE stFloatValue = {0};
            int nRet = m_pMvCamera->GetFloatValue("ResultingFrameRate", &stFloatValue);
            if (MV_OK != nRet)
            {
                return nRet;
            }
            m_dFrameRateEdit = stFloatValue.fCurValue;
            QString frameRate_str = QString::number(m_dFrameRateEdit, 'f', 2);
            ui->B__fps->setPlainText(frameRate_str);
            return MV_OK;
    }
    
    int Widget::SetFrameRate()
    {
        int nRet = m_pMvCamera->SetBoolValue("AcquisitionFrameRateEnable", true);
            if (MV_OK != nRet)
            {
                return nRet;
            }
            m_dFrameRateEdit = ui->B__fps->toPlainText().toDouble();
            return m_pMvCamera->SetFloatValue("AcquisitionFrameRate", (float)m_dFrameRateEdit);
    }
    
    int Widget::GetGamma()
    {
        MVCC_FLOATVALUE stFloatValue = {0};
            int nRet = m_pMvCamera->GetFloatValue("Gamma", &stFloatValue);
            if (MV_OK != nRet)
            {
                return nRet;
            }
            m_dGammaEdit = stFloatValue.fCurValue;
            QString gamma_str = QString::number(m_dGammaEdit, 'f', 2);
            ui->B__Gamma->setPlainText(gamma_str);
            return MV_OK;
    }
    
    int Widget::SetGamma()
    {
        int nRet = m_pMvCamera->SetBoolValue("GammaEnable", true);
            if (MV_OK != nRet)
            {
                return nRet;
            }
            m_dGammaEdit = ui->B__Gamma->toPlainText().toDouble();
            return m_pMvCamera->SetFloatValue("Gamma", (float)m_dGammaEdit);
    }
    
    void Widget::slotBtnGetGamma()
    {
        int nRet = GetGamma();
            if (nRet != MV_OK)
            {
                QMessageBox::information(this,"error","Get Gamma Fail");
            }
            m_bUpdateData = false;
    }
    
    void Widget::slotBtnSetGamma()
    {
        m_bUpdateData = true;
    
            bool bIsSetSucceed = true;
            int nRet = SetGamma();
            if (nRet != MV_OK)
            {
                bIsSetSucceed = false;
                QMessageBox::information(this,"error","设置伽马校正失败, gamma取值范围:0~4");
    
            }
    
            if (true == bIsSetSucceed)
            {
                QMessageBox::information(this,"Succeed","Gamma Correction Succeed");
            }
    }
    

    widget.ui:(自动生成)

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>Widget</class>
     <widget class="QWidget" name="Widget">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>798</width>
        <height>548</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Widget</string>
      </property>
      <widget class="QLabel" name="label">
       <property name="geometry">
        <rect>
         <x>9</x>
         <y>9</y>
         <width>551</width>
         <height>521</height>
        </rect>
       </property>
       <property name="styleSheet">
        <string notr="true">QLabel{
    border-image:url(1.jpg);
    border:5px solid red;
    border-image:url(1.jpg);
    }
    </string>
       </property>
       <property name="text">
        <string/>
       </property>
      </widget>
      <widget class="QGroupBox" name="groupBox_3">
       <property name="geometry">
        <rect>
         <x>570</x>
         <y>90</y>
         <width>221</width>
         <height>106</height>
        </rect>
       </property>
       <property name="styleSheet">
        <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: rgb(255, 255, 255);</string>
       </property>
       <property name="title">
        <string>图像保存</string>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout_3">
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_4">
          <item>
           <widget class="QPushButton" name="btnSaveBMP">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>保存BMP</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPushButton" name="btnSaveJPG">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>保存JPG</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_5">
          <item>
           <widget class="QPushButton" name="btnSaveTIFF">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>保存TIFF</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPushButton" name="btnSavePNG">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>保存PNG</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
       </layout>
      </widget>
      <widget class="QGroupBox" name="groupBox_4">
       <property name="geometry">
        <rect>
         <x>570</x>
         <y>20</y>
         <width>221</width>
         <height>68</height>
        </rect>
       </property>
       <property name="styleSheet">
        <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: rgb(255, 255, 255);</string>
       </property>
       <property name="title">
        <string>图像采集</string>
       </property>
       <widget class="QWidget" name="layoutWidget">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>30</y>
          <width>208</width>
          <height>32</height>
         </rect>
        </property>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <widget class="QPushButton" name="btnStartGrab">
           <property name="minimumSize">
            <size>
             <width>100</width>
             <height>30</height>
            </size>
           </property>
           <property name="toolTip">
            <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
           </property>
           <property name="styleSheet">
            <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
           </property>
           <property name="text">
            <string>开始抓图</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="btnStopGrab">
           <property name="minimumSize">
            <size>
             <width>100</width>
             <height>30</height>
            </size>
           </property>
           <property name="toolTip">
            <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
           </property>
           <property name="styleSheet">
            <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
           </property>
           <property name="text">
            <string>停止抓图</string>
           </property>
          </widget>
         </item>
        </layout>
       </widget>
      </widget>
      <widget class="QGroupBox" name="groupBox_5">
       <property name="geometry">
        <rect>
         <x>570</x>
         <y>200</y>
         <width>228</width>
         <height>182</height>
        </rect>
       </property>
       <property name="styleSheet">
        <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: rgb(255, 255, 255);</string>
       </property>
       <property name="title">
        <string>参数设置</string>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_7">
          <item>
           <widget class="QLabel" name="label_2">
            <property name="styleSheet">
             <string notr="true">background-color: rgb(255, 255, 174);</string>
            </property>
            <property name="text">
             <string>曝光</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPlainTextEdit" name="B__expose">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>30</height>
             </size>
            </property>
            <property name="styleSheet">
             <string notr="true">background-color: qradialgradient(spread:repeat, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 170, 0, 62), stop:1 rgba(255, 255, 255, 255));</string>
            </property>
            <property name="placeholderText">
             <string>请输入曝光值</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_8">
          <item>
           <widget class="QLabel" name="label_3">
            <property name="styleSheet">
             <string notr="true">background-color: rgb(255, 255, 174);</string>
            </property>
            <property name="text">
             <string>增益</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPlainTextEdit" name="B__gamma_2">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>30</height>
             </size>
            </property>
            <property name="styleSheet">
             <string notr="true">background-color: qradialgradient(spread:repeat, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 170, 0, 62), stop:1 rgba(255, 255, 255, 255));</string>
            </property>
            <property name="placeholderText">
             <string>取值范围:0~15</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_9">
          <item>
           <widget class="QLabel" name="label_4">
            <property name="styleSheet">
             <string notr="true">background-color: rgb(255, 255, 174);</string>
            </property>
            <property name="text">
             <string>帧率</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPlainTextEdit" name="B__fps">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>30</height>
             </size>
            </property>
            <property name="styleSheet">
             <string notr="true">background-color: qradialgradient(spread:repeat, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 170, 0, 62), stop:1 rgba(255, 255, 255, 255));</string>
            </property>
            <property name="placeholderText">
             <string>请输入帧率值</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_6">
          <item>
           <widget class="QPushButton" name="B_getParam">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>参数获取</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPushButton" name="B_setParam">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>参数设置</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
       </layout>
      </widget>
      <widget class="QGroupBox" name="groupBox_6">
       <property name="geometry">
        <rect>
         <x>570</x>
         <y>380</y>
         <width>221</width>
         <height>111</height>
        </rect>
       </property>
       <property name="styleSheet">
        <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: rgb(255, 255, 255);</string>
       </property>
       <property name="title">
        <string>伽马校正</string>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_10">
          <item>
           <widget class="QLabel" name="label_Gamma">
            <property name="styleSheet">
             <string notr="true">background-color: rgb(255, 255, 174);</string>
            </property>
            <property name="text">
             <string>伽马值</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPlainTextEdit" name="B__Gamma">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>30</height>
             </size>
            </property>
            <property name="styleSheet">
             <string notr="true">background-color: qradialgradient(spread:repeat, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 170, 0, 62), stop:1 rgba(255, 255, 255, 255));</string>
            </property>
            <property name="placeholderText">
             <string>取值范围:0~4</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item>
         <layout class="QHBoxLayout" name="horizontalLayout_13">
          <item>
           <widget class="QPushButton" name="B_getGamma">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>参数获取</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPushButton" name="B_setGamma">
            <property name="minimumSize">
             <size>
              <width>100</width>
              <height>30</height>
             </size>
            </property>
            <property name="toolTip">
             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
            </property>
            <property name="styleSheet">
             <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
            </property>
            <property name="text">
             <string>伽马校正</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
       </layout>
      </widget>
      <widget class="QPushButton" name="btnCloseWin">
       <property name="geometry">
        <rect>
         <x>690</x>
         <y>500</y>
         <width>100</width>
         <height>30</height>
        </rect>
       </property>
       <property name="minimumSize">
        <size>
         <width>100</width>
         <height>30</height>
        </size>
       </property>
       <property name="toolTip">
        <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ffffff;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
       </property>
       <property name="styleSheet">
        <string notr="true">font: 12pt &quot;楷体&quot;;
    background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 235, 235, 206), stop:0.35 rgba(255, 188, 188, 80), stop:0.4 rgba(255, 162, 162, 80), stop:0.425 rgba(255, 132, 132, 156), stop:0.44 rgba(252, 128, 128, 80), stop:1 rgba(255, 255, 255, 0));</string>
       </property>
       <property name="text">
        <string>关闭程序</string>
       </property>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    展开全文
  • Qt 调用海康摄像头完成视频预览
  • 默认的例程中不含Qt的例子,所以自己写了一个在Qt下调用海康SDK接口实现网络摄像头视频播放的例程。
  • 海康威视sdk结合qt和openc进行调试,采用独占锁模式,保证采集的速率和处理效率
  • 任务:将基于MFC图形框架的海康威视工业相机的操作,完全移植到Qt中,也就是基于Qt来实现,所选的开发环境为Qt creator,并且功能基本完全模仿MFC。 先来看一下基于MFC实现的效果图: 再来看一下基于qt实现的效果图:...
  • 最近用Qt做了一个基于海康威视网络摄像头SDK的二次开发,效果还不错。文章最后将开发的资料和demo软件通过链接方式分享,有兴趣的可以看下效果。 开发情况介绍: qt版本:Qt5.14.2 海康SDK版本:SDK_Win64 ...
  • LIBS += -LD:\project_name\ -lHCCore -lHCNetSDK \ -lPlayCtrl -lHCCoreDevCfg \ -lHCGeneralCfgMgr 需要把动态库文件和lib文件同时放入指定的目录:“D:\project_name\”, 否则会出现找不到动态库文件。...
  • 海康威视二次开发。布防,撤防,预览,抓图,录像,停止录像,入侵告警 演示地址: https://blog.csdn.net/weixin_39276851/article/details/110871893 开发环境:Vs2013+QT5.6.2
  • 最近有个项目涉及海康威视的摄像头部分,需要在服务器端自动定时抓图,由于服务器端采用的是Windows系统,不熟Windows的api,所以直接采用Qt来编写。那么摄像头的激活配置什么的就不再介绍了,直接进入正题。 先...
  • Qt调用工业相机之海康威视相机

    千次阅读 多人点赞 2020-08-03 13:05:52
    作者:billy 版权声明:著作权归作者所有,商业转载请联系作者...软件版本:Qt 5.12.8, vs2017 Community 通信方式:GigE - 千兆以太网通信协议 驱动与SDK 开发包和驱动下载地址 提取码:2hhn 安装驱动和开发包完成
  • 该文章主要介绍如何在Qt5开发环境下,使用海康威视SDK将视频流显示在界面上的具体方法。
  • 海康威视二次开发。布防,撤防,预览,抓图等 开发环境:Vs2013+QT5.6.2 摄像头:红外网络摄像头枪机,型号DS-2CD3T10D-13 Email:okjokull@gmail.com GitHub: https://github.com/okjokull/QHikvision/tree/master ...
  • 海康sdk二次开发
  • 里面有两个代码,一个是qt界面显示一个是控制台抓取RGB数据,1、将工程中的.pro中的文件路径改为自己放海康威视sdk的路径.
  • 海康威视网络摄像头SDK的二次开发,需要摄像头IP地址,与主机的IP地址在同一网段,能够ping通摄像头IP,才能登录成功。摄像头是有账户名和密码,这需要记住,在开发的时候需要用到。 在开发前可以先用IE浏览器,...
  • if (lRealPlayHandle ) { qDebug()预览失败: " 7、项目构建,在建好的Debug路径内拷入海康SDK 动态链接库 【需特别注意,所选的海康威视SDK要与QT项目一致,32位对应32位,64位对应64位,不可混淆,否则编译无提示...
  • QT引入海康威视SDK 有了上面的理解,现在分别将上述3个文件引入到QT工程下即可,总共分为4个步骤: Step1(.h文件引入):首先建立一个QT工程,并在工程下新建文件夹【include】(也可自定义名字),然后将海康威视SDK...
  • QT + C++ + 海康威视工业相机二次开发 2021-05-12

    千次阅读 热门讨论 2021-05-12 10:25:08
    1.了解海康威视工业相机 本人学习参考的是:boss_dog的博客,里面有详细的分析相机的数据,各种相机的区别,在VS中部署SDK的环境变量以及官方例程. 1.1.下载SDK 海康威视的工业相机二次开发首先是需要在...

空空如也

空空如也

1 2 3 4 5 ... 18
收藏数 342
精华内容 136
关键字:

QT 海康威视