It can be done by
- opening the file using
open()
, which supports Unicode as in the linked answer,
- read the contents as a byte array,
- convert the byte array to a NumPy array,
- decode the image
# -*- coding: utf-8 -*-
import cv2
import numpy
stream = open(u'D:\?\handschuh.jpg', "rb")
bytes = bytearray(stream.read())
numpyarray = numpy.asarray(bytes, dtype=numpy.uint8)
bgrImage = cv2.imdecode(numpyarray, cv2.IMREAD_UNCHANGED)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…