将 Python image.transform 转换为 C++ cv::transform
convert python image.transform to c++ cv::transform
我正在尝试将该页面末尾的代码从python翻译成C++。我被困在这一行:
image.transform(image.size, Image.AFFINE, (a,b,c,d,e,f), resample=resample);
显然我将不得不使用
void cv::transform(InputArray src, OutputArray dst, InputArray m)
它期望"转换 2x2 或 2x3 浮点矩阵"作为 m。我认为我必须将 python 代码的(a,b,c,d,e,f)
部分放入其中,但究竟如何?就上述元素而言,所需的 2x3 矩阵的格式是什么?
你想使用cv::WarpAffine
而不是cv::transform
,因为它是对图像进行仿射变换的函数(cv::transform
是点矩阵(。通过检查文档,很容易将PIL中的(a,b,c,d,e,f(与OpenCV想要的内容相匹配。
从 PIL 文档中,我们看到:
数据是一个 6 元组 (a, b, c, d, e, f(,其中包含仿射变换矩阵中的前两行。对于输出图像中的每个像素 (x, y(,新值取自一个位置 (a x + b y + c, d x + e y + f(
从OpenCV文档中:
函数 warpAffine 使用指定的矩阵转换源图像:
dst(x,y( = src( M11 x + M12 y + M13, M21 x + M22 y + M23(
因此,您可以将矩阵初始化为 cv::Mat warp_mat( 2, 3, CV_32FC1 );
,然后用 a,b,c,d,e,f
填充条目。
相关文章:
- 使用std::transform将一个范围的元素添加到另一个范围中
- g++ 为 transform() 的参数生成错误
- 使用 std::transform 将向量向量 (a) 添加到另一个向量向量 (b)
- std::transform 将一个结构数组复制到另一个结构数组
- 在 transform() 中调用成员函数
- 如何正确使用 std::transform 和 std::mem_fn?
- 如何在 std::transform 中使用 std::p ow 作为一元函数?
- 在 C++ 中使用 "transform" 会给出一个错误,指出这未在作用域中声明
- 将 std::transform 与 std::back_inserter 一起使用是否有效?
- 计算一个单词在映射中出现的次数 - 使用 transform() - 调用不匹配
- 使用 std::transform 最终向量保持为空
- C++ 通过 std::transform 的 vector 索引获取向量
- GLM中的Java Matrix4.transform等价物
- 使用 std::transform 在 2d C 阵列上转换为 1d C 数组
- std::transform 可以替换为 std::累积吗?
- 使用 std ::transform 构造 std::vector.返回未命名结果的可能性?
- std::transform C++ 上的致命错误
- 如何创建一个版本的 boost::range::transform,该版本具有用于捕获上下文的额外参数
- std::transform 操作到 --end() 和奇怪的输出
- 在 lambda(parameter) 中为 std::transform with std::sregex_token