我试图在Python程序中插入一个图像,但我不知道如何将图像链接到代码,以便在代码运行后查看它。我对python很陌生,我在Mac电脑上有3.9.7版。
提前感谢任何能帮我解决问题的人。
你好,盖亚。
发布于 2022-04-30 17:40:50
您可以将OpenCV用于此https://learnopencv.com/read-display-and-write-an-image-using-opencv/
您需要首先安装库,在终端pip install opencv-python上运行以下命令
# import the cv2 library
import cv2
# The function cv2.imread() is used to read an image.
img_grayscale = cv2.imread('test.jpg',0)
# The function cv2.imshow() is used to display an image in a window.
cv2.imshow('graycsale image',img_grayscale)
# waitKey() waits for a key press to close the window and 0 specifies indefinite loop
cv2.waitKey(0)
# cv2.destroyAllWindows() simply destroys all the windows we created.
cv2.destroyAllWindows()
# The function cv2.imwrite() is used to write an image.
cv2.imwrite('grayscale.jpg',img_grayscale)发布于 2022-04-30 17:54:16
https://stackoverflow.com/questions/72070725
复制相似问题