Python | cv2 imshow()方法

时间:2020-02-23 14:42:14  来源:igfitidea点击:

在本教程中,我们将看到如何使用Python将图像显示为使用Python作为CV2(计算机Vision)库存在的开放式CV。

我们可以用 imshow()的方法 cv2库在窗口中显示图像。
要使用CV2库,我们需要使用CV2库使用 import statement

现在让我们看看cv2的语法和返回值 imshow()方法,然后我们将继续执行示例。

语法

cv2.imshow(win_name,image)

参数

我们需要将两个参数传递给imwrite()方法。
参数是:1) win_name:将显示图像的窗口的名称。
2) image:该图像的图像像素矩阵,需要显示该图像。

返回值

None

返回值

让我们看看Python代码:

# import computer vision library(cv2) in this code
import cv2
 
# main code
if __name__ == "__main__" :
 
    # mentioning absolute path of the image
    img_path = "C:\Users\user\Desktop\flower.jpg"
 
    # read or load an image
    image = cv2.imread(img_path)
 
    # show the image on the newly created image window
    cv2.imshow('image window',image)

如我们所见,将打开一个窗口以显示图像。
窗口大小取决于图像的大小。
如果窗口大小大于屏幕分辨率,则它显示图像的缩放版本。