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,相机以及机器人的二次开发)等系统化学习文章。

相关推荐
好开心啊没烦恼40 分钟前
Python 数据分析:计算,分组统计1,df.groupby()。听故事学知识点怎么这么容易?
开发语言·python·数据挖掘·数据分析·pandas
lljss20202 小时前
Python11中创建虚拟环境、安装 TensorFlow
开发语言·python·tensorflow
课堂剪切板2 小时前
ch03 部分题目思路
算法
山登绝顶我为峰 3(^v^)33 小时前
如何录制带备注的演示文稿(LaTex Beamer + Pympress)
c++·线性代数·算法·计算机·密码学·音视频·latex
Two_brushes.4 小时前
【算法】宽度优先遍历BFS
算法·leetcode·哈希算法·宽度优先
Python×CATIA工业智造5 小时前
Frida RPC高级应用:动态模拟执行Android so文件实战指南
开发语言·python·pycharm
千宇宙航5 小时前
闲庭信步使用SV搭建图像测试平台:第三十一课——基于神经网络的手写数字识别
图像处理·人工智能·深度学习·神经网络·计算机视觉·fpga开发
十五年专注C++开发5 小时前
CMake基础:条件判断详解
c++·跨平台·cmake·自动化编译
我叫小白菜6 小时前
【Java_EE】单例模式、阻塞队列、线程池、定时器
java·开发语言
森焱森6 小时前
水下航行器外形分类详解
c语言·单片机·算法·架构·无人机