CV2读取字节流

TypeError: Can't convert object of type 'PngImageFile' to 'str' for 'filename'

我用cv2进行图片处理的时候发现了一条报错

File "C:\Users\Administrator\xxxxxx\xxxxxx.py", line 57, in process_request
    position = get_postion(bk_img, slide_img)
  File "C:\Users\Administrator\xxxx\xxx.py", line 38, in get_postion
    target = cv2.imread(otemp, 0)
TypeError: Can't convert object of type 'PngImageFile' to 'str' for 'filename'

 

我写爬虫的过程中,从服务器请求了一张图片,为了方便我直接把图片的字节存到了变量里,直接传到了cv2进行处理,结果发现imread只支持读取本地文件,果断用另一个方法解决

 

cv2.imdecode(otemp, 0)

posted @ 2021-07-02 03:49  gainianyun  阅读(1755)  评论(0编辑  收藏  举报