halcon识别二维码(QT调用halcon库实现)

1、简介

halcon是一款和图像处理库,里面的算法很多,效率很高。由于项目中要识别二维码,然后选择了halcon库,因为halcon算法丰富,开发起来方便省时。

2、halcon识别二维码用到的类。

(1)、HImage类:halcon的图像数据存储类。

(2)、HDataCode2D类:halcon识别二维码的算法类。

(3)、HTuple类:halcon存储基本数据的类。类似C++的int。

(4)、HRegion类:halcon用来表示区域的类,类似QT的Item类。

3、源码实现halcon识别二维码。
(1)、MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qgraphicsscene.h>
#include <qmath.h>

#include "HalconCpp.h"
#include "HDevThread.h"

#include <iostream>
using namespace std;

using namespace HalconCpp;

typedef HalconCpp::HObject          HObject;
typedef HalconCpp::HImage           HImage;
typedef HalconCpp::HRegion          HRegion;
typedef HalconCpp::HXLD             HXLD;
typedef HalconCpp::HXLDCont         HXLDCont;
typedef HalconCpp::HHomMat2D        HHomMat2D;

#define M_180_PI (57.2957796)
#define M_PI_180 (0.01745329)

struct QRotatedRect
{
    float cx;
    float cy;
    float w;
    float h;
    float angle;

    QRotatedRect(float cx = 0, float cy = 0, float w = 0, float h = 0, float angle = 0)
    {
        this->cx = cx;
        this->cy = cy;
        this->w = w;
        this->h = h;
        this->angle = angle;
    }
    QRotatedRect(const QPointF& center, const QSizeF& size, float angle)
    {
        this->cx = center.x();
        this->cy = center.y();
        this->w = size.width();
        this->h = size.height();
        this->angle = angle;
    }

    void points(QPointF pts[]) const
    {
        float fAngle = angle * M_PI_180;
        float a = (float)sin(fAngle) * 0.5f;
        float b = (float)cos(fAngle) * 0.5f;
        pts[0].setX(cx - a * h - b * w);
        pts[0].setY(cy + b * h - a * w);
        pts[1].setX(cx + a * h - b * w);
        pts[1].setY(cy - b * h - a * w);
        pts[2].setX(2 * cx - pts[0].x());
        pts[2].setY(2 * cy - pts[0].y());
        pts[3].setX(2 * cx - pts[1].x());
        pts[3].setY(2 * cy - pts[1].y());
    }
    QRectF boundingRect() const
    {
        QPointF pts[4];
        this->points(pts);

        QRectF rt(qFloor(std::min(std::min(std::min(pts[0].x(), pts[1].x()), pts[2].x()), pts[3].x())),
                  qFloor(std::min(std::min(std::min(pts[0].y(), pts[1].y()), pts[2].y()), pts[3].y())),
                  qCeil (std::max(std::max(std::max(pts[0].x(), pts[1].x()), pts[2].x()), pts[3].x())),
                  qCeil (std::max(std::max(std::max(pts[0].y(), pts[1].y()), pts[2].y()),

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mark-puls

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值