0
votes

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());
1
src isnt an image but your point vector. try cv::warpPerspective(imahe, warped, M, ...) insteadMicka
Voting to close because the question is a simple typo; Micka is correct in that you're accidentally passing the points src instead of the image!alkasm
Yes alkasm. you are rightRick.O

1 Answers

1
votes

It was discussed in topic: https://stackoverflow.com/a/17863381

Short answer:

Use cv::perspectiveTransform or matrix multiplication for points and cv::warpPerspective for images

I hope it will help.