在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例Windows系统编程 → 海康线激光立体相机的MV-DL2025-04H的SDK的C语言代码

海康线激光立体相机的MV-DL2025-04H的SDK的C语言代码

Windows系统编程

下载此实例
  • 开发语言:C/C++
  • 实例大小:3.31M
  • 下载次数:13
  • 浏览次数:351
  • 发布时间:2021-04-21
  • 实例类别:Windows系统编程
  • 发 布 人:cyber2180413
  • 文件格式:.rar
  • 所需积分:6
 相关标签: C语言 sdk 相机 代码 sd

实例介绍

【实例简介】

通过在控制台输入相机序号及相机工作类型,在控制台输出相机所拍摄包裹的体积,长,宽,高信息

【实例截图】

【核心代码】


#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <iostream>
#include <Windows.h>
#include <time.h>
#include <string.h>
using namespace std;
#include "VolumeMeasureC.h"

#pragma comment(lib, "VolMeasure.lib")

void __stdcall ExceptionCallbackFunc(void* pUser, unsigned int nCameraIndex, unsigned int nMsgType)
{
    printf("VolumeInfo: Camera off line!, recv (%d) (%d) \r\n.",nCameraIndex, nMsgType);
}

bool IsRightFormat(std::string &str)
{
    bool bRightFormat = true;
    for (int i = 0; i < str.length(); i )
    {
        

      if (str[i] < '0' || str[i] > '9' || (str[0] == '0' && 1 != str.length()))
        {
            bRightFormat = false;
            break;
        }
    }

    return bRightFormat;
}


