Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It looks like opencv swaps the blue and red channels?

Tags:

opencv

enter image description here

I am new to opencv. I found the following code swaps red and blue channel when I fed sRGB png to it. Which function should I blame, imread or fromarray?

like image 877
dom free Avatar asked Sep 11 '25 00:09

dom free


2 Answers

Yes, OpenCV follows BGR color convention internally. However, you may either use cv2.cvtColor(img, cv2.COLOR_BGR2RGB) before displaying your image using a third party function(display() in this case). Or you can also use cv2.imshow() method to debug images, which doesn't require cv2.cvtColor()

like image 149
ZdaR Avatar answered Sep 13 '25 08:09

ZdaR


Rather simple option would be swapping the R and B channels:

img = img[:, :, ::-1]
like image 38
Jeru Luke Avatar answered Sep 13 '25 09:09

Jeru Luke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!