when using 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
But, the source image being used is 1 channel and has the desired size.
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());
src
instead of theimage
! – alkasm