海康威视相机在QTcreate上的使用教程

news2024/12/23 14:34:04

文章目录

  • 前言:
  • 基础夯实:
  • 效果展示:
    • 图片展示:
    • 视频展示:
  • 参考的资料:
  • 遇到问题:
    • 问题1:int64 does not
    • 问题2:LNK2019
    • 配置思路(这个很重要)
    • 配置关键图片:
    • 配置具体过程:
  • 核心代码:
    • MvCamera.h
    • MvCamera.cpp
    • widget.cpp

前言:

海康威视的教程里面,关于C++的教程,编译环境是VS,所以想使用QTcreate对于海康威视的相机进行使用,包括查找设备,打开设备,关闭设备,开始采集,停止采集,软触发,触发一次,保存bmp,保存jpg,保存tiff,保存png,调节曝光,增益,帧率。

基础夯实:

在MVS中海康威视的相关教程:MVS链接
下载完成之后按照这个目录(我是下载的的D盘),可以找到VS的教程:D:\MVS\Development\Samples\VC\VS
如果你需要QT上的教程,请继续向下观看。

效果展示:

图片展示:

在这里插入图片描述

视频展示:

HKshow

参考的资料:

在这个过程中,我参考了很多的资料,包括VS里面的例程代码,但是我水平有限,不能直接搬运VS中的代码。
资料:参考资料1,参考资料2
简单对资料进行说明,介绍了环境的安装,包括opencv,sdk的头文件,库文件,二次封装的MvCamera.h和MvCamera.cpp文件。环境的安装是极其容易出错的过程,环境没问题,其他的才能正常的运行。

遇到问题:

问题1:int64 does not

在这里插入图片描述
这个是你mingw设置的opencv,但是你却用msvc打开了。这个编译环境必须一致。

问题2:LNK2019

在这里插入图片描述
你的opencv库没有连接好,路径问题或者camke问题,系统环境问题这都是有可能的。

配置思路(这个很重要)

首先你下载MVS之后,里面lib文件和头文件,头文件全要(参考配置图片),库文件只要一个(MvCameraControl.lib)。你需要把二次封装的函数导入你的QT下面里面,就是MvCamera.h和MvCamera.cpp这两个文件,如果你只进行导入也可以,因为你用到了opencv,不要纠结要不要使用opencv,直接用就行了,很方便,当时纠结了,想直接使用那两个文件,一直被卡。opencv按照教程按装就行了,按照mingw那个流程,在QT的pro文件中使用绝对路径,别使用相对路径(不使用导入库那个选项),因为我当时导入库就没成功。头文件直接包含,在直接的文件中导入一下,看一下有没有报错,没有保存说明导入成功。这里的MvCamera.cpp和MvCamera.h是不能直接使用的,需要在里面添加一些内容,直接使用也是会报错,原因就是你使用了opencv。最后,大佬使用的是导入.h文件,我需要ui文件,我就自己进行更改了,如果有需要ui文件的,评论区发qq邮箱,我源码或者ui可以私发你学习。基本上按照这个思路,成功搭建环境到运行应该是没有问题的。

配置关键图片:

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

配置具体过程:

海康威视相机在QTcreate上的环境配置教程(qt+opencv+海康SDK)

核心代码:

MvCamera.h

/************************************************************************/
/* 以C++接口为基础,对常用函数进行二次封装,方便用户使用                */
/************************************************************************/

#ifndef _MV_CAMERA_H_
#define _MV_CAMERA_H_

#include "MvCameraControl.h"
#include <string.h>

#include "opencv2/opencv.hpp"

//注意此处可能会跟系统函数定义冲突
using namespace cv;

#ifndef MV_NULL
#define MV_NULL    0
#endif

class CMvCamera
{
public:
    CMvCamera();
    ~CMvCamera();

    // ch:获取SDK版本号 | en:Get SDK Version
    static int GetSDKVersion();

    // ch:枚举设备 | en:Enumerate Device
    static int EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST* pstDevList);

    // ch:判断设备是否可达 | en:Is the device accessible
    static bool IsDeviceAccessible(MV_CC_DEVICE_INFO* pstDevInfo, unsigned int nAccessMode);

    // ch:打开设备 | en:Open Device
    int Open(MV_CC_DEVICE_INFO* pstDeviceInfo);

    // ch:关闭设备 | en:Close Device
    int Close();

    // ch:判断相机是否处于连接状态 | en:Is The Device Connected
    bool IsDeviceConnected();

    // 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:设置SDK内部图像缓存节点个数 | en:Set the number of the internal image cache nodes in SDK
    int SetImageNodeNum(unsigned int nNum);

    // ch:获取设备信息 | en:Get device information
    int GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo);

    // ch:获取GEV相机的统计信息 | en:Get detect info of GEV camera
    int GetGevAllMatchInfo(MV_MATCH_INFO_NET_DETECT* pMatchInfoNetDetect);

    // ch:获取U3V相机的统计信息 | en:Get detect info of U3V camera
    int GetU3VAllMatchInfo(MV_MATCH_INFO_USB_DETECT* pMatchInfoUSBDetect);

    // ch:获取和设置Int型参数,如 Width和Height,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
    // en:Get Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory
    int GetIntValue(IN const char* strKey, OUT MVCC_INTVALUE_EX *pIntValue);
    int SetIntValue(IN const char* strKey, IN int64_t nValue);

    // 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);
    int GetEnumEntrySymbolic(IN const char* strKey, IN MVCC_ENUMENTRY* pstEnumEntry);

    // 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);

    // ch:获取和设置String型参数,如 DeviceUserID,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件UserSetSave
    // en:Get String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory
    int GetStringValue(IN const char* strKey, MVCC_STRINGVALUE *pStringValue);
    int SetStringValue(IN const char* strKey, IN const char * strValue);

    // ch:执行一次Command型命令,如 UserSetSave,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
    // en:Execute Command once, such as UserSetSave, for details please refer to MvCameraNode.xlsx file under SDK installation directory
    int CommandExecute(IN const char* strKey);

    // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
    int GetOptimalPacketSize(unsigned int* pOptimalPacketSize);

    // ch:注册消息异常回调 | en:Register Message Exception CallBack
    int RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser), void* pUser);

    // ch:注册单个事件回调 | en:Register Event CallBack
    int RegisterEventCallBack(const char* pEventName, void(__stdcall* cbEvent)(MV_EVENT_OUT_INFO * pEventInfo, void* pUser), void* pUser);

    // ch:强制IP | en:Force IP
    int ForceIp(unsigned int nIP, unsigned int nSubNetMask, unsigned int nDefaultGateWay);

    // ch:配置IP方式 | en:IP configuration method
    int SetIpConfig(unsigned int nType);

    // ch:设置网络传输模式 | en:Set Net Transfer Mode
    int SetNetTransMode(unsigned int nType);

    // ch:像素格式转换 | en:Pixel format conversion
    int ConvertPixelType(MV_CC_PIXEL_CONVERT_PARAM* pstCvtParam);

    // ch:保存图片 | en:save image
    int SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam);

    // ch:保存图片为文件 | en:Save the image as a file
    int SaveImageToFile(MV_SAVE_IMG_TO_FILE_PARAM* pstParam);

    // ch:绘制圆形辅助线 | en:Draw circle auxiliary line
    int DrawCircle(MVCC_CIRCLE_INFO* pCircleInfo);

    // ch:绘制线形辅助线 | en:Draw lines auxiliary line
    int DrawLines(MVCC_LINES_INFO* pLinesInfo);

    //读取buffer
    int ReadBuffer(Mat &image);

