0

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());
Rick.O
  • 23
  • 7

1 Answers1

1

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.

Kamil Szelag
  • 708
  • 3
  • 12
  • I understand, but unfortunately, it doesn't solve my issue. I am using the cv::warpPerspective for an image, but I need the transformation matrix first. That is why I am using the cv::getperspectiveTransform. I am doing the same in Python and runs without trouble. Thanks either way ! – Rick.O Aug 05 '19 at 13:27
  • You can use matrix from getPerspectiveTransform in multiplication of points. This will help. Regards. – Kamil Szelag Aug 05 '19 at 17:59