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

相关推荐
董先生_ad986ad2 小时前
C# 中的 `lock` 关键字本质
开发语言·c#
元亓亓亓2 小时前
Java后端开发day36--源码解析:HashMap
java·开发语言·数据结构
道剑剑非道2 小时前
QT 打包安装程序【windeployqt.exe】报错c000007d原因:Conda巨坑
开发语言·qt·conda
小邓儿◑.◑3 小时前
C++武功秘籍 | 入门知识点
开发语言·c++
码银5 小时前
Java 集合:泛型、Set 集合及其实现类详解
java·开发语言
大G哥5 小时前
PHP标签+注释+html混写+变量
android·开发语言·前端·html·php
何其有幸.5 小时前
实验3-3 比较大小(PTA|C语言)
c语言·数据结构·算法
傻啦嘿哟5 小时前
HTTP代理基础:网络新手的入门指南
开发语言·php
fish_study_csdn5 小时前
pytest 技术总结
开发语言·python·pytest
杨筱毅5 小时前
【优秀三方库研读】【C++基础知识】odygrd/quill -- 折叠表达式
c++·三方库研读