c++ - OpenCV warpPerspective 错误:通道数错误
问题描述
使用时warpPerspective
,
OpenCV 错误:cvConvertImage 中的通道数错误(源图像必须有 1、3 或 4 个通道),文件 /build/opencv-ys8xiq/opencv-2.4.9.1+dfsg/modules/highgui/src/utils.cpp,第 622 行抛出'cv :: Exception'实例后调用终止what():/build/opencv-ys8xiq/opencv-2.4.9.1+dfsg/modules/highgui/src/utils.cpp:622:错误:(-15)源图像在函数 cvConvertImage 中必须有 1、3 或 4 个通道
但是,正在使用的源图像是 1 个通道并且具有所需的大小。
这段代码基本上是为了得到一张图像的鸟瞰图。
cv::Mat warped;
std::vector<cv::Point2f> src ;
src.push_back(cv::Point2f(640, 470));
src.push_back(cv::Point2f(0, 470));
src.push_back(cv::Point2f(150, 250));
src.push_back(cv::Point2f(490, 250));
std::vector<cv::Point2f> dst ;
dst.push_back(cv::Point2f(640, 480));
dst.push_back(cv::Point2f(0, 480));
dst.push_back(cv::Point2f(0, 0));
dst.push_back(cv::Point2f(640, 0));
cv::Mat M = cv::getPerspectiveTransform(src,dst);
cv::warpPerspective(src, warped, M, image.size());
解决方案
在主题中进行了讨论:https ://stackoverflow.com/a/17863381
简短的回答:
对点使用 cv::perspectiveTransform 或矩阵乘法,对图像使用 cv::warpPerspective
我希望它会有所帮助。
推荐阅读
- r - 为什么我没有得到由其他分类变量分组的两个数字列的计数,只有 tidyverse?
- asp.net-core - 如何通过控制器将参数传递给策略中使用的授权处理程序
- c# - 如何从更大的数据集中生成过滤的 .net 数据集(包括所有 JOINed 表)?
- c - 用于查找数字的阶乘的递归函数
- flutter - 如何在flutter_local_notification中使用报警音量?
- reactjs - React Native Context 包裹在里面时呈现一个空白屏幕
- node.js - 尝试发送 Post 请求时出错。我在项目中使用 Nodejs 和 MongoDB
- angular - 使用 ngx-cookieconsent 添加自定义 cookie
- html - Nutch+Solr:如何索引嵌入在 HTML 中的 PDF?
- python - 如何优化我的python循环函数