How to use opencv in Python3 to read file from file buffer

前端 未结 1 1504
甜味超标
甜味超标 2020-12-11 10:23

I am trying to use this library. In particular these 3 lines:

    image_stream = io.BytesIO(image_bytes)
    frame = cv2.imread(image_stream)
相关标签:
1条回答
  • 2020-12-11 10:44

    Here a solution:

    import io, requests, cv2, numpy as np
    
    url = "https://images.pexels.com/photos/236047/pexels-photo-236047.jpeg"
    img_stream = io.BytesIO(requests.get(url).content)
    img = cv2.imdecode(np.fromstring(img_stream.read(), np.uint8), 1)
    
    cv2.imshow("img", img)
    cv2.waitKey(0)
    
    0 讨论(0)
提交回复
热议问题