若该文为原创文章,转载请注明出处
本文章博客地址:https://hpzwl.blog.csdn.net/article/details/143105881
长沙红胖子Qt(长沙创微智科)博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬结合等等)持续更新中…
Qt开发专栏:项目实战(点击传送门)
需求
1.打开图片;
2.矫正识别角点;
3.opencv摄像头操作子线程处理;
4.支持设置棋盘格的行列角点数;
背景
深入研究图像拼接细分支算法,产出的效果查看工具,验证算法单步思路。
相关博客
《项目实战:Qt+Opencv相机标定工具v1.3.0(支持打开摄像头、视频文件和网络地址,支持标定过程查看、删除和动态评价误差率,支持追加标定等等)》
《OpenCV开发笔记(〇):使用mingw530_32编译openCV3.4.1源码,搭建Qt5.9.3的openCV开发环境》
《OpenCV开发笔记(三):OpenCV图像的概念和基本操作》
《OpenCV开发笔记(四):OpenCV图片和视频数据的读取与存储》
《OpenCV开发笔记(六):OpenCV基础数据结构、颜色转换函数和颜色空间》
《OpenCV开发笔记(四十六):红胖子8分钟带你深入了解仿射变化(图文并茂+浅显易懂+程序源码)》
《OpenCV开发笔记(七十六):相机标定(一):识别棋盘并绘制角点》
《OpenCV开发笔记(七十七):相机标定(二):通过棋盘标定计算相机内参矩阵矫正畸变摄像头图像》
Demo:affineTool_v1.1.0 windows运行包
CSDN粉丝0积分下载:https://download.csdn.net/download/qq21497936/89908724
QQ群:博客首页扫码进入QQ技术群,点击“文件”搜索“affineTool”,群内与博文同步更新)
模块化部署
关键源码
AffineManager.h
#ifndef AFFINEMANAGER_H
#define AFFINEMANAGER_H// opencv
#include "opencv/highgui.h"
#include "opencv/cxcore.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/xphoto.hpp"
#include "opencv2/dnn/dnn.hpp"
// opencv_contrib
#include <opencv2/xphoto.hpp>
#include <opencv2/ximgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>#include "cvui.h"#include <QImage>
#include <QTimer>class AffineManager: public QObject
{Q_OBJECT
public:explicit AffineManager(QObject *parent = 0);~AffineManager();public slots:void testOpencvEnv(); // 测试环境public:cv::Point2f getLeftBottomOffsetPoint() const;cv::Point2f getCenterTopOffsetPoint() const;cv::Point2f getRightBottomOffsetPoint() const;int getChessboardColCornerCount() const;int getChessboardRowCornerCount() const;public:void setLeftBottomOffsetPoint(const cv::Point2f &offsetPoint);void setRightBottomOffsetPoint(const cv::Point2f &offsetPoint);void setCenterTopOffsetPoint(const cv::Point2f &offsetPoint);void setChessboardColCornerCount(int chessboardColCornerCount);void setChessboardRowCornerCount(int chessboardRowCornerCount);signals:void signal_srcImage(QImage image);void signal_srcImage(cv::Mat mat);void signal_resultImage(QImage image);void signal_resultImage(cv::Mat mat);void signal_inited(bool result);public slots:void slot_openImage(QString filePath);void slot_initImage();void slot_affineImage();protected:void initControl();protected:bool findChessboard(int rowCornerCount, int colCornerCount, cv::Mat &mat, std::vector<cv::Point2f> &vectorPoint2fCorners);public:static QImage mat2Image(cv::Mat mat); // cv::Mat 转 QImageprivate:cv::Mat _mat; // 缓存一帧cv::Mat _resultMat; // 结果int _chessboardColCornerCount; // 一列多少个角点int _chessboardRowCornerCount; // 一行多少个角点private: // 计算内参和畸变系数cv::Mat _cameraMatrix; // 相机矩阵(接收输出)cv::Mat _distCoeffs; // 畸变系数(接收输出)std::vector<cv::Mat> _rotate; // 旋转量(接收输出)std::vector<cv::Mat> _translate; // 偏移量(接收输出)cv::Point2f _leftBottomPoint; // 仿射三点,对应原始cv::Point2f _rightBottomPoint;// 仿射三点,对应原始cv::Point2f _centerTopPoint; // 仿射三点,对应原始cv::Point2f _leftBottomOffsetPoint; // 仿射三点,对应偏移cv::Point2f _rightBottomOffsetPoint;// 仿射三点,对应偏移cv::Point2f _centerTopOffsetPoint; // 仿射三点,对应偏移
};#endif // AffineManager_H
AffineManager.cpp
...void AffineManager::slot_affineImage()
{cv::Point2f srcTraingle[3];cv::Point2f dstTraingle[3];srcTraingle[0] = _leftBottomPoint;srcTraingle[1] = _rightBottomPoint;srcTraingle[2] = _centerTopPoint;dstTraingle[0] = _leftBottomPoint + _leftBottomOffsetPoint;dstTraingle[1] = _rightBottomPoint + _rightBottomOffsetPoint;dstTraingle[2] = _centerTopPoint + _centerTopOffsetPoint;cv::Mat mat = cv::getAffineTransform(srcTraingle, dstTraingle);std::cout << srcTraingle[0] << srcTraingle[1] << srcTraingle[2] << endl;std::cout << dstTraingle[0] << dstTraingle[1] << dstTraingle[2] << endl;cv::warpAffine(_mat, _resultMat, mat, cv::Size(_mat.cols, _mat.rows));QImage image = mat2Image(_resultMat);emit signal_resultImage(image);
}
...
入坑
算法的研究优化过程中,思路需要开拓编写代码,查看效果,逐步研究出算法的优化路径,坑多暂时未记录。
本文章博客地址:https://hpzwl.blog.csdn.net/article/details/143105881