基于QT的海康威视的相机二次开发

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

代码资源:

链接: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>

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
### 回答1: Java是一种广泛应用的编程语言,而海康威视是一家知名的视听设备生产厂商,其提供的SDK包含了海康威视所生产的视频监控设备通信协议以及数据处理方案。基于海康威视SDK进行Java的二次开发可以使开发者在海康威视设备的基础上构建出更加灵活、高效的应用程序,提高了开发效率和安全性。 使用Java的特性来实现对海康威视设备的二次开发,主要包括以下几个方面: 1. 处理设备的通信协议:使用Java的网络编程技术,基于海康威视SDK中所提供的设备通信协议进行二次开发,可以实现设备之间的数据交互。 2. 实现设备数据的解析:使用Java的数据处理技术,对从设备中获取的数据进行解析和处理,将数据转换成开发者想要的格式,以便进行进一步的数据处理。 3. 开发可视化界面:通过Java的图形用户界面(GUI)开发技术,基于海康威视SDK提供的数据处理方案,开发出用户友好的界面,实现对设备的远程控制和监控。 通过基于海康威视SDK进行Java的二次开发,开发者可以轻松地实现对海康威视设备的控制和监控,从而扩展了设备的功能和优化了用户体验。 ### 回答2: Java语言是当前应用非常广泛的编程语言之一,而海康威视则是国内领先的视频监控设备和解决方案的供应商之一,其SDK(软件开发工具包)提供了视频监控设备接口、流媒体接口等丰富的接口,使得设备厂商和软件开发者可以基于这些接口进行二次开发,实现更加专业化和个性化的应用。 如何通过Java语言来实现基于海康威视SDK的二次开发呢?首先我们需要在Java开发环境中添加海康威视SDK的jar包,然后根据SDK提供的接口进行编程。一般来说,SDK的使用大致可以分为以下几个步骤: 1. 初始化SDK环境:调用SDK提供的初始化接口完成SDK环境的初始化工作,包括设备搜索、连接、登录等工作。此外,还可以设置获取日志信息、设置报警回调等操作。 2. 获取设备信息:通过SDK提供的接口,可以获取监控设备的相关信息,包括设备类型、通道数、分辨率、帧率等,这些信息可以用于后续的开发工作。 3. 获取实时视频流:通过SDK提供的接口,可以获取监控设备传输的视频流数据,包括码流类型、码率、分辨率等,将视频数据解码后可以进行实时展示或者录制等操作。 4. 控制设备操作:通过SDK提供的接口,可以对监控设备进行各种控制操作,包括云台控制、预置点设置、图像参数调节等。 以上是基于海康威视SDK进行Java开发的一些常用操作,具体实现方式还需要根据不同的业务需求进行具体的编码工作。在实际开发过程中,我们还需要根据SDK提供的文档和示例代码进行参考和学习,以便更好地掌握SDK的使用技巧和开发经验。同时,我们还需要考虑安全、稳定性等因素,在保证功能实现的前提下,尽可能地减少软件系统的风险和漏洞。 ### 回答3: Java 是一种广泛使用的编程语言,在现代软件开发中非常流行。而海康威视是一家全球领先的视频监控解决方案提供商,其SDK具有一定的开放性和可定制性,可以用于二次开发。因此,Java 基于海康威视的SDK实现二次开发是可行的。 首先,使用Java开发需要具备基本的Java编程知识、IDE开发环境和海康威视SDK技术文档。开发者可以通过访问海康威视的开发者网站,获取SDK的开发包和相关说明文档,从而开始二次开发。 其次,海康威视SDK提供了丰富的接口和工具,便于Java开发者调用和使用。通过SDK中提供的API,我们可以实现视频监控的实时预览、录像回放、设备管理等功能。同时,SDK还提供了多种编程语言和操作系统的支持,使得Java程序可以在不同平台上进行开发和运行。 最后,Java开发者可以结合SDK提供的示例代码和测试工具,对开发的程序进行测试和调试,确保其功能和性能能够满足要求。同时,Java开发者还应该遵循海康威视SDK的开发规范,尽可能地避免出现错误和异常。 总之,Java基于海康威视SDK实现二次开发是一项有挑战性的任务,需要具备Java编程技能和视频监控领域的相关经验。但是,通过充分利用SDK的开放性和可定制性,开发者可以实现更加灵活和高效的视频监控解决方案,为客户提供更好的用户体验。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_58475035

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值