void main()
{
    void* hHandle = NULL;
    int nRet = MV_VOLM_OK;

    printf("---------------------------------------------------------------\r\n");
    printf("Current SDK Version:[%#x]\r\n", VOLM_GetSDKVersion());

    //算法库版本信息
    VOLM_ALGORITHM_INFO_LIST stAlgorithm = {0};
    nRet = VOLM_GetAlgorithmVersion(&stAlgorithm);
    if(MV_VOLM_OK == nRet)
    {
        for (int i = 0; i < stAlgorithm.nAlgorithmNum; i )
        {
            printf("AlgorithName:%s, VersionInfo:%s.\r\n", stAlgorithm.stAlorithmInfo[i].chAlgorithmName, stAlgorithm.stAlorithmInfo[i].chVersionInfo);
        }
    }
    printf("---------------------------------------------------------------\r\n");


    //枚举相机
    VOLM_DEVICE_INFO_LIST stCameraInfoList = {0};
    nRet = VOLM_EnumStereoCamEx(MV_VOLM_GIGE_DEVICE | MV_VOLM_USB_DEVICE, &stCameraInfoList);
    if (MV_VOLM_OK != nRet)
    {
        printf("VOLM_EnumStereoCamEx failed. nRet[%#x]\r\n ", nRet);
        return;
    }
    else
    {
        printf("Find Camera Num:[%d], 3D Camera list:\r\n", stCameraInfoList.nDeviceNum);

        for (int i = 0; i < stCameraInfoList.nDeviceNum; i )
        {
            if (VOLM_CAMERA_3D == stCameraInfoList.pDeviceInfo[i]->nReserved[0])
            {
                if (MV_VOLM_GIGE_DEVICE == stCameraInfoList.pDeviceInfo[i]->nTLayerType)
                {
                    printf("Index:(%d) ModeleNam:%s, SN:%s, UserName:%s\r\n", i, stCameraInfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chModelName,
                        stCameraInfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber,
                        stCameraInfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chUserDefinedName);
                }
                else if (MV_VOLM_USB_DEVICE == stCameraInfoList.pDeviceInfo[i]->nTLayerType)
                {
                    printf("Index:(%d) ModeleNam:%s, SN:%s, UserName:%s\r\n", i, stCameraInfoList.pDeviceInfo[i]->SpecialInfo.stUsb3VInfo.chModelName,
                        stCameraInfoList.pDeviceInfo[i]->SpecialInfo.stUsb3VInfo.chSerialNumber,
                        stCameraInfoList.pDeviceInfo[i]->SpecialInfo.stUsb3VInfo.chUserDefinedName);
                }
                else
                {
                    //do nothing
                }
            }
        }
    }

    printf("---------------------------------------------------------------\r\n");


    unsigned int nIndex  = 0;
    while (true)
    {
        printf("请输入需要连接的相机序号:\n");
        std::string str;
        getline(std::cin, str);

      if(IsRightFormat(str))
        {
            nIndex = atoi(str.c_str());
        }
        else
        {
            printf("输入序号格式不正确,请重新输入:\r\n");
            continue;
        }

        printf("连接的相机:%d \r\n", nIndex);
        if(nIndex >= 0 && nIndex < stCameraInfoList.nDeviceNum && VOLM_CAMERA_3D == stCameraInfoList.pDeviceInfo[nIndex]->nReserved[0])
        {
            break;
        }
        else
        {
            printf("输入序号不正确\r\n");
        }
    }
    printf("---------------------------------------------------------------\r\n");

    try
    {
        int nCameType = 0;
        printf("主动循环获取体积\n");
        printf("请选择体积相机工作模式:\n");
        printf("1. 线激光相机本地体积,测量常规体积\n");
        printf("5. 线激光相机本地体积,测量积分体积\n");
        printf("7. 130W双目相机本地体积(深度图)\n");
        printf("8. 160W双目相机本地体积(深度图)\n");
        printf("9. 349线激光相机直接出体积\n");
        printf("10. 双目相机直接出体积\n");
        printf("11. 双目相机本地体积(原始图)\n");
        printf("12. 线激光相机本地体积(原始图,积分体积)\n");
        printf("13. 双目相机(MV-DS1307-05E)(不支持回调)\n");
        printf("请输入对应序号:");
        scanf("%d",&nCameType);
        printf("工作模式:%d \n", nCameType);
        printf("---------------------------------------------------------------\r\n");

        //定制双目相机MV-DS1307-05E仅支持序列号方式连接
        //其他型号相机支持序列号和Mac地址方式连接
        //根据获取序列号创建句柄
        if (MV_VOLM_GIGE_DEVICE == stCameraInfoList.pDeviceInfo[nIndex]->nTLayerType)
        {
            nRet = VOLM_CreateHandleBySerial(&hHandle, (char*)stCameraInfoList.pDeviceInfo[nIndex]->SpecialInfo.stGigEInfo.chSerialNumber);
        }
        else if (MV_VOLM_USB_DEVICE == stCameraInfoList.pDeviceInfo[nIndex]->nTLayerType)
        {
            // 单MV-DS1307-05E相机场景
            //nRet = VOLM_CreateOBHandle(&hHandle);

            //多MV-DS1307-05E相机场景
            nRet = VOLM_CreateHandleBySerial(&hHandle, (char*)stCameraInfoList.pDeviceInfo[nIndex]->SpecialInfo.stUsb3VInfo.chSerialNumber);
        }
        if (MV_VOLM_OK != nRet)
        {
            printf("VOLM_CreateHandleBySerial failed. nRet[%#x]\r\n ", nRet);
            throw -1;
        }
        else 
        {
            printf("VOLM_CreateHandleBySerial success.\r\n");
        }

        if (MV_VOLM_GIGE_DEVICE == stCameraInfoList.pDeviceInfo[nIndex]->nTLayerType )
        {
            //设置心跳时间(可选)
            CAMERA_PARAM stCameraParam  = {0};  //参数结构体
            strcpy(stCameraParam.cParamName, "GevHeartbeatTimeout");
            stCameraParam.unParamValue.nParamValue = 3000;
            //根据节点名称设置参数
            nRet = VOLM_SetParam(hHandle, VOLMEASURE_CFG_CAMERA, &stCameraParam, sizeof(stCameraParam));
            if (MV_VOLM_OK != nRet)
            {
                printf("VOLM_SetParam failed. nRet[%#x]\r\n ", nRet);
                throw -1;
            }
            else 
            {
                printf("VOLM_SetParam success.\r\n");
            }
        }

        //无特殊情况,nCameType的值不能为0,具体定义见CAMERATYPE结构体
        nRet = VOLM_SetAlgorithmType(hHandle,nCameType);
        if (MV_VOLM_OK != nRet)
        {
            printf("VOLM_SetAlgorithmType failed. nCameType[%d]. nRet[%#x]\r\n ", nCameType, nRet);
            throw -1;
        }
        else 
        {
            printf("VOLM_SetAlgorithmType success. nCameType[%d]\r\n",nCameType);
        }

        nRet = VOLM_RegisterExceptionCallBack(hHandle, ExceptionCallbackFunc, NULL);
        if (MV_VOLM_OK != nRet)
        {
            printf("VOLM_RegisterExceptionCallBack failed. nRet[%#x].\r\n",nRet);
        }
        else 
        {
            printf("VOLM_RegisterExceptionCallBack success.\r\n");
        }

        //开始工作
        nRet = VOLM_Start(hHandle);
        if (MV_VOLM_OK != nRet)
        {
            printf("VOLM_Start failed. nRet[%#x]\r\n ", nRet);
            throw -1;
        }
        else 
        {
            printf("VOLM_Start success\r\n");
        }
        printf("begin volume info measure!\r\n");


        //循环获取体积信息
        while(true)
        {
            VOLM_RESULT_INFO stResultInfo = {0};

            //主动获取体积,没有数据时返回非MV_VOLM_OK
            nRet = VOLM_GetResult(hHandle,&stResultInfo);
            if (MV_VOLM_OK != nRet)
            {
                //printf("VOLM_GetResult failed. nRet[%#x]\r\n",nRet);
            }
            else 
            {
                static unsigned int nIndex = 0;
                nIndex ;

                 //根据标记位,判断是否有体积信息
                if (stResultInfo.nVolumeFlag)
                {
                    printf("\n count: %d\n", nIndex);
                    //打印体积信息
                    printf("VolumeInfo: volume[%.02f] length[%.02f] width[%.02f] height[%.02f]\r\n",
                        stResultInfo.stVolumeInfo.volume,
                        stResultInfo.stVolumeInfo.length,
                        stResultInfo.stVolumeInfo.width,
                        stResultInfo.stVolumeInfo.height);

                    //打印坐标点的信息
                    for(int i=0; i<4; i )
                    {
                        printf("coordinate:[%d] [%.02f-%.02f-%.02f] \r\n",
                            i,
                            stResultInfo.stVolumeInfo.vertex_pnts[i].x,
                            stResultInfo.stVolumeInfo.vertex_pnts[i].y,
                            stResultInfo.stVolumeInfo.vertex_pnts[i].z);
                    }
                }

                //根据标记位,判断是否有图像信息
                if (stResultInfo.nImgFlag)
                {
                    //所需图片信息
                    //图片缓存:stResultInfo.stImage.pData, 图片长度:stResultInfo.stImage.nFrameLen
                    printf("VolumeInfo: recv image.FrameNum[%d] len[%d]\r\n.",stResultInfo.stImage.nFrameNum, stResultInfo.stImage.nFrameLen);
                }
            }
            Sleep(10);
        }

        //停止工作
        nRet = VOLM_Stop(hHandle);
        if (MV_VOLM_OK != nRet)
        {
            printf("VOLM_Stop failed, nRet:(%#x)\r\n", nRet);
        }
        else
        {
            printf("VOLM_Stop success.\r\n");
        }

        if (NULL != hHandle)
        {
            //销毁句柄
            nRet = VOLM_DestroyHandle(hHandle);
            if (MV_VOLM_OK != nRet)
            {
                printf("VOLM_DestroyHandle failed, nRet:(%#x)\r\n", nRet);
            }
            else
            {
                printf("VOLM_DestroyHandle success.\r\n");
            }

            hHandle = NULL;
        }
    }
    catch(...)
    {
        //处理异常
        printf("start volume measure failed. nRet[%#x] \r\n", nRet);

        //停止工作
        VOLM_Stop(hHandle);

        //销毁句柄
        if (NULL != hHandle)
        {
            VOLM_DestroyHandle(hHandle);
            hHandle = NULL;
        }
    }

    //让进程暂停,调试使用,实际不使用
  system("pause");
    return;
}



标签: C语言 sdk 相机 代码 sd

实例下载地址

海康线激光立体相机的MV-DL2025-04H的SDK的C语言代码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警