private:

    void *m_hDevHandle;

    //用于保存图像的缓存
    unsigned int m_nBufSizeForSaveImage;

};

#endif//_MV_CAMERA_H_

MvCamera.cpp

#include "mvcamera.h"

CMvCamera::CMvCamera()
{
    m_hDevHandle = MV_NULL;
}

CMvCamera::~CMvCamera()
{
    if (m_hDevHandle)
    {
        MV_CC_DestroyHandle(m_hDevHandle);
        m_hDevHandle = MV_NULL;
    }
}

// ch:获取SDK版本号 | en:Get SDK Version
int CMvCamera::GetSDKVersion()
{
    return MV_CC_GetSDKVersion();
}

// ch:枚举设备 | en:Enumerate Device
int CMvCamera::EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST* pstDevList)
{
    return MV_CC_EnumDevices(nTLayerType, pstDevList);
}

// ch:判断设备是否可达 | en:Is the device accessible
bool CMvCamera::IsDeviceAccessible(MV_CC_DEVICE_INFO* pstDevInfo, unsigned int nAccessMode)
{
    return MV_CC_IsDeviceAccessible(pstDevInfo, nAccessMode);
}

// ch:打开设备 | en:Open Device
int CMvCamera::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;
}

// ch:关闭设备 | en:Close Device
int CMvCamera::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;
}

// ch:判断相机是否处于连接状态 | en:Is The Device Connected
bool CMvCamera::IsDeviceConnected()
{
    return MV_CC_IsDeviceConnected(m_hDevHandle);
}

// ch:注册图像数据回调 | en:Register Image Data CallBack
int CMvCamera::RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), void* pUser)
{
    return MV_CC_RegisterImageCallBackEx(m_hDevHandle, cbOutput, pUser);
}

// ch:开启抓图 | en:Start Grabbing
int CMvCamera::StartGrabbing()
{
    return MV_CC_StartGrabbing(m_hDevHandle);
}

// ch:停止抓图 | en:Stop Grabbing
int CMvCamera::StopGrabbing()
{
    return MV_CC_StopGrabbing(m_hDevHandle);
}

// ch:主动获取一帧图像数据 | en:Get one frame initiatively
int CMvCamera::GetImageBuffer(MV_FRAME_OUT* pFrame, int nMsec)
{
    return MV_CC_GetImageBuffer(m_hDevHandle, pFrame, nMsec);
}

// ch:释放图像缓存 | en:Free image buffer
int CMvCamera::FreeImageBuffer(MV_FRAME_OUT* pFrame)
{
    return MV_CC_FreeImageBuffer(m_hDevHandle, pFrame);
}

// ch:设置显示窗口句柄 | en:Set Display Window Handle
int CMvCamera::DisplayOneFrame(MV_DISPLAY_FRAME_INFO* pDisplayInfo)
{
    return MV_CC_DisplayOneFrame(m_hDevHandle, pDisplayInfo);
}

// ch:设置SDK内部图像缓存节点个数 | en:Set the number of the internal image cache nodes in SDK
int CMvCamera::SetImageNodeNum(unsigned int nNum)
{
    return MV_CC_SetImageNodeNum(m_hDevHandle, nNum);
}

// ch:获取设备信息 | en:Get device information
int CMvCamera::GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo)
{
    return MV_CC_GetDeviceInfo(m_hDevHandle, pstDevInfo);
}

// ch:获取GEV相机的统计信息 | en:Get detect info of GEV camera
int CMvCamera::GetGevAllMatchInfo(MV_MATCH_INFO_NET_DETECT* pMatchInfoNetDetect)
{
    if (MV_NULL == pMatchInfoNetDetect)
    {
        return MV_E_PARAMETER;
    }

    MV_CC_DEVICE_INFO stDevInfo = {0};
    GetDeviceInfo(&stDevInfo);
    if (stDevInfo.nTLayerType != MV_GIGE_DEVICE)
    {
        return MV_E_SUPPORT;
    }

    MV_ALL_MATCH_INFO struMatchInfo = {0};

    struMatchInfo.nType = MV_MATCH_TYPE_NET_DETECT;
    struMatchInfo.pInfo = pMatchInfoNetDetect;
    struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_NET_DETECT);
    memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_NET_DETECT));

    return MV_CC_GetAllMatchInfo(m_hDevHandle, &struMatchInfo);
}

// ch:获取U3V相机的统计信息 | en:Get detect info of U3V camera
int CMvCamera::GetU3VAllMatchInfo(MV_MATCH_INFO_USB_DETECT* pMatchInfoUSBDetect)
{
    if (MV_NULL == pMatchInfoUSBDetect)
    {
        return MV_E_PARAMETER;
    }

    MV_CC_DEVICE_INFO stDevInfo = {0};
    GetDeviceInfo(&stDevInfo);
    if (stDevInfo.nTLayerType != MV_USB_DEVICE)
    {
        return MV_E_SUPPORT;
    }

    MV_ALL_MATCH_INFO struMatchInfo = {0};

    struMatchInfo.nType = MV_MATCH_TYPE_USB_DETECT;
    struMatchInfo.pInfo = pMatchInfoUSBDetect;
    struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_USB_DETECT);
    memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_USB_DETECT));

    return MV_CC_GetAllMatchInfo(m_hDevHandle, &struMatchInfo);
}

// ch:获取和设置Int型参数,如 Width和Height,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Get Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int CMvCamera::GetIntValue(IN const char* strKey, OUT MVCC_INTVALUE_EX *pIntValue)
{
    return MV_CC_GetIntValueEx(m_hDevHandle, strKey, pIntValue);
}

int CMvCamera::SetIntValue(IN const char* strKey, IN int64_t nValue)
{
    return MV_CC_SetIntValueEx(m_hDevHandle, strKey, nValue);
}

