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

相关推荐
万少6 小时前
小龙虾(openclaw),轻松玩转自动发帖
前端·人工智能·后端
飞哥数智坊8 小时前
openclaw 重大更新,真的懂我啊
人工智能
KaneLogger8 小时前
AI 时代编程范式迁移的思考
人工智能·程序员·代码规范
飞哥数智坊8 小时前
养虾记第2期:从“人工智障”到“赛博分身”,你的龙虾还缺这两个灵魂
人工智能
飞哥数智坊8 小时前
龙虾虽香,小心扎手!官方点名后,我们该怎么“养虾”?
人工智能
yiyu07168 小时前
3分钟搞懂深度学习AI:实操篇:卷积层
人工智能·深度学习
字节架构前端9 小时前
Skill再回首—深度解读Anthropic官方最新Skill白皮书
人工智能·agent·ai编程
冬奇Lab11 小时前
OpenClaw 深度解析(八):Skill 系统——让 LLM 按需学习工作流
人工智能·开源·源码阅读
冬奇Lab11 小时前
一天一个开源项目(第45篇):OpenAI Agents SDK Python - 轻量级多 Agent 工作流框架,支持 100+ LLM 与实时语音
人工智能·开源·openai