2.3安装工业相机SDK及测试

2023-11-14

不同工业相机的sdk不同,可以到相应的官网下载,我使用的是大华相机
文中提到的例程的Camera和src的代码在文尾(有兴趣可以参考)

下载:

官方下载地址:http://download.huaraytech.com/pub/sdk/
我使用的是2.2.5的Linux的x86的版本
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
点击下载
在这里插入图片描述

安装:

将下载的压缩包中.run文件提取出来,增加可执行权限,然后运行即可
在这里插入图片描述
在这里插入图片描述
安装位置:/opt/DahuaTech/MVviewer

测试:

运行启动脚本:/opt/DahuaTech/MVviewer/bin/run.sh
成功打开MVviewer
在这里插入图片描述

QT使用大华:

新建一个QT工程

导入OpenCV的头文件和库:

pro文件中输入下列代码
在这里插入图片描述

INCLUDEPATH +=/usr/local/include/ \
              /usr/local/include/opencv4/ \
              /usr/local/include/opencv4/opencv2
LIBS +=/usr/local/lib/lib*

添加大华头文件和动态库:

将大华目录下的头文件复制到工程文件夹下
在这里插入图片描述

导入QT:

在这里插入图片描述
在这里插入图片描述
pro文件中输入下列代码
在这里插入图片描述

INCLUDEPATH +=./include \

LIBS += -L/opt/DahuaTech/MVviewer/lib/ -lMVSDK
LIBS += -L/opt/DahuaTech/MVviewer/lib/ -lImageConvert
LIBS += -L/opt/DahuaTech/MVviewer/lib/ -lVideoRender
LIBS += -L/opt/DahuaTech/MVviewer/lib/GenICam/bin/Linux64_x64/ -lGCBase_gcc421_v3_0 -lGenApi_gcc421_v3_0 -lLog_gcc421_v3_0
LIBS += -L/opt/DahuaTech/MVviewer/lib/GenICam/bin/Linux64_x64/ -llog4cpp_gcc421_v3_0 -lNodeMapData_gcc421_v3_0 -lXmlParser_gcc421_v3_0
LIBS += -L/opt/DahuaTech/MVviewer/lib/GenICam/bin/Linux64_x64/ -lMathParser_gcc421_v3_0

大华动态库:

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

添加动态库文件的一般方法:

添加动态库,如libMVSDK.so文件
LIBS+=-L/opt/DahuaTech/MVviewer/lib -lMVSDK
//注意:最前面加上大写字母L。将文件名中的lib替换成-l

添加测试代码:

将例程下的env_test中Camera和src复制到工程文件夹下
在这里插入图片描述
在这里插入图片描述
将其导入Qt
在这里插入图片描述

修改主函数:

#include <iostream>
#include "Camera/video.h"
#include<opencv2/opencv.hpp>
using namespace Dahua::GenICam;
using namespace Dahua::Infra;

using namespace std;
using namespace cv;
int main()
{// 创建工业相机的实例
    Video v;


    if (!v.videoCheck())
    {
        printf("videoCheck failed!\n");
        return 0;
    }
    if (!v.videoOpen())
    {
        printf("videoOpen failed!\n");
        return 0;
    }

                                     //设置增益
    Video::ETrigType type = Video::ETrigType::trigContinous; //改为连续拉流
    v.CameraChangeTrig(type);                                //默认为软触发
    if (!v.videoStart())
    {
        printf("videoStart failed!\n");
        return 0;
    }
   Mat src;
   while(1)
   {
    if(v.getFrame(src)){
        imshow("img",src);
   }
    else
    {
        printf("getFrame failed!\n");
         break;
    }
    if(waitKey(1)=='q')
    {
        break;
    }
    cout << "Hello World!" << endl;
    return 0;
}

}

插入大华相机,运行,显示设备信息即成功

完成

例程的Camera和src的代码

文件结构

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

video.h

#ifndef VIDEO_H
#define VIDEO_H

#include <math.h>
#include "GenICam/System.h"
#include "Media/VideoRender.h"
#include "Media/ImageConvert.h"
#include <iostream>
#include "GenICam/Camera.h"
#include "GenICam/GigE/GigECamera.h"
#include "GenICam/GigE/GigEInterface.h"
#include "Infra/PrintLog.h"
#include "Memory/SharedPtr.h"
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace Dahua::GenICam;
using namespace Dahua::Infra;
using namespace Dahua::Memory;
using namespace std;
using namespace cv;

static uint32_t gFormatTransferTbl[] =
    {
        // Mono Format
        gvspPixelMono1p,
        gvspPixelMono8,
        gvspPixelMono10,
        gvspPixelMono10Packed,
        gvspPixelMono12,
        gvspPixelMono12Packed,

        // Bayer Format
        gvspPixelBayRG8,
        gvspPixelBayGB8,
        gvspPixelBayBG8,
        gvspPixelBayRG10,
        gvspPixelBayGB10,
        gvspPixelBayBG10,
        gvspPixelBayRG12,
        gvspPixelBayGB12,
        gvspPixelBayBG12,
        gvspPixelBayRG10Packed,
        gvspPixelBayGB10Packed,
        gvspPixelBayBG10Packed,
        gvspPixelBayRG12Packed,
        gvspPixelBayGB12Packed,
        gvspPixelBayBG12Packed,
        gvspPixelBayRG16,
        gvspPixelBayGB16,
        gvspPixelBayBG16,
        gvspPixelBayRG10p,
        gvspPixelBayRG12p,

        gvspPixelMono1c,

        // RGB Format
        gvspPixelRGB8,
        gvspPixelBGR8,

        // YVR Format
        gvspPixelYUV411_8_UYYVYY,
        gvspPixelYUV422_8_UYVY,
        gvspPixelYUV422_8,
        gvspPixelYUV8_UYV,
};
#define gFormatTransferTblLen sizeof(gFormatTransferTbl) / sizeof(gFormatTransferTbl[0])

