📜  cv2.imshow (1)

📅  最后修改于: 2023-12-03 15:14:24.463000             🧑  作者: Mango

Introduction to cv2.imshow

cv2.imshow is a method in the OpenCV library that allows you to display images on the screen. It is a simple way to visualize your image processing results and debug your code.

Syntax:
cv2.imshow(window_name, image)

Arguments:

  • window_name: Name of the window to display the image in.
  • image: The image to be displayed.

Returns:

  • This method does not return anything.

Example:

import cv2

img = cv2.imread("image.jpg")

# Create a window
cv2.namedWindow("Image", cv2.WINDOW_NORMAL)

# Display Image
cv2.imshow("Image", img)

# Wait for any key to be pressed
cv2.waitKey(0)

# Destroy all windows
cv2.destroyAllWindows()

The above code opens an image, creates a window for it, displays it, waits for any key to be pressed and then closes all the windows.

Additional Information:
  • To modify the size of the window, use the cv2.WINDOW_NORMAL flag while creating the window.
  • It is recommended to destroy all the windows using cv2.destroyAllWindows() at the end of the program to release all resources.