OpenCV之薄板样条插值(ThinPlateSpline)

官方文档:OpenCV: cv::ThinPlateSplineShapeTransformer Class Reference

使用方法:

头文件:#include <opencv2/shape/shape_transformer.hpp>

复制代码
(1)点匹配
一般根据有多少个样本(或者点)来设置,如有M个点,并且下标相同的点是对应点,那么其匹配设置:
复制代码
std::vector<cv::DMatch> matches;
for(int i=0;i < M; ++i)
    matches.append(cv::DMatch(i, i, 0))

(2)计算转换矩阵

复制代码
//源点及目标点(请自行填充)
vector<Point2f> _dstPts,_srcPts;

//获取转换矩阵
cv::Ptr<cv::ThinPlateSplineShapeTransformer> tps
tps = cv::createThinPlateSplineShapeTransformer(0);
tps->estimateTransformation(_dstPts, _srcPts,matches);

(3)获取任意点的转换值

复制代码
//_in_pts--输入值,_out_pts--输出值
vector<Point2f> _in_pts,_out_pts;
_in_pts.push_back(Point2f(0,0));//只举了两个值
_in_pts.push_back(Point2f(1,1));
tps->applyTransformation(_in_pts,_out_pts);

(4)图像变换

图像变换与多点变换相同,注意estimateTransformation只接受输入为(1,m,2)的tuple,不然就会报错,因此如果是图像需要做以下变换:

img = img.reshape(1, -1, 2)

estimatetransformation的说明文档的输入顺序如下:source_points,target_points,matches. 但开发者搞反了输入顺序,如果对图像变换,source 和 target 点应该互换,但对浮动图像选的点做变换又是正确的(崩溃)参考这个opencv的issue:

https://github.com/opencv/opencv/issues/7084

相关推荐
周末程序猿21 小时前
开源项目|不一样的思维导图
人工智能·后端
Wgrape1 天前
一文了解常见AI搜索方案的代码实现
人工智能·后端
Vadaski1 天前
私有 Context 工程如何落地:从方法论到实战
人工智能·程序员
胖墩会武术1 天前
【OpenCV图像处理】深度学习:cv2.dnn() —— 图像分类、人脸检测、目标检测
图像处理·pytorch·python·opencv
刘国华-平价IT运维课堂1 天前
红帽企业Linux 10.1发布:AI命令行助手、量子安全加密和混合云创新
linux·运维·服务器·人工智能·云计算
Xiaok10181 天前
在 Jupyter Notebook 中启动 TensorBoard
人工智能·python·jupyter
亚马逊云开发者1 天前
相得益彰:Mem0 记忆框架与亚马逊云科技的企业级 AI 实践
人工智能
AAA修煤气灶刘哥1 天前
Y-Agent Studio :打破 DAG 的“无环”铁律?揭秘有向有环图如何让智能体真正“活”起来
人工智能·低代码·agent
WWZZ20251 天前
快速上手大模型:深度学习9(池化层、卷积神经网络1)
人工智能·深度学习·神经网络·算法·机器人·大模型·具身智能
__如果1 天前
Surgical Video Understanding LLM
人工智能