How to Re-Size the image Open Cv
by vigneshchennai74 Updated: Jan 31, 2023
OpenCV is a library for image processing and computer vision that can be used to resize images. Resizing images using OpenCV can be useful in a number of ways, some of which include:
- Image compression: to reduce the file size of an image.
- Image processing: as a pre-processing step in image processing algorithms, such as object detection, segmentation, and feature extraction.
- Computer vision: to adjust the resolution of an image to match the requirements of a computer vision algorithm, such as object detection or image recognition.
- Data augmentation: as a data augmentation technique to increase the diversity of the training data, which can improve the performance of machine learning models
- Printing: To adjust the resolution of an image to match the requirements of a printing device.
- Video editing: To adjust the resolution of an image to match the requirements of video editing software.
Here is how you can print coloured text in Terminal:
Preview of the output that you will get on running this code in your ide
In this solution we have used Imread function in python,
import cv2 img = cv2.imread('/home/img/python.png', cv2.IMREAD_UNCHANGED) print('Original Dimensions : ',img.shape) width = 350 height = 450 dim = (width, height) # resize image resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) print('Resized Dimensions : ',resized.shape) cv2.imshow("Resized image", resized) cv2.waitKey(0) cv2.destroyAllWindows()
- Copy the code using the "Copy" button above, and paste it in a Python file in your IDE.
- Modify the name, location of the image to be read in the code.
- Run the file to resize the image.
I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.
I found this code snippet by searching for " Re-Size the image in Open Cv using python" in kandi. You can try any such use case!
I have tested this solution in the following version. Be mindful of changes when working with other versions.
- This solution is created and executed in Python 3.7.15 version
- This solution is tested in Opencv 4.6.0 version
Using this solution we able to re size the image in python with the help of OpenCv library with simple steps. This process also facilities an easy to use, hassle free method to create a hands-on working version of code which would help us resize an image in Python.
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page.