class Video
{
  public:
    Video() {}
    ~Video()
    {
        videoStopStream(); //断流
        videoClose();	  //析构断开与相机的链接
    }

    //枚举触发方式
    enum ETrigType
    {
        trigContinous = 0, //连续拉流
        trigSoftware = 1,  //软件触发
        trigLine = 2,	  //外部触发
    };

    bool videoCheck();										  //搜索相机
    bool videoOpen();										  //初始化相机
    void CameraChangeTrig(ETrigType trigType = trigSoftware); //设置触发模式,一般为软触发
    void ExecuteSoftTrig();									  //执行一次软触发
    bool videoStart();										  //创建流对象
    bool getFrame(Mat &img);                                  //获取一帧图片
    bool convertToRGB24(Mat &img);							  //转换为opencv可以识别的格式
    void videoStopStream();									  //断开拉流
    void videoClose();										  //断开相机

    void startGrabbing();                                   //
    void SetExposeTime(double exp);							//设置曝光
    void SetAdjustPlus(double adj);							//设置增益
    void setBufferSize(int nSize);
    void setBalanceRatio(double dRedBalanceRatio, double dGreenBalanceRatio, double dBlueBalanceRatio);
    void setResolution(int height = 720, int width = 1280); //设置分辨率
    void setROI(int64_t nX, int64_t nY, int64_t nWidth, int64_t nHeight);
    void setBinning();
    bool loadSetting(int mode);
    void setFrameRate(double rate = 210);					//设置帧率
    ICameraPtr m_pCamera;				  //相机对象
  private:
    TVector<ICameraPtr> m_vCameraPtrList; //相机列表
    IStreamSourcePtr m_pStreamSource;	 //流文件


};

class FrameBuffer
{
  private:
    uint8_t *Buffer_;

    int Width_;

    int Height_;

    int PaddingX_;

    int PaddingY_;

    int DataSize_;

    int PixelFormat_;

    uint64_t TimeStamp_;

    uint64_t BlockId_;

  public:
    FrameBuffer(Dahua::GenICam::CFrame const &frame)
    {
        if (frame.getImageSize() > 0)
        {
            if (frame.getImagePixelFormat() == Dahua::GenICam::gvspPixelMono8)
            {
                Buffer_ = new (std::nothrow) uint8_t[frame.getImageSize()];
            }
            else
            {
                Buffer_ = new (std::nothrow) uint8_t[frame.getImageWidth() * frame.getImageHeight() * 3];
            }
            if (Buffer_)
            {
                Width_ = frame.getImageWidth();
                Height_ = frame.getImageHeight();
                PaddingX_ = frame.getImagePadddingX();
                PaddingY_ = frame.getImagePadddingY();
                DataSize_ = frame.getImageSize();
                PixelFormat_ = frame.getImagePixelFormat();
                BlockId_ = frame.getBlockId();
            }
        }
    }

    ~FrameBuffer()
    {
        if (Buffer_ != NULL)
        {
            delete[] Buffer_;
            Buffer_ = NULL;
        }
    }

