convert openCV image into PIL Image in Python (for use with Zbar library)

后端 未结 4 652
长发绾君心
长发绾君心 2021-02-05 01:18

I\'m trying to use the Zbar library\'s QR code detection methods on images I extract with OpenCV\'s camera methods. Normally the QR code detection methods work with images (jpg,

4条回答
  •  Happy的楠姐
    2021-02-05 01:56

    A simple way is to directly swap the channels. Suppose you are trying to convert a 3-channel image file between OpenCV format and PIL format. You can just use:

    img[...,[0,2]]=img[...,[2,0]]
    

    In this way, you won't be bothered with cv2.cvtColor as this function only works on images with certain depth.

提交回复
热议问题