python imread
时间: 2023-09-10 14:06:23 浏览: 92
The `imread` function in Python is used to read an image file and convert it into a NumPy array. It is part of the OpenCV library and can read various image formats such as PNG, BMP, JPEG, TIFF, etc.
Here is an example of how to use `imread` function:
```python
import cv2
# Read image file
img = cv2.imread('image.jpg')
# Display image
cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
In this example, we are reading an image file called `image.jpg` using the `imread` function and storing it in the variable `img`. We then display the image using the `imshow` function and wait for a key to be pressed before closing the window using the `waitKey` and `destroyAllWindows` functions.
Note that the `imread` function returns a NumPy array of the image pixels in BGR format. If you want to display the image in RGB format, you can use the `cvtColor` function to convert the color space.
阅读全文