0
votes

I want to transform a polar grid image into a cartesian representation. But I keep have a strange error message that says:

OpenCV Error : Bad flag(parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file M : \libs\OpenCV - 2.4.13x86\sources\modules\core\src\array.cpp, line 2482

Here is my code that i kept as simple as possible:

#include<cstdio>
#include <opencv2/opencv.hpp>
#include "opencv2/imgproc.hpp"

int main()
{
    // cv::Mat src = cv::imread("savetest.png"); // _lin_polar_img
    // cv::Mat src = cv::imread("280px_1.png"); // _lin_polar_img
    cv::Mat src = cv::Mat(800, 800, CV_8SC3); // _lin_polar_img
    cv::Mat _recovered_cart_img;

    cv::Point2f center( (float)src.cols / 2.f, (float)src.rows / 2.f );
    double maxRadius = 0.7*std::min(center.y, center.x);

    // cvLinearPolar(const CvArr* src, CvArr* dst, CvPoint2D32f center, double maxRadius, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS )
    cvLinearPolar(&src, &_recovered_cart_img, center, maxRadius, cv::INTER_LINEAR+CV_WARP_INVERSE_MAP);

    system("pause");
    return 0;
}

I am using OpenCV 2.4.13 on windows 10 (VisualC++ 2015).

1
Can you possibly upgrade to OpenCV 3.x? That has a C++ implementation of this, rather than this old C function which works with the legacy data structure. - Dan Mašek
I cannot change the version of the library. I am developing a small component inside a big project. - Yazan
The error you are facing come from the function cvLinearPolar which is a C function that you gave c++ structures. A cvArr has nothing related with Mat container from namespace cv. Try to find in the documentation a c++ function (e.g. cv::cartToPolar) that has replaced it. - John_Sharp1318

1 Answers

0
votes

I have solved the issue thanks to the comment of @John_Sharp1318. I had to work with the Iplimage which is the C image container. The working code:

IplImage* _recovered_cart_img;
_recovered_cart_img = cvLoadImage("savetest.png");

IplImage *_lin_polar_img = cvCreateImage(cvSize(_recovered_cart_img->height, _recovered_cart_img->width), IPL_DEPTH_8U, 3);

cv::Point2f center( (float)_lin_polar_img->width / 2.f, (float)_lin_polar_img->height / 2.f );
double maxRadius = 4.0*std::min(center.y, center.x);

cvLinearPolar(_lin_polar_img, _recovered_cart_img, center, maxRadius, cv::INTER_LINEAR+CV_WARP_INVERSE_MAP);