2:QT联合HALCON编程—图像显示放大缩小

1.声明事件

复制代码
#include <HalconCpp.h>
using namespace HalconCpp;


#include <QCloseEvent>//滚轮事件

2.在.h文件中声明和定义公共全局变量,以及图像缩放的函数

复制代码
            void wheelEvent(QWheelEvent *event);//定义函数
            HTuple wcRow0, wcRow1, wcCol0, wcCol1,m_objImage;
            bool GunLunFlag = false;
            HObject  ho_Image;

3.在.cpp文件中,构造函数中

复制代码
   GunLunFlag = true; //变量变为1

4.在.cpp的函数中开始定义

使用此函数时,需要替换窗口名和图像名。(如果在别处也需要使用这两个变量,所以才把这些变量声明到全局变量中去)

HTuple hv_WindowHandle; //公共窗口 大家都会去使用 全局作用域(在联合编程1节里面有提到)

复制代码
//滚轮事件函数
void MainWindow::wheelEvent(QWheelEvent *event)
{
    if(ui->gvDepthMap->geometry().contains(this->mapFromGlobal(QCursor::pos())))
    {
        //resizeImage();
        SetWindowExtents(hv_hv_WindowHandle, 0, 0,  ui->gvDepthMap->width(), ui->gvDepthMap->height());
        try
        {
            if (GunLunFlag == true)
        {
            QPoint pos = event->pos();
            HTuple Row0_1, Col0_1, Row1_1, Col1_1;
            HTuple ImagePtX, ImagePtY;
            QRect WndRect;
            double Scale = 0.1;
            HTuple Width, Height;
            GetImageSize(ho_Image, &Width, &Height);
            WndRect = QRect(QPoint(0, 0), QPoint(ui->gvDepthMap->width(), ui->gvDepthMap->height()));

            if (WndRect.contains(event->pos()))
            {
                if (event->delta() > 0)
                {
                    ImagePtX = wcCol0 + (pos.x() - WndRect.left()) / (WndRect.width() - 1.0) * (wcCol1 - wcCol0);
                    ImagePtY = wcRow0 + (pos.y() - WndRect.top()) / (WndRect.height() - 1.0) * (wcRow1 - wcRow0);
                    Row0_1 = ImagePtY - 1 / (1 - Scale) * (ImagePtY - wcRow0);
                    Row1_1 = ImagePtY - 1 / (1 - Scale) * (ImagePtY - wcRow1);
                    Col0_1 = ImagePtX - 1 / (1 - Scale) * (ImagePtX - wcCol0);
                    Col1_1 = ImagePtX - 1 / (1 - Scale) * (ImagePtX - wcCol1);
                    wcRow0 = Row0_1;
                    wcCol0 = Col0_1;
                    wcRow1 = Row1_1;
                    wcCol1 = Col1_1;
                    if (wcRow0 < 0 || wcCol0 < 0)
                    {
                        wcRow0 = 0;
                        wcCol0 = 0;
                        wcRow1 = Height;
                        wcCol1 = Width;
                    }
                    ClearWindow(hv_hv_WindowHandle);
                    SetPart(hv_hv_WindowHandle, wcRow0, wcCol0, wcRow1, wcCol1);
                    DispObj(ho_Image, hv_hv_WindowHandle);
                }
                else
                {
                    ImagePtX = wcCol0 + (pos.x() - WndRect.left()) / (WndRect.width() - 1.0) * (wcCol1 - wcCol0);
                    ImagePtY = wcRow0 + (pos.y() - WndRect.top()) / (WndRect.height() - 1.0) * (wcRow1 - wcRow0);
                    Row0_1 = ImagePtY - 1 / (1 + Scale) * (ImagePtY - wcRow0);
                    Row1_1 = ImagePtY - 1 / (1 + Scale) * (ImagePtY - wcRow1);
                    Col0_1 = ImagePtX - 1 / (1 + Scale) * (ImagePtX - wcCol0);
                    Col1_1 = ImagePtX - 1 / (1 + Scale) * (ImagePtX - wcCol1);
                    wcRow0 = Row0_1;
                    wcCol0 = Col0_1;
                    wcRow1 = Row1_1;
                    wcCol1 = Col1_1;
                }
                ClearWindow(hv_hv_WindowHandle);
                SetPart(hv_hv_WindowHandle, wcRow0, wcCol0, wcRow1, wcCol1);
                DispObj(ho_Image, hv_hv_WindowHandle);
            }
        }
        }
        catch(...)
        {
          
          // ui->(可以添加界面框显示内容)
           return;
        }
    }
}

已经看到这里了,不妨点个赞和关注吧!

刚开始写文章,如有不足请多多包含;之后会持续更新关于(halcon学习,VS联合编程,QT联合编程,C++,C#,Opencv图像处理库,三维点云库pcl,相机以及机器人的二次开发)等系统化学习文章。

相关推荐
勇闯逆流河1 小时前
【数据结构】堆
c语言·数据结构·算法
jjkkzzzz1 小时前
Linux下的c/c++开发之操作Redis数据库
数据库·c++·redis
prinrf('千寻)2 小时前
MyBatis-Plus 的 updateById 方法不更新 null 值属性的问题
java·开发语言·mybatis
pystraf2 小时前
LG P9844 [ICPC 2021 Nanjing R] Paimon Segment Tree Solution
数据结构·c++·算法·线段树·洛谷
m0_555762902 小时前
Qt缓动曲线详解
开发语言·qt
Funny-Boy2 小时前
菱形继承原理
c++
计算机小手2 小时前
零基础搭建!基于PP-ShiTuV2的轻量级图像识别系统(Docker+API部署指南)
图像处理·经验分享·开源软件
飞川撸码2 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
揽你·入怀3 小时前
数据结构:ArrayList简单实现与常见操作实例详解
java·开发语言
yuhao__z3 小时前
代码随想录算法训练营第六十六天| 图论11—卡码网97. 小明逛公园,127. 骑士的攻击
算法