To read an image and convert it to BGR color format in Python, you can use the OpenCV library. Here's an example code snippet:
main.py179 chars8 lines
In the code above, we first load the image into a grayscale format using the cv2.imread()
function. This function takes the filename of the image as input, as well as a flag indicating the format in which to read the image (in this case, grayscale).
Next, we use the cv2.cvtColor()
function to convert the grayscale image to BGR color format. This function takes the input image and a flag indicating the conversion type as input (in this case, cv2.COLOR_GRAY2BGR
indicates that we want to convert from grayscale to BGR).
The resulting img_bgr
variable will contain the image data in BGR color format, which you can then use for further image processing tasks.
gistlibby LogSnag