// 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 CMvCamera::GetEnumValue(IN const char* strKey, OUT MVCC_ENUMVALUE *pEnumValue)
{
    return MV_CC_GetEnumValue(m_hDevHandle, strKey, pEnumValue);
}

int CMvCamera::SetEnumValue(IN const char* strKey, IN unsigned int nValue)
{
    return MV_CC_SetEnumValue(m_hDevHandle, strKey, nValue);
}

int CMvCamera::SetEnumValueByString(IN const char* strKey, IN const char* sValue)
{
    return MV_CC_SetEnumValueByString(m_hDevHandle, strKey, sValue);
}

int CMvCamera::GetEnumEntrySymbolic(IN const char* strKey, IN MVCC_ENUMENTRY* pstEnumEntry)
{
    return MV_CC_GetEnumEntrySymbolic(m_hDevHandle, strKey, pstEnumEntry);
}

// 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 CMvCamera::GetFloatValue(IN const char* strKey, OUT MVCC_FLOATVALUE *pFloatValue)
{
    return MV_CC_GetFloatValue(m_hDevHandle, strKey, pFloatValue);
}

int CMvCamera::SetFloatValue(IN const char* strKey, IN float fValue)
{
    return MV_CC_SetFloatValue(m_hDevHandle, strKey, 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 CMvCamera::GetBoolValue(IN const char* strKey, OUT bool *pbValue)
{
    return MV_CC_GetBoolValue(m_hDevHandle, strKey, pbValue);
}

int CMvCamera::SetBoolValue(IN const char* strKey, IN bool bValue)
{
    return MV_CC_SetBoolValue(m_hDevHandle, strKey, bValue);
}

// ch:获取和设置String型参数,如 DeviceUserID,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件UserSetSave
// en:Get String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int CMvCamera::GetStringValue(IN const char* strKey, MVCC_STRINGVALUE *pStringValue)
{
    return MV_CC_GetStringValue(m_hDevHandle, strKey, pStringValue);
}

int CMvCamera::SetStringValue(IN const char* strKey, IN const char* strValue)
{
    return MV_CC_SetStringValue(m_hDevHandle, strKey, strValue);
}

// ch:执行一次Command型命令,如 UserSetSave,详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Execute Command once, such as UserSetSave, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int CMvCamera::CommandExecute(IN const char* strKey)
{
    return MV_CC_SetCommandValue(m_hDevHandle, strKey);
}

// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
int CMvCamera::GetOptimalPacketSize(unsigned int* pOptimalPacketSize)
{
    if (MV_NULL == pOptimalPacketSize)
    {
        return MV_E_PARAMETER;
    }

    int nRet = MV_CC_GetOptimalPacketSize(m_hDevHandle);
    if (nRet < MV_OK)
    {
        return nRet;
    }

    *pOptimalPacketSize = (unsigned int)nRet;

    return MV_OK;
}

// ch:注册消息异常回调 | en:Register Message Exception CallBack
int CMvCamera::RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser),void* pUser)
{
    return MV_CC_RegisterExceptionCallBack(m_hDevHandle, cbException, pUser);
}

// ch:注册单个事件回调 | en:Register Event CallBack
int CMvCamera::RegisterEventCallBack(const char* pEventName, void(__stdcall* cbEvent)(MV_EVENT_OUT_INFO * pEventInfo, void* pUser), void* pUser)
{
    return MV_CC_RegisterEventCallBackEx(m_hDevHandle, pEventName, cbEvent, pUser);
}

// ch:强制IP | en:Force IP
int CMvCamera::ForceIp(unsigned int nIP, unsigned int nSubNetMask, unsigned int nDefaultGateWay)
{
    return MV_GIGE_ForceIpEx(m_hDevHandle, nIP, nSubNetMask, nDefaultGateWay);
}

// ch:配置IP方式 | en:IP configuration method
int CMvCamera::SetIpConfig(unsigned int nType)
{
    return MV_GIGE_SetIpConfig(m_hDevHandle, nType);
}

// ch:设置网络传输模式 | en:Set Net Transfer Mode
int CMvCamera::SetNetTransMode(unsigned int nType)
{
    return MV_GIGE_SetNetTransMode(m_hDevHandle, nType);
}

// ch:像素格式转换 | en:Pixel format conversion
int CMvCamera::ConvertPixelType(MV_CC_PIXEL_CONVERT_PARAM* pstCvtParam)
{
    return MV_CC_ConvertPixelType(m_hDevHandle, pstCvtParam);
}

// ch:保存图片 | en:save image
int CMvCamera::SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam)
{
    return MV_CC_SaveImageEx2(m_hDevHandle, pstParam);
}

// ch:保存图片为文件 | en:Save the image as a file
int CMvCamera::SaveImageToFile(MV_SAVE_IMG_TO_FILE_PARAM* pstSaveFileParam)
{
    return MV_CC_SaveImageToFile(m_hDevHandle, pstSaveFileParam);
}

// ch:绘制圆形辅助线 | en:Draw circle auxiliary line
int CMvCamera::DrawCircle(MVCC_CIRCLE_INFO* pCircleInfo)
{
    return MV_CC_DrawCircle(m_hDevHandle, pCircleInfo);
}

// ch:绘制线形辅助线 | en:Draw lines auxiliary line
int CMvCamera::DrawLines(MVCC_LINES_INFO* pLinesInfo)
{
    return MV_CC_DrawLines(m_hDevHandle, pLinesInfo);
}

