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

相关推荐
漫长的~以后2 小时前
Edge TPU LiteRT V2拆解:1GB内存设备也能流畅跑AI的底层逻辑
前端·人工智能·edge
星火10242 小时前
“重生”之我用 Solo 写了一盘中国象棋
人工智能·ai编程
祝余Eleanor2 小时前
Day37 模型可视化与推理
人工智能·python·深度学习
是Dream呀2 小时前
【openFuyao】openFuyao社区AI推理加速组件技术解析与实践
人工智能·架构·openfuyao
独自归家的兔2 小时前
千问通义plus - 代码解释器的使用
java·人工智能
程序员博博2 小时前
这才是vibe coding正确的打开方式 - 手把手教你开发一个MCP服务
javascript·人工智能·后端
文心快码 Baidu Comate2 小时前
Comate Spec模式实测:让AI编程更精准可靠
人工智能·ai编程·文心快码·ai编程助手
疾风sxp2 小时前
nl2sql技术实现自动sql生成
人工智能·word2vec
阿星AI工作室2 小时前
让gemini3做的网页拥有支付功能,访客变付费用户!附提示词
人工智能
LaughingZhu2 小时前
Product Hunt 每日热榜 | 2025-12-10
人工智能·经验分享·深度学习·神经网络·产品运营