资源简介

利用QT建立工程项目,用C++调用海康相机SDK来采集图像,并通过openCV将获取的图像数据转换为可以进行显示的图像。

资源截图

代码片段和文件信息

#include “hikvisionsdk.h“

MV_CC_DEVICE_INFO_LIST m_stDevList;         // ch:设备信息列表结构体变量,用来存储设备列表
MV_CC_DEVICE_INFO* m_Device=NULL;                 //设备对象

HikvisionSDK::HikvisionSDK()
{
    m_hDevHandle    = NULL;
}

HikvisionSDK::~HikvisionSDK()
{
    if (m_hDevHandle)
    {
        MV_CC_DestroyHandle(m_hDevHandle);
        m_hDevHandle    = NULL;
    }
}

//连接相机
int  HikvisionSDK::connectCamera(string id)
{
    //查询设备列表
    int tempValue=MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE &m_stDevList);
    if(tempValue!=0)
        //设备更新成功接收命令的返回值为0,返回值不为0则为异常
        return -1;
    if(m_stDevList.nDeviceNum==0)
        //未找到任何相机
        return 2;
    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)
        {
            if(id== (char*)pDeviceInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName||id== (char*)pDeviceInfo->SpecialInfo.stUsb3VInfo.chSerialNumber||id==“1“)
            {
                m_Device= m_stDevList.pDeviceInfo[i];
                break;
            }
        }

        if(pDeviceInfo->nTlayerType==MV_GIGE_DEVICE)
        {
            if(id== (char*)pDeviceInfo->SpecialInfo.stGigEInfo.chUserDefinedName||id== (char*)pDeviceInfo->SpecialInfo.stGigEInfo.chSerialNumber||id==“1“)
            {
                m_Device= m_stDevList.pDeviceInfo[i];
                break;
            }
        }
        continue;
    }
    if(m_Device==NULL)
    {
        //未找到指定名称的相机
        return 3;
    }

    tempValue  = MV_CC_CreateHandle(&m_hDevHandle m_Device);
    if(tempValue!=0)
        return -1;

    tempValue = MV_CC_OpenDevice(m_hDevHandle);
    if (tempValue!=0)
    {
        MV_CC_DestroyHandle(m_hDevHandle);
        m_hDevHandle = NULL;
        return -1;
    }else
    {
        setTriggerMode(1);
        return 0;
    }
    if (m_Device->nTlayerType == MV_GIGE_DEVICE)
    {
       //std::cout<<“okokokk“<    }
    if(m_Device->nTlayerType == MV_USB_DEVICE)
    {
        MV_CC_SetImageNodeNum(&m_hDevHandle2);
    }

}

//启动相机采集
int HikvisionSDK::startCamera()
{
    int tempValue=MV_CC_StartGrabbing(m_hDevHandle);
    if(tempValue!=0)
    {
        return -1;
    }else
    {
        return 0;
    }
}

//停止相机采集
int HikvisionSDK::stopCamera()
{
    int tempValue=MV_CC_StopGrabbing(m_hDevHandle);
    if(tempValue!=0)
    {
        return -1;
    }else
    {
        return 0;
    }
}

//关闭相机
int HikvisionSDK::closeCamera()
{
    if (NULL == m_hDevHandle)
    {
        return -1;
    }
    MV_CC_CloseDevice(m_hDevHandle);
    int tempValue = MV_CC_DestroyHandle(m_hDevHandle);
    m_hDevHandle = NULL;
    if(tempValue!=0)
    {
        return -1;
    }else
    {
        return 0;
    }
}


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

     文件       1224  2019-04-10 12:21  Hik\Hik.pro

     文件      33381  2019-04-10 12:41  Hik\Hik.pro.user

     文件      10184  2019-04-10 12:37  Hik\hikvisionsdk.cpp

     文件       1941  2019-04-10 12:34  Hik\hikvisionsdk.h

     文件      39011  2018-07-23 10:46  Hik\Includes\CameraParams.h

     文件       1944  2018-07-23 10:46  Hik\Includes\GenICam\base\GCArray.h

     文件       1726  2018-07-23 10:46  Hik\Includes\GenICam\base\GCbase.h

     文件       2900  2018-07-23 10:46  Hik\Includes\GenICam\base\GCError.h

     文件      11910  2018-07-23 10:46  Hik\Includes\GenICam\base\GCException.h

     文件       7283  2018-07-23 10:46  Hik\Includes\GenICam\base\GClinkage.h

     文件       2068  2018-07-23 10:46  Hik\Includes\GenICam\base\GCNamespace.h

     文件       7698  2018-07-23 10:46  Hik\Includes\GenICam\base\GCRTSSUtilities.h

     文件      10466  2018-07-23 10:46  Hik\Includes\GenICam\base\GCString.h

     文件       8697  2018-07-23 10:46  Hik\Includes\GenICam\base\GCStringVector.h

     文件      10095  2018-07-23 10:46  Hik\Includes\GenICam\base\GCSynch.h

     文件       8929  2018-07-23 10:46  Hik\Includes\GenICam\base\GCTypes.h

     文件       9389  2018-07-23 10:46  Hik\Includes\GenICam\base\GCUtilities.h

     文件       6358  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CLAllAdapter.h

     文件      17264  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\ClAllSerial.h

     文件       3221  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CLAutoBuffer.h

     文件       2753  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CLException.h

     文件      20471  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CLPort.h

     文件        229  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\ClProtocol.def

     文件      25464  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CLProtocol.h

     文件       2247  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CLProtocollinkage.h

     文件        251  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\ClSerial.def

     文件      13800  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\ClSerial.h

     文件       5505  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\ClSerialTypes.h

     文件       3017  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\CVersion.h

     文件       4997  2018-07-23 10:46  Hik\Includes\GenICam\CLProtocol\DeviceID.h

............此处省略392个文件信息

评论

共有 条评论