import cv2 cv2.namedWindow("output", cv2.WINDOW_AUTOSIZE) # Create window with freedom of dimensions im = cv2.imread("earth.jpg") # Read image imS = cv2.resize(im, (960, 540)) # Resize image cv2.imshow("output", imS) # Show image cv2.waitKey(0) # Display the image infinitely until any keypress
Here is what the above code is Doing:
1. We create a window named output with the cv2.WINDOW_AUTOSIZE flag. This is so that the window can adjust to the size of the image.
2. We read the image into a variable named im.
3. We resize the image to 960×540 pixels and store it in a variable named imS.
4. We display the image in the output window.
5. We wait for a keypress and then close the window.