CSDN文章都翻遍了,STACKoverflow的阿三哥都被我问烦了,折腾了两个礼拜...
记录一下代码吧
首先我这个是webcam,想用openCV的caputure(0)方式是行不通的。只能使用rtsp协议,但我尝试后无果,只能选用原生海康SDK开启摄像头。关键代码如下:
tar_dev = MV_CC_OpenDevice(m_devhandle);//m_devhandle是设备句柄
if(MV_OK != tar_dev){
MV_CC_DestroyHandle(m_devhandle);
m_devhandle = MV_NULL;
}
开启相机后进行采集数据。
MV_CC_StartGrabbing(m_devhandle);
同时设备显示数据。
//构造函数中:
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(displayImage()));//显示图片的槽函数
//开始采集后定时器开启
timer->start(720);
//-----------------渲染图片
void HiCamera::displayImage()
{
int tempValue;
unsigned int nRecvBufSize = 0;
MVCC_INTVALUE stParam;
memset(&stParam, 0, sizeof(MVCC_INTVALUE));
int temp = MV_CC_GetIntValue(m_devhandle, "PayloadSize", &stParam);
if (temp != 0)
{
printf("over point%d\n",1);
return;
}
nRecvBufSize = stParam.nCurValue;
unsigned char* m_pBufForDriver = (unsigned char *)malloc(nRecvBufSize);
MV_FRAME_OUT_INFO_EX stImageInfo;
memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
tempValue= MV_CC_GetOneFrameTimeout(m_devhandle, m_pBufForDriver, nRecvBufSize, &stImageInfo, 700); //主动调用取图
if(tempValue!=0)
{
printf("over %x\n",tempValue);
return;
}