调整图像大小可减少图像中的像素数。当想要减少图像处理时间或减少神经网络训练时间时,它会很有用。
OpenCV 提供了resize
将图像缩小或放大指定宽度和高度的功能。
import cv2
width = 320
height = 240
img = cv2.imread('test.jpg')
resizedImg = cv2.resize(img, (width, height))
cv2.imshow('Original image', img)
cv2.imshow('Resized image', resizedImg)
cv2.waitKey(0)
cv2.destroyAllWindows()
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
int width = 320;
int height = 240;
Mat img = imread("test.jpg");
Mat resizedImg;
resize(img, resizedImg, Size(width, height));
imshow("Original image", img);
imshow("Grayscale image", resizedImg);
waitKey(0);
destroyAllWindows();
return 0;
}
package app;
import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class Main
{
static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
public static void main(String[] args)
{
int width = 320;
int height = 240;
Mat img = Imgcodecs.imread("test.jpg");
Mat resizedImg = new Mat();
Imgproc.resize(img, resizedImg, new Size(width, height));
HighGui.imshow("Original image", img);
HighGui.imshow("Resized image", resizedImg);
HighGui.waitKey(0);
HighGui.destroyAllWindows();
System.exit(0);
}
}
效果图:
版权声明:本文内容转自互联网,本文观点仅代表作者本人。本站仅提供信息存储空间服务,所有权归原作者所有。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至1393616908@qq.com 举报,一经查实,本站将立刻删除。