简体   繁体   English

OpenCV warpPerspective错误:通道数错误

[英]OpenCV warpPerspective error : Bad number of channels

when using warpPerspective , 使用warpPerspective

OpenCV Error: Bad number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage, file /build/opencv-ys8xiq/opencv-2.4.9.1+dfsg/modules/highgui/src/utils.cpp, line 622 terminate called after throwing an instance of 'cv::Exception' what(): /build/opencv-ys8xiq/opencv-2.4.9.1+dfsg/modules/highgui/src/utils.cpp:622: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage OpenCV错误:cvConvertImage文件/build/opencv-ys8xiq/opencv-2.4.9.1+dfsg/modules/highgui/src/utils.cpp,第622行中的通道数错误(源图像必须具有1、3或4个通道)抛出'cv :: Exception'what()实例后终止终止调用:/build/opencv-ys8xiq/opencv-2.4.9.1+dfsg/modules/highgui/src/utils.cpp:622:错误:(-15)源图像必须在功能cvConvertImage中具有1、3或4个通道

But, the source image being used is 1 channel and has the desired size. 但是,正在使用的源图像为1通道,并且具有所需的大小。

This code is basically to get the birdeye's view of an image. 这段代码基本上是为了获得图像的鸟瞰图。

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());

It was discussed in topic: https://stackoverflow.com/a/17863381 在主题中进行了讨论: https : //stackoverflow.com/a/17863381

Short answer: 简短答案:

Use cv::perspectiveTransform or matrix multiplication for points and cv::warpPerspective for images 对点使用cv :: perspectiveTransform或矩阵乘法,对图像使用cv :: warpPerspective

I hope it will help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM