python opencv轉換bytesio

ShellCollector發表於2019-03-04

 

opencv bytesio

轉不轉bytesio,opencv都能讀取文字成圖片:

str_encode opencv也能解析

def a():
    path='d:/1.jpg'
    for i in range(10):

        img=cv2.imread(path)

        start=time.time()

        img_encode = cv2.imencode('.jpg', img)  # 可以看出第二個元素是矩陣 print(img_encode)
        str_encode = img_encode[1].tostring()
        buf_str = BytesIO(str_encode).getvalue()

        encode_t=time.time()-start
        nparr = np.fromstring(buf_str, np.uint8)
        img_decode = cv2.imdecode(nparr, 1)
        print('time', encode_t, time.time() - start)
        # cv2.imshow('',img_decode)
        # cv2.waitKey(1)

 

相關文章