why cv2.imwrite() changes the color of pics?

前端 未结 2 1625
温柔的废话
温柔的废话 2020-12-23 11:26

I have the following piece of code:

imgs = glob.glob(\'/home/chipin/heart/tray.png\')
current_img = io.imread(imgs[0])
cv2.imwrite(\'/home/chipin/heart/01.pn         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 12:02

    The image on input (as a png) is in RGB order but the image in memory (as a cv::Mat) is in BGR order. Use cv2.imread() for input. So, imread() will internally convert from rgb to bgr and imwrite() will do the opposite, all under the hood.

    Here's how you do it:

    current_img = cv2.imread('/home/chipin/heart/tray.png')
    cv2.imwrite('/home/chipin/heart/01.png', current_img)  
    

提交回复
热议问题