未验证 提交 8fc815f0 编写于 作者: 走神的阿圆's avatar 走神的阿圆 提交者: GitHub

Delete requirement of cv2. (#769)

上级 5ff9b7b3
......@@ -7,4 +7,3 @@ flask >= 1.1.1
Flask-Babel >= 1.0.0
six >= 1.14.0
protobuf >= 3.11.0
opencv-python
......@@ -14,7 +14,6 @@
# =======================================================================
from visualdl.proto.record_pb2 import Record
import numpy as np
import cv2
from PIL import Image
......@@ -66,10 +65,18 @@ def imgarray2bytes(np_array):
Returns:
Binary bytes of np_array.
"""
np_array = cv2.cvtColor(np_array, cv2.COLOR_BGR2RGB)
ret, buf = cv2.imencode(".png", np_array)
img_bin = Image.fromarray(np.uint8(buf)).tobytes("raw")
try:
import cv2
np_array = cv2.cvtColor(np_array, cv2.COLOR_BGR2RGB)
ret, buf = cv2.imencode(".png", np_array)
img_bin = Image.fromarray(np.uint8(buf)).tobytes("raw")
except ImportError:
import io
im = Image.fromarray(np_array)
with io.BytesIO() as fp:
im.save(fp, format='png')
img_bin = fp.getvalue()
return img_bin
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册