c++ - 计算机视觉(使用 opencv c++ 对齐),出现错误
问题描述
我正在尝试在 Visual Studio 中使用getPerspectiveTransform
或getAffineTransform
运行,但是当我运行代码时,我会看到此消息,并且代码根本无法正常工作。
这是我的代码的一部分:
//Mat im_src = imread("img_name.png",-1);
// Five corners of the source image
vector<Point2f> pts_src;
pts_src.push_back(Point2f(106, 115));
pts_src.push_back(Point2f(141, 111));
pts_src.push_back(Point2f(129, 134));
pts_src.push_back(Point2f(109, 150));
pts_src.push_back(Point2f(147, 146));
// Read destination
// Five corners of the book in destination image.
vector<Point2f> pts_dst;
pts_dst.push_back(Point2f(30.2946, 51.6963));
pts_dst.push_back(Point2f(65.5318, 51.5014));
pts_dst.push_back(Point2f(48.0252, 71.7366));
pts_dst.push_back(Point2f(33.5493, 92.3655));
pts_dst.push_back(Point2f(62.7299, 92.2041));
// Calculate Homography
Mat h = cv::getPerspectiveTransform(pts_src, pts_dst);
//The error is due to the previous line
// Output image
Mat im_out;
// Warp source image to destination based on homography
Size imgSize(112, 96);
warpPerspective(img, im_out, h, imgSize);
// Display images
imshow("Source Image", im_src);
imshow("Warped Source Image", im_out);
这是发生的错误:
解决方案
根据opencv文档:
cv::getPerspectiveTransform()
使用两个 4 元素向量。您传递了 5 元素向量 - 这可能是您的问题的根源。如果您想使用更多积分,您应该考虑
cv::findHomography()
带有 RANSAC 标志
推荐阅读
- vue.js - Nuxt JS 根据 API 响应加载组件
- haskell - 如何根据第一个值生成元组列表的笛卡尔连接?
- python - 如何解释 vowpal wabbit --rank 模型的 --audit 和 --invert_hash 输出?
- reactjs - 如何在 TS/NextJS 项目中设置 JSS?
- python - 将文件中的单词拆分并添加到列表中,“str”对象不能解释为整数错误
- r - R中的数据框列表:分配问题
- java - 除了 AlphaComposite,还有其他方法可以改变 Java 中的图像不透明度吗?
- r - 使用 R 中的 staplr 包合并 PDF 文件
- vim - Vim 中记录的插入模式命令 Control-Shift-U 在哪里?
- angular - Angular 7 Styles 仅在我按下一个键示例控件 f12 后应用,如果组件处于 app.module 级别,它也可以工作