关于QT加载海康威SDK图像像叠加的解决方案

关于QT加载海康威SDK图像像叠加的解决方案


       最近,需要用QT做一个界面,在显示实时图像的基础上,需要加一个鼠标在视频图像上绘图的功能(即图像叠加),代码如下,供大家参考:

/****************鼠标按下事件*****************/
void Calibration::mousePressEvent(QMouseEvent *e)
{
    Q_UNUSED(e);
    left_1=ui->widget_5->mapFromGlobal(QCursor::pos()).x();
    top_1=ui->widget_5->mapFromGlobal(QCursor::pos()).y();
    right_1=ui->widget_5->mapFromGlobal(QCursor::pos()).x();
    bottom_1=ui->widget_5->mapFromGlobal(QCursor::pos()).y();
}
/****************鼠标移动事件*****************/
void Calibration::mouseMoveEvent(QMouseEvent *e)
{
    Q_UNUSED(e);
    right_1=ui->widget_5->mapFromGlobal(QCursor::pos()).x();
    bottom_1=ui->widget_5->mapFromGlobal(QCursor::pos()).y();
}
/****************鼠标绘图事件*****************/
void Calibration::paintEvent(QPaintEvent *e)
{
    Q_UNUSED(e);
    if(bool_Rectangle==true)
    {
        NET_DVR_RigisterDrawFun(IRealPlayHandle_1,g_DrawFun_Rect_1,0);
    }
}
/****************矩形绘图触发*****************/
void Calibration::on_pbn_Rectangle_clicked()
{
    bool_Rectangle=true;
}
/****************图像叠加回调函数*****************/
void CALLBACK Calibration::g_DrawFun_Rect_1(LONG lRealHandle, HDC hDc, DWORD dwUser)
{
    Q_UNUSED(lRealHandle);
    Q_UNUSED(dwUser);
    RECT rect;
    rect.left=ca->left_1;
    rect.top=ca->top_1;
    rect.right=ca->right_1;
    rect.bottom=ca->bottom_1;
    DrawEdge(hDc,&rect,BDR_SUNKENOUTER,BF_RECT);
}

       视频图像叠加主要用到了NET_DVR_RigisterDrawFun函数,通过调用回调函数获取画图HDC,在HDC上进行绘图。

//横线
int point_X=ca->stPoint.CenterX;
int point_Y=ca->stPoint.CenterY;
MoveToEx(hDc,point_X-50,point_Y,nullptr);
LineTo(hDc,point_X+50,point_Y);
//竖线
int point_X=ca->stPoint.CenterX;
int point_Y=ca->stPoint.CenterY;
MoveToEx(hDc,point_X,point_Y-50,nullptr);
LineTo(hDc,point_X,point_Y+50);    
//交叉线
int point_X=ca->stPoint.CenterX;
int point_Y=ca->stPoint.CenterY;
MoveToEx(hDc,point_X-50,point_Y,nullptr);
LineTo(hDc,point_X+50,point_Y);
MoveToEx(hDc,point_X,point_Y-50,nullptr);
LineTo(hDc,point_X,point_Y+50);
//矩形
POINT poly[5];
poly[0].x=ca->stRectangle.left;
poly[0].y=ca->stRectangle.top;
poly[1].x=ca->stRectangle.right;
poly[1].y=ca->stRectangle.top;
poly[2].x=ca->stRectangle.right;
poly[2].y=ca->stRectangle.bottom;
poly[3].x=ca->stRectangle.left;
poly[3].y=ca->stRectangle.bottom;
poly[4].x=ca->stRectangle.left;
poly[4].y=ca->stRectangle.top;
Polyline(hDc,poly,5);
//圆弧
HPEN hPen=CreatePen(PS_SOLID,1,ca->selectColor);
SelectObject(hDc,hPen);
int point_X=ca->stPoint.CenterX;
int point_Y=ca->stPoint.CenterY;
int Radius =ca->stPoint.Radius;
Arc(hDc,point_X-Radius,point_Y-Radius,point_X+Radius,point_Y+Radius,point_X,point_Y-Radius,point_X,point_Y-Radius);

备注:
1.MinGW与MSVC编译器的结果不一样,MSVC编译器无法得出结果。
2.回调函数中必须要引用全局变量,要经过处理。
3.必须在登录和预览函数,获取到图像句柄之后,再调用NET_DVR_RigisterDrawFun叠加函数。
4.画圆弧Arc时,要指定画笔颜色。
5. .pro添加LIBS += -lgdi32 -luser32;
6. .h添加<windows.h> <winuser.h> <wingdi.h>

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值