调整图像类型“垫"的大小. opencv C ++ [英] Resize an image type "Mat" opencv C++
问题描述
我想调整图像大小,当图像是IplImage时,下面的代码有效,但是当我将其更改为Mat时,出现以下错误: -无法将'cv :: Mat :: depth'从类型'int(cv :: Mat ::)()const'转换为'int'. -无法将参数'1'的'cv :: Mat'转换为'const CvArr * {aka const void *}'转换为'void cvResize(const CvArr *,CvArr *,int)'.
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;
有人可以帮我吗?
推荐答案
使用C ++ API语法(当前正在使用C api):
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);
如果不需要,请不要再使用旧的C api cvMethodname函数.而是使用cv :: Methodname函数,这些函数通常不易出错.
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)
这篇关于调整图像类型“垫"的大小. opencv C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!