编程语言
首页 > 编程语言> > 海康威视连续采图设置ROI局部显示_c#

海康威视连续采图设置ROI局部显示_c#

作者:互联网

为啥要设置ROI来局部显示呢?

是因为当生产线速度很快时,每张图片只给几毫秒的处理时间,如果把整张图片都传输给计算机,那么时间会浪费在数据传输上,而画一个ROI来减小图像尺寸从而减小传输数据的大小,就可以提升数据的处理速度来适应快速的生产线节拍

首先,先从连续采图的图像中单步采集出一张图片来设置ROI区域

然后,重启相机

最后,绘制好ROI区域(X、Y的偏移量+roi图像的宽与高),把参数写进相机,然后再连续采图

private uint imgWidth, imgHeight, offsetX, offsetY;
        public void SetRoi(ComboBox comboBox)
        {
            int nRet = MyCamera.MV_OK;


            //获取相机采图的最大尺寸
            ImageSize imgMaxSize = GetMaxSize();
            uint nWidthMax = imgMaxSize.Width;
            uint nHeightMax = imgMaxSize.Height;
            

            double width = CommonParam.width;
            double height = CommonParam.height;
            double offX = CommonParam.offX;
            double offY = CommonParam.offY;
            //初始化	
            nRet = m_pMyCamera.MV_CC_SetIntValue_NET("OffsetX", 0);
            if (MyCamera.MV_OK != nRet)
            {
                ShowErrorMsg("Set OffsetX Fail!", nRet);
            }
            nRet = m_pMyCamera.MV_CC_SetIntValue_NET("OffsetY", 0);
            if (MyCamera.MV_OK != nRet)
            {
                ShowErrorMsg("Set OffsetY Fail!", nRet);
            }
            //设置宽高
            imgWidth = (uint)(width * nWidthMax);
            uint nVal = (imgWidth / 32) * 32;
            nRet = m_pMyCamera.MV_CC_SetIntValue_NET("Width", nVal);
            if (MyCamera.MV_OK != nRet)

            {
                ShowErrorMsg("Set Width Fail!", nRet);
            }
            imgHeight = (uint)(height * nHeightMax);
            nVal = (imgHeight / 16) * 16;
            nRet = m_pMyCamera.MV_CC_SetIntValue_NET("Height", nVal);
            if (MyCamera.MV_OK != nRet)
            {
                ShowErrorMsg("Set Height Fail!", nRet);
            }
            offsetX = (uint)(offX * nWidthMax);
            nVal = (offsetX / 16) * 16;
            nRet = m_pMyCamera.MV_CC_SetIntValue_NET("OffsetX", nVal);
            if (MyCamera.MV_OK != nRet)
            {
                ShowErrorMsg("Set OffsetX Fail!", nRet);
            }
            offsetY = (uint)(offY * nHeightMax);
            nVal = (offsetY / 16) * 16;
            nRet = m_pMyCamera.MV_CC_SetIntValue_NET("OffsetY", nVal);
            if (MyCamera.MV_OK != nRet)
            {
                ShowErrorMsg("Set OffsetY Fail!", nRet);
            }
            
        }

 

标签:ROI,OK,威视,c#,nVal,MV,uint,nRet,MyCamera
来源: https://blog.csdn.net/qq_48705696/article/details/112586065