Resize an image type "Mat" opencv C++

I want to resize my image the code below works when the image is an IplImage but when i change it into Mat i get these errors: -Cannot convert 'cv::Mat::depth' from type 'int (cv::Mat::)() const' to type 'int'. -Cannot convert 'cv::Mat' to 'const CvArr* {aka const void*}' for argument '1' to 'void cvResize(const CvArr*, CvArr*, int)'.

 Mat image=imread("21.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat dst;
dst= cvCreateImage(cvSize(150,150),image.depth,image.channels());
cvResize(image, dst);
namedWindow("Source", CV_WINDOW_AUTOSIZE );
imshow("Source", image);
namedWindow("resize", CV_WINDOW_AUTOSIZE );
imshow("resize", dst);
waitKey(0);
    return 0;

Can someone please help me?


use the C++ API syntax (currently you are using the C api):

cv::Mat image = cv::imread("21.png", CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat dst;
cv::resize(image, dst, cv::Size(150,150));

cv::namedWindow("Source", CV_WINDOW_AUTOSIZE );
cv::imshow("Source", image);
cv::namedWindow("resize", CV_WINDOW_AUTOSIZE );
cv::imshow("resize", dst);
waitKey(0);

please don't use the old C api cvMethodname functions anymore if you don't have to. Instead use the cv::Methodname functions which are typically much less error prone.

If you need to specifiy an aspect ratio or different interpolation, see http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#void%20resize(InputArray%20src,%20OutputArray%20dst,%20Size%20dsize,%20double%20fx,%20double%20fy,%20int%20interpolation)


You can also use the code given below:

 Mat3b groupres;
 cvtColor(img, groupres, COLOR_GRAY2BGR);
 imshow("Grouped Result", groupres);
 Size size1(400, 450);
 resize(groupres, groupres, size1);
 waitKey();

the waitKey(); helps the image to stay and wait for a response.

链接地址: http://www.djcxy.com/p/89830.html

上一篇: 将字节数组转换为不在c#中工作的字符串

下一篇: 调整图像类型“Mat”opencv C ++