OpenCV Display Image: cv2.imshow() Guide

One way to display images in OpenCV is to use the cv2.imshow() function. Here is an example code using this function:

import cv2

# 读取图片
img = cv2.imread('image.jpg')

# 显示图片
cv2.imshow('Image', img)

# 等待键盘输入
cv2.waitKey(0)

# 关闭窗口
cv2.destroyAllWindows()

In the above code, the function cv2.imshow() is used to display an image, where the first parameter is the name of the window and the second parameter is the image to display. cv2.waitKey(0) is used to wait for keyboard input, with the parameter 0 indicating an infinite wait until any key is pressed. Lastly, cv2.destroyAllWindows() is used to close all windows.

bannerAds