# image channels are in BGR B = image[:, :, 0] G = image[:, :, 1] R = image[:, :, 2] # change the channel order from BGR to RGB and restore
时间: 2024-01-26 07:02:31 浏览: 35
To change the channel order from BGR to RGB and restore the image, you can use the following code:
```python
import cv2
# Load the image
image = cv2.imread("image.jpg")
# Split the channels
B = image[:, :, 0]
G = image[:, :, 1]
R = image[:, :, 2]
# Change the channel order from BGR to RGB and restore the image
image = cv2.merge([R, G, B])
# Display the restored image
cv2.imshow("Restored Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
In this code, we first load the image using the `cv2.imread()` function. Then, we split the channels into three separate arrays `B`, `G`, and `R`. After that, we change the channel order from BGR to RGB using the `cv2.merge()` function. Finally, we display the restored image using the `cv2.imshow()` function and wait for a key press before closing the window using the `cv2.waitKey()` and `cv2.destroyAllWindows()` functions.