    bool Valid()
    {
        if (NULL != Buffer_)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    int Width()
    {
        return Width_;
    }

    int Height()
    {
        return Height_;
    }

    int PaddingX()
    {
        return PaddingX_;
    }

    int PaddingY()
    {
        return PaddingY_;
    }

    int DataSize()
    {
        return DataSize_;
    }

    uint64_t PixelFormat()
    {
        return PixelFormat_;
    }

    uint64_t TimeStamp()
    {
        return TimeStamp_;
    }

    void setWidth(uint32_t iWidth)
    {
        Width_ = iWidth;
    }

    void setPaddingX(uint32_t iPaddingX)
    {
        PaddingX_ = iPaddingX;
    }

    uint64_t BlockId()
    {
        return BlockId_;
    }

    void setPaddingY(uint32_t iPaddingX)
    {
        PaddingY_ = iPaddingX;
    }

    void setHeight(uint32_t iHeight)
    {
        Height_ = iHeight;
    }

    void setDataSize(int dataSize)
    {
        DataSize_ = dataSize;
    }

    void setPixelFormat(uint32_t pixelFormat)
    {
        PixelFormat_ = pixelFormat;
    }

    void setTimeStamp(uint64_t timeStamp)
    {
        TimeStamp_ = timeStamp;
    }

    uint8_t *bufPtr()
    {
        return Buffer_;
    }
};

#endif

video.cpp

#include "Camera/video.h"

void Video::setBufferSize(int nSize){
    bool bRet;
    m_pStreamSource = CSystem::getInstance().createStreamSource(m_pCamera);
    if (NULL == m_pStreamSource)
    {
        printf("create a SourceStream failed!\n");
        return;
    }

    m_pStreamSource->setBufferCount(nSize);
//	bRet = intNode.setValue(width);
//	if (false == bRet)
//	{
//		printf("set width fail.\n");
//		return;
//	}

//	intNode = sptrImageFormatControl
//	bRet = intNode.setValue(height);
//	if (false == bRet)
//	{
//		printf("set height fail.\n");
//		return;
//	}
}


bool Video::loadSetting(int mode)
{
    CSystem &sysobj = CSystem::getInstance();
    IUserSetControlPtr iSetPtr;
    iSetPtr = sysobj.createUserSetControl(m_pCamera);
    CEnumNode nodeUserSelect(m_pCamera, "UserSetSelector");
    if (mode == 0)
    {
        if (!nodeUserSelect.setValueBySymbol("UserSet1")){
            cout << "set UserSetSelector failed!" << endl;
        }
    }
    else if (mode == 1){
        if (!nodeUserSelect.setValueBySymbol("UserSet2")){
            cout << "set UserSetSelector failed!" << endl;
        }
    }

    CCmdNode nodeUserSetLoad(m_pCamera, "UserSetLoad");
    if (!nodeUserSetLoad.execute()){
        cout << "set UserSetLoad failed!" << endl;
    }
}

bool Video::videoCheck()
{
    CSystem &systemObj = CSystem::getInstance();

    bool bRet = systemObj.discovery(m_vCameraPtrList);
    if (false == bRet)
    {
        printf("discovery fail.\n");
        exit(-1);
        return false;
    }

    // 打印相机基本信息(key, 制造商信息, 型号, 序列号)
    for (int i = 0; i < m_vCameraPtrList.size(); i++)
    {
        ICameraPtr cameraSptr = m_vCameraPtrList[i];

        printf("Camera[%d] Info :\n", i);
        printf("    key           = [%s]\n", cameraSptr->getKey());
        printf("    vendor name   = [%s]\n", cameraSptr->getVendorName());
        printf("    model         = [%s]\n", cameraSptr->getModelName());
        printf("    serial number = [%s]\n", cameraSptr->getSerialNumber());
    }

    if (m_vCameraPtrList.size() < 1)
    {
        printf("no camera.\n");
        return false;
        //	msgBoxWarn(tr("Device Disconnected."));
    }
    else
    {
        //默认设置列表中的第一个相机为当前相机,其他操作比如打开、关闭、修改曝光都是针对这个相机。
        m_pCamera = m_vCameraPtrList[0];
    }
    return true;
}

bool Video::videoOpen()
{
    if (NULL == m_pCamera)
    {
        printf("connect camera fail. No camera.\n");
        exit(-1);
        return false;
    }

    if (true == m_pCamera->isConnected())
    {
        printf("camera is already connected.\n");
        exit(-1);
        return false;
    }

    if (false == m_pCamera->connect())
    {
        printf("connect camera fail.\n");
        exit(-1);
        return false;
    }

    return true;
}

void Video::videoClose()
{
    if (NULL == m_pCamera)
    {
        printf("disconnect camera fail. No camera.\n");
        exit(-1);
        return;
    }

    if (false == m_pCamera->isConnected())
    {
        printf("camera is already disconnected.\n");
        exit(-1);
        return;
    }

    if (false == m_pCamera->disConnect())
    {
        printf("disconnect camera fail.\n");
    }
}

bool Video::videoStart()
{
    if (m_pStreamSource != NULL)
    {
        return true;
    }

    if (NULL == m_pCamera)
    {
        printf("start camera fail. No camera.\n");
        exit(-1);
        return false;
    }

    m_pStreamSource = CSystem::getInstance().createStreamSource(m_pCamera); //创建流的对象
    if (NULL == m_pStreamSource)
    {
        printf("Create stream source failed.");
        exit(-1);
        return false;
    }


    return true;
}

void Video::startGrabbing()
{
    m_pStreamSource->setBufferCount(1);
    m_pStreamSource->startGrabbing();
}

void Video::CameraChangeTrig(ETrigType trigType)
{
    if (NULL == m_pCamera)
    {
        printf("Change Trig fail. No camera or camera is not connected.\n");
        exit(-1);
        return;
    }

    if (trigContinous == trigType)
    {
        //设置触发模式
        CEnumNode nodeTriggerMode(m_pCamera, "TriggerMode");
        if (false == nodeTriggerMode.isValid())
        {
            printf("get TriggerMode node fail.\n");
            return;
        }
        if (false == nodeTriggerMode.setValueBySymbol("Off"))
        {
            printf("set TriggerMode value = Off fail.\n");
            return;
        }
    }
    else if (trigSoftware == trigType)
    {
        //设置触发源为软触发
        CEnumNode nodeTriggerSource(m_pCamera, "TriggerSource");
        if (false == nodeTriggerSource.isValid())
        {
            printf("get TriggerSource node fail.\n");
            return;
        }
        if (false == nodeTriggerSource.setValueBySymbol("Software"))
        {
            printf("set TriggerSource value = Software fail.\n");
            return;
        }

        //设置触发器
        CEnumNode nodeTriggerSelector(m_pCamera, "TriggerSelector");
        if (false == nodeTriggerSelector.isValid())
        {
            printf("get TriggerSelector node fail.\n");
            return;
        }
        if (false == nodeTriggerSelector.setValueBySymbol("FrameStart"))
        {
            printf("set TriggerSelector value = FrameStart fail.\n");
            return;
        }

        //设置触发模式
        CEnumNode nodeTriggerMode(m_pCamera, "TriggerMode");
        if (false == nodeTriggerMode.isValid())
        {
            printf("get TriggerMode node fail.\n");
            return;
        }
        if (false == nodeTriggerMode.setValueBySymbol("On"))
        {
            printf("set TriggerMode value = On fail.\n");
            return;
        }
    }
    else if (trigLine == trigType)
    {
        //设置触发源为Line1触发
        CEnumNode nodeTriggerSource(m_pCamera, "TriggerSource");
        if (false == nodeTriggerSource.isValid())
        {
            printf("get TriggerSource node fail.\n");
            return;
        }
        if (false == nodeTriggerSource.setValueBySymbol("Line1"))
        {
            printf("set TriggerSource value = Line1 fail.\n");
            return;
        }

        //设置触发器
        CEnumNode nodeTriggerSelector(m_pCamera, "TriggerSelector");
        if (false == nodeTriggerSelector.isValid())
        {
            printf("get TriggerSelector node fail.\n");
            return;
        }
        if (false == nodeTriggerSelector.setValueBySymbol("FrameStart"))
        {
            printf("set TriggerSelector value = FrameStart fail.\n");
            return;
        }

        //设置触发模式
        CEnumNode nodeTriggerMode(m_pCamera, "TriggerMode");
        if (false == nodeTriggerMode.isValid())
        {
            printf("get TriggerMode node fail.\n");
            return;
        }
        if (false == nodeTriggerMode.setValueBySymbol("On"))
        {
            printf("set TriggerMode value = On fail.\n");
            return;
        }

        // 设置外触发为上升沿(下降沿为FallingEdge)
        CEnumNode nodeTriggerActivation(m_pCamera, "TriggerActivation");
        if (false == nodeTriggerActivation.isValid())
        {
            printf("get TriggerActivation node fail.\n");
            return;
        }
        if (false == nodeTriggerActivation.setValueBySymbol("RisingEdge"))
        {
            printf("set TriggerActivation value = RisingEdge fail.\n");
            return;
        }
    }
}

void Video::ExecuteSoftTrig()
{
    if (NULL == m_pCamera)
    {
        printf("Set GainRaw fail. No camera or camera is not connected.\n");
        return;
    }

    CCmdNode nodeTriggerSoftware(m_pCamera, "TriggerSoftware");
    if (false == nodeTriggerSoftware.isValid())
    {
        printf("get TriggerSoftware node fail.\n");
        return;
    }
    if (false == nodeTriggerSoftware.execute())
    {
        printf("set TriggerSoftware fail.\n");
        return;
    }

    // printf("ExecuteSoftTrig success.\n");
}

void Video::videoStopStream()
{
    if (m_pStreamSource == NULL)
    {
        printf("stopGrabbing succefully!\n");
        return;
    }

    if (!m_pStreamSource->stopGrabbing())
    {
        printf("stopGrabbing  fail.\n");
    }
}

bool Video::getFrame(Mat &img)
{

    CFrame frame, frameClone;
    bool isSuccess = m_pStreamSource->getFrame(frame, 300/*500*/);
    if (!isSuccess)
    {
        printf("getFrame  fail.\n");
        m_pStreamSource->stopGrabbing();
        m_pCamera->disConnect();
        exit(0);
        return false;
    }

    //判断帧的有效性
    bool isValid = frame.valid();
    if (!isValid)
    {
        printf("frame is invalid!\n");
        return false;
    }

    frameClone = frame.clone();

    TSharedPtr<FrameBuffer> PtrFrameBuffer(new FrameBuffer(frameClone));
    if (!PtrFrameBuffer)
    {
        printf("create PtrFrameBuffer failed!\n");
        return false;
    }

    uint8_t *pSrcData = new (std::nothrow) uint8_t[frameClone.getImageSize()];
    if (pSrcData)
    {
        memcpy(pSrcData, frameClone.getImage(), frameClone.getImageSize());
    }
    else
    {
        printf("new pSrcData failed!\n");
        return false;
    }

    int dstDataSize = 0;
    IMGCNV_SOpenParam openParam;
    openParam.width = PtrFrameBuffer->Width();
    openParam.height = PtrFrameBuffer->Height();
    openParam.paddingX = PtrFrameBuffer->PaddingX();
    openParam.paddingY = PtrFrameBuffer->PaddingY();
    openParam.dataSize = PtrFrameBuffer->DataSize();
    openParam.pixelForamt = PtrFrameBuffer->PixelFormat();

    IMGCNV_EErr status = IMGCNV_ConvertToBGR24(pSrcData, &openParam, PtrFrameBuffer->bufPtr(), &dstDataSize);
    if (IMGCNV_SUCCESS != status)
    {
        delete[] pSrcData;
        return false;
    }

    delete[] pSrcData;

    //将读进来的帧数据转化为opencv中的Mat格式操作
    Size size;
    size.height = PtrFrameBuffer->Height();
    size.width = PtrFrameBuffer->Width();
    img = Mat(size, CV_8UC3, PtrFrameBuffer->bufPtr()).clone();
//    PtrFrameBuffer.reset();
    frameClone.reset();
    return true;
}


void Video::setBalanceRatio(double dRedBalanceRatio, double dGreenBalanceRatio, double dBlueBalanceRatio)
{
    bool bRet;
    IAnalogControlPtr sptrAnalogControl = CSystem::getInstance().createAnalogControl(m_pCamera);
    if (NULL == sptrAnalogControl)
    {
        return ;
    }

    /* 关闭自动白平衡 */
    CEnumNode enumNode = sptrAnalogControl->balanceWhiteAuto();
    if (false == enumNode.isReadable())
    {
        printf("balanceRatio not support.\n");
        return ;
    }

    bRet = enumNode.setValueBySymbol("Off");
    if (false == bRet)
    {
        printf("set balanceWhiteAuto Off fail.\n");
        return ;
    }

    enumNode = sptrAnalogControl->balanceRatioSelector();
    bRet = enumNode.setValueBySymbol("Red");
    if (false == bRet)
    {
        printf("set red balanceRatioSelector fail.\n");
        return ;
    }

    CDoubleNode doubleNode = sptrAnalogControl->balanceRatio();
    bRet = doubleNode.setValue(dRedBalanceRatio);
    if (false == bRet)
    {
        printf("set red balanceRatio fail.\n");
        return ;
    }

    enumNode = sptrAnalogControl->balanceRatioSelector();
    bRet = enumNode.setValueBySymbol("Green");
    if (false == bRet)
    {
        printf("set green balanceRatioSelector fail.\n");
        return ;
    }

    doubleNode = sptrAnalogControl->balanceRatio();
    bRet = doubleNode.setValue(dGreenBalanceRatio);
    if (false == bRet)
    {
        printf("set green balanceRatio fail.\n");
        return ;
    }

    enumNode = sptrAnalogControl->balanceRatioSelector();
    bRet = enumNode.setValueBySymbol("Blue");
    if (false == bRet)
    {
        printf("set blue balanceRatioSelector fail.\n");
        return ;
    }

    doubleNode = sptrAnalogControl->balanceRatio();
    bRet = doubleNode.setValue(dBlueBalanceRatio);
    if (false == bRet)
    {
        printf("set blue balanceRatio fail.\n");
        return ;
    }
}


void Video::SetExposeTime(double exp)
{
    bool bRet;
    IAcquisitionControlPtr sptrAcquisitionControl = CSystem::getInstance().createAcquisitionControl(m_pCamera);
    if (NULL == sptrAcquisitionControl)
    {
        printf("create a IAcquisitionControlPtr failed!\n");
        return;
    }
    CEnumNode eNode = sptrAcquisitionControl->exposureAuto();
    uint64 getValue;
    if (!eNode.getValue(getValue))
    {
        printf("get value of type is failed!\n");
        return;
    }
    if (getValue)//如果开启了自动曝光模式,则关闭
    {
        bRet = eNode.setValueBySymbol("Off");
        if (!bRet)
        {
            printf("close autoExposure failed!\n");
            return;
        }
    }

    CDoubleNode dNode = sptrAcquisitionControl->exposureTime();
    bRet = dNode.setValue(exp);
    if (!bRet)
    {
        printf("set exposure failed!\n");
        return;
    }

}

void Video::SetAdjustPlus(double adj)
{
    if (NULL == m_pCamera)
    {
        printf("Set GainRaw fail. No camera or camera is not connected.\n");
        return;
    }

    CDoubleNode nodeGainRaw(m_pCamera, "GainRaw");

    if (false == nodeGainRaw.isValid())
    {
        printf("get GainRaw node fail.\n");
        return;
    }

    if (false == nodeGainRaw.isAvailable())
    {
        printf("GainRaw is not available.\n");
        return;
    }

    if (false == nodeGainRaw.setValue(adj))
    {
        printf("set GainRaw value = %f fail.\n", adj);
        return;
    }
}

void Video::setResolution(int height, int width)
{
    bool bRet;
    IImageFormatControlPtr sptrImageFormatControl = CSystem::getInstance().createImageFormatControl(m_pCamera);
    if (NULL == sptrImageFormatControl)
    {
        printf("create a IImageFormatControlPtr failed!\n");
        return;
    }

    CIntNode intNode = sptrImageFormatControl->height();
    bRet = intNode.setValue(width);
    if (false == bRet)
    {
        printf("set width fail.\n");
        return;
    }

    intNode = sptrImageFormatControl->height();
    bRet = intNode.setValue(height);
    if (false == bRet)
    {
        printf("set height fail.\n");
        return;
    }
}

void Video::setROI(int64_t nX, int64_t nY, int64_t nWidth, int64_t nHeight)
{
    bool bRet;
    CIntNode nodeWidth(m_pCamera, "Width");
    bRet = nodeWidth.setValue(nWidth);
    if (!bRet)
    {
        printf("set width fail.\n");
    return;
    }
    CIntNode nodeHeight(m_pCamera, "Height");
    bRet = nodeHeight.setValue(nHeight);
    if (!bRet)
    {
        printf("set Height fail.\n");
    return;
    }
    CIntNode OffsetX(m_pCamera, "OffsetX");
    bRet = OffsetX.setValue(nX);
    if (!bRet)
    {
        printf("set OffsetX fail.\n");
    return;
    }
    CIntNode OffsetY(m_pCamera, "OffsetY");
    bRet = OffsetY.setValue(nY);
    if (!bRet)
    {
        printf("set OffsetY fail.\n");
    return;
    }
//    bool bRet;
//    IImageFormatControlPtr sptrImageFormatControl = CSystem::getInstance().createImageFormatControl(m_pCamera);
//    if (NULL == sptrImageFormatControl)
//    {
//        return;
//    }

//    /* width */
//    CIntNode intNode = sptrImageFormatControl->width();
//    bRet = intNode.setValue(nWidth);
//    if (!bRet)
//    {
//        printf("set width fail.\n");
//    return;
//    }

//    /* height */
//    intNode = sptrImageFormatControl->height();
//    bRet = intNode.setValue(nHeight);
//    if (!bRet)
//    {
//        printf("set height fail.\n");
//    return;
//    }

//    /* OffsetX */
//    intNode = sptrImageFormatControl->offsetX();
//    bRet = intNode.setValue(nX);
//    if (!bRet)
//    {
//        printf("set offsetX fail.\n");
//    return;
//    }

//    /* OffsetY */
//    intNode = sptrImageFormatControl->offsetY();
//    bRet = intNode.setValue(nY);
//    if (!bRet)
//    {
//        printf("set offsetY fail.\n");
//    return;
//    }

    return;
}

void Video::setBinning()
{
    CEnumNodePtr ptrParam(new CEnumNode(m_pCamera, "Binning"));
    if (ptrParam)
    {
        if (false == ptrParam->isReadable())
        {
            printf("binning not support.\n");
            return;
        }

        if (false == ptrParam->setValueBySymbol("XY"))
        {
            printf("set Binning XY fail.\n");
            return;
        }

//        if (false == ptrParam->setValueBySymbol("Off"))
//        {
//            printf("set Binning Off fail.\n");
//            return;
//        }
    }
    return;
}

void Video::setFrameRate(double rate)
{
    bool bRet;
    IAcquisitionControlPtr sptAcquisitionControl = CSystem::getInstance().createAcquisitionControl(m_pCamera);
    if (NULL == sptAcquisitionControl)
    {
        return;
    }

    CBoolNode booleanNode = sptAcquisitionControl->acquisitionFrameRateEnable();
    bRet = booleanNode.setValue(true);
    if (false == bRet)
    {
        printf("set acquisitionFrameRateEnable fail.\n");
        return;
    }

    CDoubleNode doubleNode = sptAcquisitionControl->acquisitionFrameRate();
    bRet = doubleNode.setValue(rate);
    if (false == bRet)
    {
        printf("set acquisitionFrameRate fail.\n");
        return;
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

2.3安装工业相机SDK及测试 的相关文章

  • 无法使用 android.support.v7.widget.AppCompatTextView 实例化以下类

    最近我在 android studio 的应用程序中将我的 sdk 从 25 更改为 26 我在所有 xml 中都遇到了这个奇怪的错误 目前 该错误并没有以我能看到的任何方式影响我的应用程序 但每次我必须编辑或更改 xml 中的某些内容时
  • 使用 OpenCV 从轮廓获取掩模

    我想从我通过 cv findContours 计算的轮廓 它只存在 1 个轮廓 获取图像掩模 然而 虽然我的轮廓变量不为空 但我无法使用 cv drawContours 检索图像蒙版 我的目标图像始终为空 这是我的代码 img mosaic
  • 优化 Keras 以使用所有可用的 CPU 资源

    好吧 我真的不知道我在说什么 所以请耐心听我说 我正在使用 Theano 后端运行 Keras 以在 MNIST 图像上运行基本的神经网络 目前只是一个教程 过去 我一直使用我的旧 HP 笔记本电脑 因为我有 Windows 和 Ubunt
  • 使用 hcitool 扫描低功耗蓝牙?

    当我运行此命令时 BLE 设备扫描仅持续 5 秒 sudo timeout 5s hcitool i hci0 lescan 输出显示在终端屏幕中 但是 当我将输出重定向到文件以保存广告设备的地址时 每次运行该命令时 我都会发现该文件是空的
  • cv2.imdecode 始终返回 None

    我正在从存储 JPEG 图像的 sqlite BLOB 读取二进制数据 sqlite3 Binary 图像被写入数据库 img cv2 imread images image jpg c execute INSERT INTO pictur
  • 使用 CLion 进行 OpenCV Windows 设置

    我想在 Windows 上为 CLion IDE 设置 OpenCV 我尝试使用 OpenCV 3 1 和 2 4 得到相同的结果 我有 Windows 10 64 位 CLion 使用 cygwin 环境 到目前为止我做了什么 1 从Op
  • SVN 不断提示我输入密码并拒绝缓存我的凭据

    环境 Eclipse Indigo Ubuntu 11 04 Subclipse 1 6 SVN 客户端 Subclipse RabbitVCS 我通过 svn ssh 连接 我的网址如下所示 svn ssh 我的名字 我的域名 路径 我可
  • Android Studio SDK 位置

    我看到有很多与此问题相关的类似主题 但我在这些帖子中没有找到适合我的解决方案 我刚刚安装了 Android Studio v0 8 14 但它不允许我创建新项目 因为我没有指定 SDK 路径 对于我的一生 我找不到那条路应该在哪里 我看到很
  • 如何在不使用 Cocos2D 的情况下将声音实现到现有应用程序中

    例如 iOS SDK下载页面上有示例代码 我正在使用计算器应用程序 iPhoneUnitTests 我想知道是否可以轻松地向已构建的应用程序上的按钮添加声音 播放短声音 例如按钮声音 实际上非常简单 这是一个简单的例子 您必须链接 Audi
  • Android SDK 位置不应包含空格,因为这会导致 NDK 工具出现问题

    Recently I have installed the last version of Android Studio Android Studio 2 1 keeping the old 1 2 version previously i
  • Opencv中内存Mat表示

    我知道在内存中opencv将Mat对象表示为一个大数组 因此 如果我有 3 个尺寸为 200x200 的通道垫 那么在内存中它将将该垫存储在尺寸为 3x200x200 的数组中 或者更一般地说 内存中的任何 Mat 都将存储为channel
  • 如何在 Ubuntu 16.04 上安装适用于 Python 2.7 的 openCV 2.4.13?

    我尝试了很多在线帖子来安装 opencv 但它们不适用于 Ubuntu 16 04 有人可以给我安装 openCV 2 4 13 的步骤吗 我不久前制作了一个脚本 用于安装最新版本的 OpenCV 截至本答案的最后一次更新为 4 2 这是它
  • OpenCV 中更新窗口的 waitKey() 的替代方法

    到目前为止我见过的所有示例和书籍都建议使用 waitKey 1 来强制重新绘制 OpenCV 窗口 这看起来很奇怪而且太老套了 不必要的时候为什么还要等待 1 毫秒呢 还有其他选择吗 我尝试了 cv updateWindow 但它似乎需要
  • 如何使用 Python 3 在 OpenCV 3 上正确加载 cv2.KeyPoint 和描述符?

    有一天 我不得不恢复一个使用 OpenCV 3 和 Python 2 7 的旧项目 在此代码中 要加载 cv2 KeyPoint 我执行以下操作 import numpy as np import cPickle import cv2 ke
  • 使用 openCV 锐化视频图像

    我想使用 OpenCV 锐化我的图像 我在网上查看了一个示例 该示例正在对灰度图像执行锐化 我尝试了它 它工作得很好 然而 我现在尝试做同样的事情 但使用 RGB 颜色 所以我分别在三个通道上执行相同的功能 但它没有给我任何结果 图像与原始
  • PostgreSQL docker:“无法绑定 IPv6 套接字:无法分配请求的地址”

    编辑2 经过很长一段时间 解决了 请参阅下面的答案 编辑 我很遗憾地说 从昨天到今天 问题 自行 消失了 而我没有做任何事情 在这里学习很棒的非确定性课程 额外的乐趣 无法绑定 IPv6 套接字 错误仍然出现在错误日志中 因此这可能根本不是
  • gnutls_handshake() 失败:握手失败 GIT

    一切都工作正常 但突然我收到错误 致命 无法访问 https 电子邮件受保护 cdn cgi l email protection name repo name git gnutls handshake 失败 握手失败 我在我的计算机和 E
  • ECC 导致多光谱图像的图像对齐失败

    我正在尝试将 RGB 图像与 IR 图像 单通道 对齐 目标是创建 4 通道图像 R G B IR 为了做到这一点 我正在使用cv2 findTransformECC如中所述这个非常简洁的指南 https learnopencv com i
  • 检测骰子的上侧

    是否可以检测骰子的上面 虽然从顶部看这将是一项简单的任务 但从许多角度来看 可以看到多个侧面 Here is an example of a dice feel free to take your own pictures 您通常想知道自己
  • OpenCV非旋转图像拼接

    我正在 OpenCV 中进行图像拼接 从不同位置拍摄平面场景的照片并尝试构图全景图 我修改了缝合示例以满足我的需要 openCV 拼接管道的问题是 它假设相机纯粹旋转 但对我来说情况并非如此 当拍摄的照片与场景完全正交时 没有相机旋转 只是

随机推荐

  • little endian && big-endian

    java 的ClassFile采用big endian存储数据 Intel x86 采用little endian Motorola采用big endian 0x1234 Intel 地址 0x4000 0000 0x34 0x4000 0
  • vue-使用sass定义全局样式及变量

    vue cli2使用sass定义全局样式及变量 vue cli2创建的vue项目使用sass预处理器需按顺序安装以下插件 其中sass loader版本和node sass需要安装固定版本 其他的依赖不要求版本 亲测有效 如果不不固定sas
  • unity Domain Reload & scene Reload 静态变量重置

    关闭 Domain Reload 选项后 c 的静态变量在下次运行时不会怎么重置 需要手动添加重置代码 使用下面的属性设置重置变量函数 using UnityEngine public class StaticCounterExampleF
  • ns.ajax,UIWebView使用NSURLProtocol(拦截),ajax加载失败的问题

    问题 ajax跨域访问是一个老问题了 解决方法很多 比较常用的是JSONP方法 JSONP方法是一种非官方方法 而且这种方法只支持GET方式 不如POST方式安全 即使使用jquery的jsonp方法 type设为POST 也会自动变为GE
  • 解决eclipse新建dynamic web project没有apache的Runtime environment问题

    在新建eclipse web项目时候 想选择Tomact服务器 不过运行时环境选择中没有 没有出现下图的Apache目录吗 网络上好像没有找到教程 其实很简单 只是没有装上相应的插件 解决步骤如下 1 打开Help gt Install N
  • ThinkPad BIOS 设置详解

    ThinkPad BIOS 设置详解 ThinkPad BIOS 设置详解 主流 新机型 在网上查看了相关资料 发现好多都是T40或者更老的BIOS设置信息 不适合现在的主流以及新机型 于是找到分享该贴 希望对各位有所帮助 简洁的分割线 T
  • Python-错误与异常处理

    通常情况下 在try语句块中写我们想要的逻辑 发生错误和异常时Python解释器会采用raise方法即将异常抛出 except语句可以承接raise方法抛出的异常并对异常做出处理 Python中有三种异常捕获与处理形式 第一种 try ex
  • 为什么MySQL字符串不加引号索引失效?《死磕MySQL系列 十一》

    群里一个小伙伴在问为什么MySQL字符串不加单引号会导致索引失效 这个问题估计很多人都知道答案 没错 是因为MySQL内部进行了隐式转换 本期文章就聊聊什么是隐式转换 为什么会发生隐式转换 文章目录 系列文章 一 几大索引失效原因 二 从规
  • 解决git中文乱码

    1 配置git bash idea 随便找地方打开git bash 右击窗口进入options 分别将text选项的Locale改为zh CN character set改为UTF 8 如图所示 2 命令执行 我改了这个就好了 如果不行 在
  • C++基础知识(二)

    C 基础知识 二 文章目录 C 基础知识 二 1 指针与引用 2 日期与时间 3 cerr与clog 1 指针与引用 C 有两种指针运算符 一种是取地址运算符 另一种是间接寻址运算符 它们都是单目运算符 返回操作数的内存地址 如 var读作
  • Vulkan【15】图形管线(Graphics Pipline)

    创建图形管线 本节的代码是 14 init pipeline cpp 你越来越接近把这些拉到一起来渲染一个立方体 下一步是通过设置图形管道来配置GPU来进行渲染 一个图形管线由着色阶段 管线布局 渲染过程和固定功能管线阶段组成 您在前面的部
  • 一个栈的入栈序列是 a,b,c,d,e,则栈的不可能的输出序列是( ) 。

    一个栈的入栈序列是 a b c d e 则栈的不可能的输出序列是 a edcba b decbac dceab d abcde 堆栈讲究先进后出 后进先出 选项1是abcde先入栈 然后依次出栈 正好是edcba 选项2是abcd先依次入栈
  • python 数据清洗 豆瓣电影_python 数据清洗篇

    前面我们用pandas做了一些基本的操作 接下来进一步了解数据的操作 数据清洗一直是数据分析中极为重要的一个环节 本篇主要演示 python 数据清洗的数据合并 转换 过滤 排序 数据合并 在pandas中可以通过merge对数据进行合并操
  • 【Python搞搞轻量Blog】第一发 Flask入门

    我发现很多小伙伴一直想着有自己的一个博客 而且还想自己写一个 你们都这么爱折腾 我就给你们搞一个轻量级级别的Blog 准备 我们要用Python来写一套轻量级的博客 那么必须要有Python方面的基础 如果有HTML和CSS的基础食用更佳
  • Ren'Py引擎源代码解读(1)——脚本文件加载

    因为想要尝试把Ren Py移植到Cocos上 尽可能的使用原来的rpy文件 这就难免要解析rpy文件 因此就参考了一下Ren Py自己是怎么解析脚本的 文件加载 那么从哪里看起呢 先简要看一下Ren Py的启动过程 启动脚本肯定是根目录下的
  • 1.1.3 Hadoop生态系统

    1 1 3 Hadoop生态系统 2013 05 08 09 38 16 我来说两句 收藏 我要投稿 本文所属图书 gt Hadoop技术内幕 深入解析Hadoop Common和HDFS架构设计与实现原理 Hadoop技术内幕共两册 分别
  • CDMA 猫用AT命令发中文短信(C#)

    CDMA猫连PDU都不支持 只能发文本短信 而且发中文短信居然是UNICODE 无法在超级终端里输入 只能写程序 网上这个问题谈论地比较多 做起来比较累 还偶尔会出乱码 还是将C 的成功代码帖一下吧 void SendCHNSms stri
  • 力扣 - 1、俩数之和

    题目 给定一个整数数组 nums 和一个整数目标值 target 请你在该数组中找出 和为目标值 的那 两个 整数 并返回它们的数组下标 你可以假设每种输入只会对应一个答案 但是 数组中同一个元素在答案里不能重复出现 你可以按任意顺序返回答
  • 清华梦的粉碎-写给清华大学的退学申请

    作者 王垠 清华梦的诞生 小时候 妈妈给我一个梦 她指着一个大哥哥的照片对我说 这是爸爸的学生 他考上了清华 大学 他是我们中学的骄傲 长大后 你也要进入清华大学读书 为我们家争光 我不知道清华是什么样子 但是我知道爱迪生和 牛顿 的故事
  • 2.3安装工业相机SDK及测试

    不同工业相机的sdk不同 可以到相应的官网下载 我使用的是大华相机 文中提到的例程的Camera和src的代码在文尾 有兴趣可以参考 下载 官方下载地址 http download huaraytech com pub sdk 我使用的是2