![opencv resize image opencv resize image](https://blog.zuru.tech/images/image-resizing/circle_comparison.png)
Since we know that our image is 647 pixels wide, let’s resize it and make it 100 pixels wide: # we need to keep in mind aspect ratio so the image does This little may be a bit confusing if you’re just getting started with OpenCV and is important to keep in mind. Our image is actually 647 pixels wide and 388 pixels tall, implying that the height is the first entry in the shape and the width is the second. Looking at the shape of the matrix, we may think that our image is 388 pixels wide and 647 pixels tall. However, when working with images this can become a bit confusing since we normally specify images in terms of width x height. When we write matrices, it is common to write them in the form (# of rows x # of columns) - which is the same way you specify the matrix size in NumPy. This means that the image has 388 rows, 647 columns, and 3 channels (the RGB components). When executing this code, we see that (388, 647, 3) is outputted to our terminal. We can examine the dimensions of the image by using the shape attribute of the image, since the image is a NumPy array after-all: # print the dimensions of the image Let’s resize this image and make it much smaller. Just loading and displaying an image isn’t very interesting. Using a parameter of “0” indicates that any keypress will un-pause the execution. Finally, a call to waitKey pauses the execution of the script until we press a key on our keyboard. The second parameter is a reference to the image we loaded off disk on Line 5. The first parameter is a string, the “name” of our window. Line 6 and 7: A call to imshow displays the image on our screen.The imread functions returns a NumPy array, representing the image itself. Line 5: We are now loading the image off of disk.Line 2: The first line is just telling the Python interpreter to import the OpenCV package.Image = cv2.imread("jurassic-park-tour-jeep.jpg")Įxecuting this Python snippet gives me the following result on my computer: Figure 2: Loading and Displaying the Jurassic Park tour jeep.Īs you can see, the image is now displaying. You’ll need it to start playing with some of the Python and OpenCV sample code.įirst, let’s load the image and display it on screen: # import the necessary packages
#Opencv resize image download#
Go ahead and download this image to your computer. If you need help installing OpenCV, check out the quick start guides on the OpenCV website.Ĭontinuing my obsession with Jurassic Park let’s use the Jurassic Park tour jeep as our example image to play with: Figure 1: Our example image - a Jurassic Park Tour Jeep. I’m also going to assume that you have OpenCV installed.
#Opencv resize image how to#
This example will run on Python 2.7 and OpenCV 2.4.X/OpenCV 3.0+.įor this introduction to basic image processing, I’m going to assume that you have basic knowledge of how to create and execute Python scripts.
#Opencv resize image code#
Looking for the source code to this post? Jump Right To The Downloads Section