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

相关推荐
HIT_Weston2 小时前
45、【Agent】【OpenCode】本地代理分析(请求&接收回调)
人工智能·agent·opencode
逻辑君2 小时前
认知神经科学研究报告【20260010】
人工智能·深度学习·神经网络·机器学习
星河耀银海3 小时前
远控体验分享:安全与实用性参考
人工智能·安全·微服务
企业架构师老王3 小时前
2026企业架构演进:科普Agent(龙虾)如何从“极客玩具”走向实在Agent规模化落地?
人工智能·ai·架构
GreenTea3 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
鬼先生_sir3 小时前
Spring AI Alibaba 1.1.2.2 完整知识点库
人工智能·ai·agent·源码解析·springai
深念Y3 小时前
豆包AI能力集成方案:基于会话管理的API网关设计
人工智能
龙文浩_3 小时前
Attention Mechanism: From Theory to Code
人工智能·深度学习·神经网络·学习·自然语言处理
ulimate_3 小时前
八卡算力、三个Baseline算法(WALLOSS、pi0、DreamZero)
人工智能
深小乐4 小时前
AI 周刊【2026.04.06-04.12】:Anthropic 藏起最强模型、AI 社会矛盾激化、"欢乐马"登顶
人工智能