//读取相机中的图像
int CMvCamera::ReadBuffer(Mat &image)
{
    Mat* getImage = new Mat();
    unsigned int nRecvBufSize = 0;
    MVCC_INTVALUE stParam;
    memset(&stParam, 0, sizeof(MVCC_INTVALUE));
    int tempValue = MV_CC_GetIntValue(m_hDevHandle, "PayloadSize", &stParam);
    if (tempValue != 0)
    {
        return -1;
    }
    nRecvBufSize = stParam.nCurValue;
    unsigned char* pDate;
    pDate=(unsigned char *)malloc(nRecvBufSize);

    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    tempValue= MV_CC_GetOneFrameTimeout(m_hDevHandle, pDate, nRecvBufSize, &stImageInfo, 700);
    if(tempValue!=0)
    {
        return -1;
    }
    m_nBufSizeForSaveImage = stImageInfo.nWidth * stImageInfo.nHeight * 3 + 2048;
    unsigned char* m_pBufForSaveImage;
    m_pBufForSaveImage = (unsigned char*)malloc(m_nBufSizeForSaveImage);


    bool isMono;
    switch (stImageInfo.enPixelType)
    {
    case PixelType_Gvsp_Mono8:
    case PixelType_Gvsp_Mono10:
    case PixelType_Gvsp_Mono10_Packed:
    case PixelType_Gvsp_Mono12:
    case PixelType_Gvsp_Mono12_Packed:
        isMono=true;
        break;
    default:
        isMono=false;
        break;
    }
    if(isMono)
    {
        *getImage = Mat(stImageInfo.nHeight,stImageInfo.nWidth,CV_8UC1,pDate);
        //imwrite("d:\\测试opencv_Mono.tif", image);
    }
    else
    {
        //转换图像格式为BGR8
        MV_CC_PIXEL_CONVERT_PARAM stConvertParam = {0};
        memset(&stConvertParam, 0, sizeof(MV_CC_PIXEL_CONVERT_PARAM));
        stConvertParam.nWidth = stImageInfo.nWidth;                 //ch:图像宽 | en:image width
        stConvertParam.nHeight = stImageInfo.nHeight;               //ch:图像高 | en:image height
        //stConvertParam.pSrcData = m_pBufForDriver;                  //ch:输入数据缓存 | en:input data buffer
        stConvertParam.pSrcData = pDate;                  //ch:输入数据缓存 | en:input data buffer
        stConvertParam.nSrcDataLen = stImageInfo.nFrameLen;         //ch:输入数据大小 | en:input data size
        stConvertParam.enSrcPixelType = stImageInfo.enPixelType;    //ch:输入像素格式 | en:input pixel format
        stConvertParam.enDstPixelType = PixelType_Gvsp_BGR8_Packed; //ch:输出像素格式 | en:output pixel format  适用于OPENCV的图像格式
        //stConvertParam.enDstPixelType = PixelType_Gvsp_RGB8_Packed; //ch:输出像素格式 | en:output pixel format
        stConvertParam.pDstBuffer = m_pBufForSaveImage;                    //ch:输出数据缓存 | en:output data buffer
        stConvertParam.nDstBufferSize = m_nBufSizeForSaveImage;            //ch:输出缓存大小 | en:output buffer size
        MV_CC_ConvertPixelType(m_hDevHandle, &stConvertParam);

        *getImage = Mat(stImageInfo.nHeight,stImageInfo.nWidth,CV_8UC3,m_pBufForSaveImage);
        //imwrite("d:\\测试opencv_Color.tif", image);
    }
    (*getImage).copyTo(image);
    (*getImage).release();
    free(pDate);
    free(m_pBufForSaveImage);
    return 0;
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include<QMessageBox>
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    ,m_bOpenDevice(false)
    ,m_nDeviceCombo(0)
    ,m_nTriggerMode(MV_TRIGGER_MODE_OFF)
    ,m_bStartGrabbing(false)
    ,m_pcMyCamera(NULL)
    ,m_pSaveImageBuf(NULL)
    ,m_nSaveImageBufSize(0)
    ,m_bSoftWareTriggerCheck(false)
    , m_nTriggerSource(MV_TRIGGER_SOURCE_SOFTWARE)
    ,m_dExposureEdit(0)
    ,m_dGainEdit(0)
    ,m_dFrameRateEdit(0)
    ,m_isDeviceReady(false)
{
    m_WorkThread=new WorkThread(*this);
    ui->setupUi(this);
    setWindowTitle("海康相机");
    InitUi();
    connect(ui->searchDeviceBtn   ,SIGNAL(clicked()),this,SLOT(slot_searchDevice()));
    connect(ui->openDeviceBtn     ,SIGNAL(clicked()),this,SLOT(slot_openDevice()));
    connect(ui->closeDeviceBtn    ,SIGNAL(clicked()),this,SLOT(slot_closeDevice()));
    connect(ui->continusModeBtn   ,SIGNAL(clicked()),this,SLOT(slot_continusModeBtn()));
    connect(ui->triggerModeBtn    ,SIGNAL(clicked()),this,SLOT(slot_triggerModeBtn()));
    connect(ui->startGrabBtn      ,SIGNAL(clicked()),this,SLOT(slot_grabbingBtn()));

    connect(ui->softwareTriggerBtn,SIGNAL(stateChanged(int)),this,SLOT(slot_softwareTriggerBtn()));

    connect(ui->softwareOnceBtn   ,SIGNAL(clicked()),this,SLOT(slot_softwareoOnceBtn()));
    connect(ui->saveBmpBtn        ,SIGNAL(clicked()),this,SLOT(slot_saveBmpBtn()));
    connect(ui->saveJpgBtn        ,SIGNAL(clicked()),this,SLOT(slot_saveJpgBtn()));
    connect(ui->saveTiffBtn       ,SIGNAL(clicked()),this,SLOT(slot_saveTiffBtn()));
    connect(ui->savePngBtn        ,SIGNAL(clicked()),this,SLOT(slot_savePngBtn()));
    connect(ui->GetParamterBtn    ,SIGNAL(clicked()),this,SLOT(slot_getParameterBtn()));
    connect(ui->SetParameterBtn   ,SIGNAL(clicked()),this,SLOT(slot_setParameterBtn()));
    connect(ui->stopGrabBtn       ,SIGNAL(clicked()),this,SLOT(slot_stopGrbbingBtn()));
}

void Widget::slot_setParameterBtn()
{
    bool bIsSetSucceed = true;
    int nRet = SetExposureTime();
    if (nRet != MV_OK)
    {
        bIsSetSucceed = false;
        QMessageBox::critical(this,"Exposure","Set Exposure Time Fail");
    }
    nRet = SetGain();
    if (nRet != MV_OK)
    {
        bIsSetSucceed = false;
        QMessageBox::critical(this,"Gain","Set Gain Fail");
    }
    nRet = SetFrameRate();
    if (nRet != MV_OK)
    {
        bIsSetSucceed = false;
        QMessageBox::critical(this,"Frame","Set Frame Rate Fail");
    }

    if (true == bIsSetSucceed)
    {
        QMessageBox::critical(this,"Parameter","Set Parameter Succeed");
    }
}

void Widget::slot_stopGrbbingBtn()
{
    if (false == m_bOpenDevice || false == m_bStartGrabbing || NULL == m_pcMyCamera)
    {
        return;
    }
    m_WorkThread->SetRun(false);
    bool f=m_WorkThread->isRun();
    if(f)
    {
        m_WorkThread->quit();
        m_WorkThread->wait();
        m_WorkThread=NULL;
    }
    int nRet = m_pcMyCamera->StopGrabbing();
    if(MV_OK != nRet)
    {
        QMessageBox::critical(this,"grabbing","Stop grabbing fail");
        return;
    }
    m_bStartGrabbing = false;
}

int Widget::SetTriggerSource()
{
    int nRet = MV_OK;
    m_bSoftWareTriggerCheck=ui->softwareTriggerBtn->isChecked();
    if (m_bSoftWareTriggerCheck)
    {
        m_nTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE;
        nRet = m_pcMyCamera->SetEnumValue("TriggerSource", m_nTriggerSource);
        if (MV_OK != nRet)
        {
            QMessageBox::critical(this,"Trigger","Set Software Trigger Fail");
            return nRet;
        }
        // GetDlgItem(IDC_SOFTWARE_ONCE_BUTTON )->EnableWindow(TRUE);
    }
    else
    {
        m_nTriggerSource = MV_TRIGGER_SOURCE_LINE0;
        nRet = m_pcMyCamera->SetEnumValue("TriggerSource", m_nTriggerSource);
        if (MV_OK != nRet)
        {
            QMessageBox::critical(this,"Hardware","Set Hardware Trigger Fail");
            return nRet;
        }
        //GetDlgItem(IDC_SOFTWARE_ONCE_BUTTON )->EnableWindow(FALSE);
    }
    return nRet;
}

int Widget::SetFrameRate()
{
    int nRet = m_pcMyCamera->SetBoolValue("AcquisitionFrameRateEnable", true);
    if (MV_OK != nRet)
    {
        return nRet;
    }

    bool ok;
    float frameRate = ui->FrameRateLineEdit->text().toDouble(&ok);
    if (!ok) {
        // 处理转换失败的情况,可能需要返回错误代码或显示错误消息
        return -1; // 示例错误代码
    }

    return m_pcMyCamera->SetFloatValue("AcquisitionFrameRate", (float)frameRate);
}

int Widget::SetGain()
{
    // 先尝试关闭自动增益
    m_pcMyCamera->SetEnumValue("GainAuto", 0);

    bool ok;
    float gain = ui->GainLineEdit->text().toDouble(&ok);
    if (!ok) {
        // 处理转换失败的情况
        return -1; // 示例错误代码
    }

    return m_pcMyCamera->SetFloatValue("Gain", (float)gain);
}

int Widget::SetExposureTime()
{
    int nRet = m_pcMyCamera->SetEnumValue("ExposureMode", MV_EXPOSURE_MODE_TIMED);
    if (MV_OK != nRet)
    {
        return nRet;
    }

    // 关闭自动曝光
    m_pcMyCamera->SetEnumValue("ExposureAuto", MV_EXPOSURE_AUTO_MODE_OFF);

    bool ok;
    float exposureTime = ui->ExposureLineEdit->text().toDouble(&ok);
    if (!ok) {
        // 处理转换失败的情况
        return -1; // 示例错误代码
    }

    return m_pcMyCamera->SetFloatValue("ExposureTime", (float)exposureTime);
}

int Widget::SetTriggerMode()
{
    return m_pcMyCamera->SetEnumValue("TriggerMode", m_nTriggerMode);
}

void Widget::slot_getParameterBtn()
{
    int nRet = GetTriggerMode();
    if (nRet != MV_OK)
    {
        QMessageBox::critical(this,"Mode","Get Trigger Mode Fail");
    }
    nRet = GetExposureTime();
    if (nRet != MV_OK)
    {
        QMessageBox::critical(this,"Mode","Get Exposure Time Fail");
    }
    ui->ExposureLineEdit->setText(QString("%1").arg(m_dExposureEdit));
    nRet = GetGain();
    if (nRet != MV_OK)
    {
        QMessageBox::critical(this,"Gain","Get Gain Fail");
    }
    ui->GainLineEdit->setText(QString("%1").arg(m_dGainEdit));
    nRet = GetFrameRate();
    if (nRet != MV_OK)
    {
        QMessageBox::critical(this,"Frame","Get Frame Rate Fail");
    }
    ui->FrameRateLineEdit->setText(QString("%1").arg(m_dFrameRateEdit));
    nRet = GetTriggerSource();
    if (nRet != MV_OK)
    {
        QMessageBox::critical(this,"Trigger","Get Trigger Source Fail");
    }

}

int Widget::GetTriggerSource()
{
    MVCC_ENUMVALUE stEnumValue = {0};

    int nRet = m_pcMyCamera->GetEnumValue("TriggerSource", &stEnumValue);
    if (MV_OK != nRet)
    {
        return nRet;
    }

    if ((unsigned int)MV_TRIGGER_SOURCE_SOFTWARE == stEnumValue.nCurValue)
    {
        m_bSoftWareTriggerCheck = true;
    }
    else
    {
        m_bSoftWareTriggerCheck = false;
    }

    return MV_OK;
}

int Widget::GetGain()
{
    MVCC_FLOATVALUE stFloatValue = {0};

    int nRet = m_pcMyCamera->GetFloatValue("Gain", &stFloatValue);
    if (MV_OK != nRet)
    {
        return nRet;
    }
    m_dGainEdit = stFloatValue.fCurValue;

    return MV_OK;
}

int Widget::GetFrameRate()
{
    MVCC_FLOATVALUE stFloatValue = {0};

    int nRet = m_pcMyCamera->GetFloatValue("ResultingFrameRate", &stFloatValue);
    if (MV_OK != nRet)
    {
        return nRet;
    }
    m_dFrameRateEdit = stFloatValue.fCurValue;

    return MV_OK;
}

int Widget::GetTriggerMode()
{
    MVCC_ENUMVALUE stEnumValue = {0};
    int nRet = m_pcMyCamera->GetEnumValue("TriggerMode", &stEnumValue);
    if(MV_OK != nRet)
    {
        return nRet;
    }
    m_nTriggerMode = stEnumValue.nCurValue;
    EnableControls();
    return MV_OK;
}

int Widget::GetExposureTime()
{
    MVCC_FLOATVALUE stFloatValue = {0};

    int nRet = m_pcMyCamera->GetFloatValue("ExposureTime", &stFloatValue);
    if(MV_OK != nRet)
    {
        return nRet;
    }
    m_dExposureEdit = stFloatValue.fCurValue;
    return MV_OK;
}

void Widget::slot_savePngBtn()
{
    int nRet = SaveImage(MV_Image_Png);
    if (MV_OK != nRet)
    {
        QMessageBox::critical(this,"picture","Save Png fail");
        return;
    }
    QMessageBox::critical(this,"picture","Save Png succeed!");
}

void Widget::slot_saveTiffBtn()
{
    int nRet = SaveImage(MV_Image_Tif);
    if (MV_OK != nRet)
    {
        QMessageBox::critical(this,"picture","Save jpg fail");
        return;
    }
    QMessageBox::critical(this,"picture","Save jpg succeed!");
}

void Widget::slot_saveJpgBtn()
{
    int nRet = SaveImage(MV_Image_Jpeg);
    if (MV_OK != nRet)
    {
        QMessageBox::critical(this,"picture","Save jpg fail");
        return;
    }
    QMessageBox::critical(this,"picture","Save jpg succeed!");
}

int Widget::SaveImage(MV_SAVE_IAMGE_TYPE enSaveImageType)
{
    MV_SAVE_IMG_TO_FILE_PARAM stSaveFileParam;
    memset(&stSaveFileParam, 0, sizeof(MV_SAVE_IMG_TO_FILE_PARAM));
    m_mutex.lock();
    if (m_pSaveImageBuf == NULL || m_stImageInfo.enPixelType == 0)
    {
        m_mutex.unlock();
        return MV_E_NODATA;
    }

    if(RemoveCustomPixelFormats(m_stImageInfo.enPixelType))
    {
        m_mutex.unlock();
        return MV_E_SUPPORT;
    }
    stSaveFileParam.enImageType = enSaveImageType;              // ch:需要保存的图像类型 | en:Image format to save
    stSaveFileParam.enPixelType = m_stImageInfo.enPixelType;    // ch:相机对应的像素格式 | en:Camera pixel type
    stSaveFileParam.nWidth      = m_stImageInfo.nWidth;         // ch:相机对应的宽 | en:Width
    stSaveFileParam.nHeight     = m_stImageInfo.nHeight;        // ch:相机对应的高 | en:Height
    stSaveFileParam.nDataLen    = m_stImageInfo.nFrameLen;
    stSaveFileParam.pData       = m_pSaveImageBuf;
    stSaveFileParam.iMethodValue = 0;

    // ch:jpg图像质量范围为(50-99], png图像质量范围为[0-9] | en:jpg image nQuality range is (50-99], png image nQuality range is [0-9]
    if (MV_Image_Bmp == stSaveFileParam.enImageType)
    {
        sprintf_s(stSaveFileParam.pImagePath, 256, "Image_w%d_h%d_fn%03d.bmp", stSaveFileParam.nWidth, stSaveFileParam.nHeight, m_stImageInfo.nFrameNum);
    }
    else if (MV_Image_Jpeg == stSaveFileParam.enImageType)
    {
        stSaveFileParam.nQuality = 80;
        sprintf_s(stSaveFileParam.pImagePath, 256, "Image_w%d_h%d_fn%03d.jpg", stSaveFileParam.nWidth, stSaveFileParam.nHeight, m_stImageInfo.nFrameNum);
    }
    else if (MV_Image_Tif == stSaveFileParam.enImageType)
    {
        sprintf_s(stSaveFileParam.pImagePath, 256, "Image_w%d_h%d_fn%03d.tif", stSaveFileParam.nWidth, stSaveFileParam.nHeight, m_stImageInfo.nFrameNum);
    }
    else if (MV_Image_Png == stSaveFileParam.enImageType)
    {
        stSaveFileParam.nQuality = 8;
        sprintf_s(stSaveFileParam.pImagePath, 256, "Image_w%d_h%d_fn%03d.png", stSaveFileParam.nWidth, stSaveFileParam.nHeight, m_stImageInfo.nFrameNum);
    }
    int nRet = m_pcMyCamera->SaveImageToFile(&stSaveFileParam);
    m_mutex.unlock();
    return nRet;
}

void Widget::slot_saveBmpBtn()
{
    int nRet = SaveImage(MV_Image_Bmp);
    if (MV_OK != nRet)
    {
        QMessageBox::critical(this,"picture","Save bmp fail");
        return;
    }
    QMessageBox::critical(this,"picture","Save bmp succeed!");
}

void Widget::slot_closeDevice()
{
    bool f=m_WorkThread->isRun();
    if (f)
    {
        m_WorkThread->quit();
        m_WorkThread->wait();
        m_WorkThread->SetRun(false);
    }

    if(m_pcMyCamera)
    {
        m_pcMyCamera->Close();
        delete m_pcMyCamera;
        m_pcMyCamera = NULL;
    }
    m_bStartGrabbing=false;
    m_bOpenDevice = false;
    if(m_pSaveImageBuf)
    {
        free(m_pSaveImageBuf);
        m_pSaveImageBuf=NULL;
    }
    m_nSaveImageBufSize=0;
    EnableControls();
}

void Widget::slot_continusModeBtn()
{
    m_nTriggerMode = MV_TRIGGER_MODE_OFF;
    m_pcMyCamera->SetEnumValue("TriggerMode", m_nTriggerMode);
    EnableControls();
}

void Widget::slot_triggerModeBtn()
{
    m_nTriggerMode = MV_TRIGGER_MODE_ON;
    m_pcMyCamera->SetEnumValue("TriggerMode", m_nTriggerMode);
    EnableControls();
}

void Widget::slot_grabbingBtn()
{
    if (false == m_bOpenDevice || true == m_bStartGrabbing || NULL == m_pcMyCamera)
    {
        return;
    }
    memset(&m_stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    m_WorkThread->SetRun(true);
    m_WorkThread->start();

    int nRet = m_pcMyCamera->StartGrabbing();
    if (MV_OK != nRet)
    {
        m_WorkThread->SetRun(false);
        QMessageBox::information(this,"Device","Start grabbing fail");
        return;
    }
    m_bStartGrabbing = true;
    EnableControls();
}

void Widget::slot_softwareTriggerBtn()
{
    int nRet = MV_OK;
    m_bSoftWareTriggerCheck=ui->softwareTriggerBtn->isChecked();
    if (m_bSoftWareTriggerCheck)
    {
        m_nTriggerSource = MV_TRIGGER_SOURCE_SOFTWARE;
        nRet = m_pcMyCamera->SetEnumValue("TriggerSource", m_nTriggerSource);
        if (MV_OK != nRet)
        {
            QMessageBox::information(this,"Device","Set Software Trigger Fail");
            return;
        }
    }
    else
    {
        m_nTriggerSource = MV_TRIGGER_SOURCE_LINE0;
        nRet = m_pcMyCamera->SetEnumValue("TriggerSource", m_nTriggerSource);
        if (MV_OK != nRet)
        {
            QMessageBox::information(this,"Device","Set Hardware Trigger Fail");
            return;
        }
    }
    EnableControls();
    return;
}

void Widget::slot_softwareoOnceBtn()
{
    if(true != m_bStartGrabbing)
    {
        return;
    }
    m_pcMyCamera->CommandExecute("TriggerSoftware");
}

void Widget::InitUi()
{
    memset(&m_stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    m_WorkThread->SetRun(false);
    EnableControls();
}

void  Widget::EnableControls()
{
    //如果查询到设备,开启打开设备按钮
    ui->openDeviceBtn->setEnabled(m_isDeviceReady?true:false);
    ui->closeDeviceBtn->setEnabled(m_bOpenDevice?true:false);
    ui->continusModeBtn->setEnabled(m_bOpenDevice?true:false);
    ui->triggerModeBtn->setEnabled(m_bOpenDevice?true:false);
    ui->startGrabBtn->setEnabled(m_bOpenDevice?true:false);
    ui->stopGrabBtn->setEnabled(m_bOpenDevice?true:false);

    //首先是否是在采集图像中,在采集图像的过程中,判断是否为触发模式,只有在触发模式下,才能开启软触发按钮。
    ui->softwareTriggerBtn->setEnabled(m_bStartGrabbing?((MV_TRIGGER_MODE_ON ==  m_nTriggerMode)?true:false):false);
    ui->softwareOnceBtn->setEnabled(
        (MV_TRIGGER_MODE_OFF ==  m_nTriggerMode) ? false:
            (m_bSoftWareTriggerCheck?true:false) );
    ui->saveBmpBtn->setEnabled(m_bStartGrabbing?true:false);
    ui->saveJpgBtn->setEnabled(m_bStartGrabbing?true:false);
    ui->saveTiffBtn->setEnabled(m_bStartGrabbing?true:false);
    ui->savePngBtn->setEnabled(m_bStartGrabbing?true:false);
    ui->GetParamterBtn->setEnabled(m_bOpenDevice?true:false);
    ui->SetParameterBtn  ->setEnabled(m_bOpenDevice?true:false);
    ui->ExposureLineEdit->setEnabled(m_bOpenDevice?true:false);
    ui->GainLineEdit->setEnabled(m_bOpenDevice?true:false);
    ui->FrameRateLineEdit->setEnabled(m_bOpenDevice?true:false);
}

bool Widget::RemoveCustomPixelFormats(MvGvspPixelType enPixelFormat)
{
    int nResult = enPixelFormat & MV_GVSP_PIX_CUSTOM;
    if(MV_GVSP_PIX_CUSTOM == nResult)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void Widget::slot_openDevice()
{
    if (true == m_bOpenDevice || NULL != m_pcMyCamera)
    {
        return;
    }
    int nIndex = m_nDeviceCombo;
    if ((nIndex < 0) | (nIndex >= MV_MAX_DEVICE_NUM))
    {
        QMessageBox::critical(this,"Device","Device index is error!");
        return;
    }
    // ch:由设备信息创建设备实例 | en:Device instance created by device information
    if (NULL == m_stDevList.pDeviceInfo[nIndex])
    {
        QMessageBox::critical(this,"Device","Device does not exist!");
        return;
    }
    m_pcMyCamera = new CMvCamera;
    if (NULL == m_pcMyCamera)
    {
        return;
    }
    int nRet = m_pcMyCamera->Open(m_stDevList.pDeviceInfo[nIndex]);
    if (MV_OK != nRet)
    {
        delete m_pcMyCamera;
        m_pcMyCamera = NULL;
        QMessageBox::critical(this,"Device","Device Open error!");
        return;
    }
    // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
    if (m_stDevList.pDeviceInfo[nIndex]->nTLayerType == MV_GIGE_DEVICE)
    {
        unsigned int nPacketSize = 0;
        nRet = m_pcMyCamera->GetOptimalPacketSize(&nPacketSize);
        if (nRet == MV_OK)
        {
            nRet = m_pcMyCamera->SetIntValue("GevSCPSPacketSize",nPacketSize);
            if(nRet != MV_OK)
            {
                QMessageBox::critical(this,"Device","Warning: Set Packet Size fail!");
            }
        }
        else
        {
            QMessageBox::critical(this,"Device","Warning: Get Packet Size fail!");
        }
    }
    m_bOpenDevice = true;
    EnableControls();
    slot_getParameterBtn();
}

void Widget::slot_searchDevice()
{
    QString strMsg;
    ui->comboBox->clear();
    memset(&m_stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    //ch:枚举子网内所有设备,将查询到的设备信息保存到m_stDevList列表中。
    int nRet   = CMvCamera::EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &m_stDevList);
    if (MV_OK != nRet)
    {
        QMessageBox::critical(this,"device","No device!");
        return;
    }

    // ch:将值加入到信息列表框中并显示出来 | en:Add value to the information list box and display
    for (unsigned int i = 0; i < m_stDevList.nDeviceNum; i++)
    {
        MV_CC_DEVICE_INFO* pDeviceInfo = m_stDevList.pDeviceInfo[i];
        if (NULL == pDeviceInfo)
        {
            continue;
        }

        if (pDeviceInfo->nTLayerType == MV_USB_DEVICE)
        {

            char strUserName[256] = {0};
            sprintf_s(strUserName, 256, "%s %s (%s)", pDeviceInfo->SpecialInfo.stUsb3VInfo.chModelName,
                      pDeviceInfo->SpecialInfo.stUsb3VInfo.chModelName,
                      pDeviceInfo->SpecialInfo.stUsb3VInfo.chSerialNumber);

            QString  UserName(strUserName);

            QString strMsg = QString("USB %1").arg(QString::fromUtf8(reinterpret_cast<const char*>(pDeviceInfo->SpecialInfo.stUsb3VInfo.chSerialNumber)));
            ui->comboBox->addItem(strMsg);
        }
    }

    if (0 == m_stDevList.nDeviceNum)
    {

        QMessageBox::critical(this,"device","No device!");
        return;
    }
    ui->comboBox->setCurrentIndex(0);
    m_isDeviceReady=true;                                 //设备已经打开
    EnableControls();
}

Widget::~Widget()
{
    delete ui;
    slot_closeDevice();
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2128038.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

HyperWorks二维网格划分与单元连续性

自动网格划分 HyperWorks中为零件定义几何曲面是创建零件壳单元网格的最佳方式。HyperMesh 创建二维网格最有效的方法是使用 Automesh 面板直接在零件的表面创建网格。 Automesh 面板是 HyperMesh 重要的网格划分工具&#xff0c;通过 automesh 可实现单元尺寸、单元密度、单…

TopN问题

100亿个integer数据&#xff0c;如何找到前k个最小值。 也就是问的如何排序最快 堆排序最快 完全二叉树 堆结构其实就是一颗完全二叉树 大根堆和小根堆 大根堆&#xff1a;每一个根节点都大于它的叶子结点 小根堆&#xff1a;每一个根节点都小于它的叶子结点 通过建立大根…

【最新顶刊综述】【多模态学习】Vision + X:A Survey on Multimodal Learning in the Light of Data

VisionX&#xff1a;基于数据的多模态学习综述 论文链接 0.论文摘要和信息 摘要 摘要——我们以多感官的方式感知世界并与世界交流&#xff0c;不同的信息源由人脑的不同部分复杂地处理和解释&#xff0c;构成一个复杂但和谐统一的感知系统。为了赋予机器真正的智能&#x…

核心系统用PG了,抠脑壳的权限,搞晕了!

作者&#xff1a;IT邦德 中国DBA联盟(ACDU)成员&#xff0c;10余年DBA工作经验&#xff0c; Oracle、PostgreSQL ACE CSDN博客专家及B站知名UP主&#xff0c;全网粉丝10万 擅长主流Oracle、MySQL、PG、 高斯及Greenplum备份恢复&#xff0c; 安装迁移&#xff0c;性能优化、故障…

ThinkPHP8出租屋管理系统

有需要请加文章底部Q哦 可远程调试 ThinkPHP8出租屋管理系统 一 介绍 此出租屋管理系统基于ThinkPHP8框架开发&#xff0c;数据库mysql&#xff0c;前端Vue3&#xff0c;前后端不分离&#xff0c;系统主要角色为管理员。房租计算器&#xff0c;房东记账收租管理&#xff0c;房…

使用 Prism 框架实现导航.NET 6.0 + WPF

动动您的手指关注下公众号&#xff0c;获取更多优质文章 前言 Prism 一个开源的框架&#xff0c;专门用于开发可扩展、模块化和可测试的企业级 XAML 应用程序&#xff0c;适用于 WPF&#xff08;Windows Presentation Foundation&#xff09;和 Xamarin Forms 等平台。 Prism…

用什么软件可以把做过的试卷还原?4款软件轻松还原

用什么软件可以把做过的试卷还原&#xff1f;在数字化教育的浪潮中&#xff0c;将做过的试卷还原成空白状态不仅满足了学生和教师对于重复练习和分享的需求&#xff0c;还极大地提升了学习效率与资源利用率。这一功能使得错题重做、模拟考试等教学活动更加便捷&#xff0c;促进…

Openpose

核心概念&#xff1a; OpenPose基于Part Affinity Fields&#xff08;PAFs&#xff0c;部件亲和场&#xff09;的概念&#xff0c;这是一种非参数化的表示方法&#xff0c;用于学习图像中个体的身体部位之间的关联。 系统流程&#xff1a; 输入图像&#xff1a; 方法接受一个…

单片机,传感器等低功耗管理

**有些客户需求&#xff0c;把设备做成低功耗管理&#xff0c;这样就可以节省电池的电量&#xff0c;也可以增加传感器的使用寿命 HCLK为CPU提供时钟&#xff0c;内核执行代码。当CPU不需要继续运行时&#xff0c;可以利用多种低功耗模式&#xff0c;等待某个事件触发 ① 睡眠…

大模型实战教程:使用Langchain与ChatGLM实现本地知识库

大语言模型也只是将用户提供的大规模数据集训练而来&#xff0c;也并非万能的什么都知道&#xff0c;特别是一些小众知识、内部数据或私密的个人数据等&#xff0c;此时ChatGLM3肯定会胡乱回答就是ChatGPT4也不一定能给出满意回答&#xff1b;不少公司、个人都有自己的知识库或…

大型集团企业指标体系建设

大型集团企业在进行指标体系建设时&#xff0c;通常会遵循以下几个方面的要求来确保体系的有效性和适用性&#xff1a; 全面性&#xff1a;指标体系应覆盖企业的各个方面&#xff0c;包括但不限于财务状况、市场表现、运营效率、客户满意度、员工发展等。这有助于企业从多个角度…

c4d的vray的蒙版渲染

在一个比较隐藏的角落&#xff0c;extensions>v-ray Tags> Object Properties>勾选Matte Surface&#xff0c;Alpha Contribution打上-1.

JVM面试真题总结(七)

文章收录在网站&#xff1a;http://hardyfish.top/ 文章收录在网站&#xff1a;http://hardyfish.top/ 文章收录在网站&#xff1a;http://hardyfish.top/ 文章收录在网站&#xff1a;http://hardyfish.top/ 解释GC的引用计数算法及其局限性 引用计数算法是一种非常直观、简…

Rocky Linux 9 初次安装后启用 SSH Root 远程登录

Rocky Linux 9 是由 CentOS 的创始人发布的版本&#xff0c;目的是解决 CentOS 停服后企业用户的替代需求。Rocky Linux 9 基于 Red Hat Enterprise Linux 9 下游版本。在 Rocky Linux 9 中&#xff0c;为了增强系统的安全性&#xff0c;默认禁用了 SSH root 密码登录。这是为了…

第12章 进入保护模式

第12章 进入保护模式 章节一开始说明了为什么要有保护模式&#xff1f;后续介绍了如何进入保护模式。 实模式&#xff1a;在实模式下&#xff0c;程序是可以“为所欲为”的。它想访问内存的哪一部分&#xff0c;都可以很轻松地通过设置段地址和偏移地址来办到。 保护模式&am…

Plasma FX

Plasma FX是使用自定义着色器的等离子效果的集合。 通过调整粒子系统参数和颜色,可以轻松自定义效果。 特征 50+效果 定制化 等离子粒子着色器 演示场景 移动预制件 下载:​​Unity资源商店链接资源下载链接 效果图:

nodejs基础教程之-异步编程promise/async/generator

1. 异步 所谓"异步"&#xff0c;简单说就是一个任务分成两段&#xff0c;先执行第一段&#xff0c;然后转而执行其他任务&#xff0c;等做好了准备&#xff0c;再回过头执行第二段,比如&#xff0c;有一个任务是读取文件进行处理&#xff0c;异步的执行过程就是下面…

C#获取计算机信息

目录 效果 项目 代码 下载 效果 项目 代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Management; n…

基于SSM的二手物品交易管理系统的设计与实现 (含源码+sql+视频导入教程+文档+PPT)

&#x1f449;文末查看项目功能视频演示获取源码sql脚本视频导入教程视频 1 、功能描述 基于SSM的二手物品交易管理系统7拥有两种角色 管理员&#xff1a;用户管理、分类管理、商品管理、订单管理、系统管理等 用户&#xff1a;登录注册、充值、收货、评价、收藏、购物车、订…

vue + Element UI table动态合并单元格

一、功能需求 1、根据名称相同的合并工作阶段和主要任务合并这两列&#xff0c;但主要任务内容一样&#xff0c;但要考虑主要任务一样&#xff0c;但工作阶段不一样的情况。&#xff08;枞向合并&#xff09; 2、落实情况里的定量内容和定性内容值一样则合并。&#xff08;横向…