letterbox BGR to RGB
时间: 2023-11-15 21:05:42 浏览: 139
LetterBox
To convert a BGR image to RGB in Python, you can use the following code:
```python
import cv2
bgr_img = cv2.imread('image.jpg')
rgb_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB)
cv2.imshow('BGR Image', bgr_img)
cv2.imshow('RGB Image', rgb_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
In this code, we first read the BGR image using the `cv2.imread()` function. Then, we convert it to RGB using the `cv2.cvtColor()` function and specifying the conversion flag `cv2.COLOR_BGR2RGB`. Finally, we display both the BGR and RGB images using the `cv2.imshow()` function and wait for a keystroke using the `cv2.waitKey()` function. The `cv2.destroyAllWindows()` function is used to close all windows.
阅读全文