How to convert the arithmetic color to its RGB counterpart?

When using an RGB color (255.0,0.0,0.0) (red) in openCV the output is blue instead.

import cv2
import matplotlib.pyplot as plt

plt.plot([1,2,3,4] ,  color=[1.0, 0.0, 0.0])
plt.savefig('tester.png')
img = cv2.imread('tester.png')
m_img = (cv2.line(img,(0,0),(100,100),(255.0,0.0,0.0),5))
cv2.imwrite('./update.png', m_img)

tester.png :

enter image description here

update.png :

enter image description here

How to modify line m_img = (cv2.line(img,(0,0),(100,100),(255.0,0.0,0.0),5)) so that same RGB line colour from plt.plot([1,2,3,4] , color=[1.0, 0.0, 0.0]) is drawn ?

1 answer

  • answered 2018-07-18 22:02 wim

    OpenCV uses BGR, not RGB. Swap the 0 and 2 channels.

    m_img = (cv2.line(img,(0,0),(100,100),(255.0,0.0,0),5))  # blue line
    m_img = (cv2.line(img,(0,0),(100,100),(0,0.0,255.0),5))  # red line