comment here

This commit is contained in:
ton
2023-03-18 21:01:58 +07:00
parent 012fe5a8dd
commit 26aa35c4b9

View File

@@ -27,7 +27,7 @@ vecToDict(vec::Vector{UInt8}) = copy(JSON3.read(String(vec)))
# https://pyshine.com/Video-and-bidirectional-text-streaming/
using CondaPkg; CondaPkg.add_pip("pybase64"); CondaPkg.add_pip("opencv-python"); CondaPkg.add("jsons"); CondaPkg.add("numpy");
using PythonCall
cv = pyimport("cv2")
cv2 = pyimport("cv2")
base64 = pyimport("pybase64")
np = pyimport("numpy")
@@ -39,10 +39,10 @@ vecToDict(vec::Vector{UInt8}) = copy(JSON3.read(String(vec)))
webcam = cv2.VideoCapture(0)
_, frame_1 = webcam.read() # julia's PythonCall python-obj numpy array
# frame_1 = cv.imread("20.jpg")
# cv2_bgr_img = cv2.imread("20.jpg")
# compress image data formats in order to make network transfer easier.
_, buffer = cv.imencode(".jpg", frame_1)
_, buffer = cv2.imencode(".jpg", cv2_bgr_img)
jpg_as_pyStr = base64.b64encode(buffer).decode("utf-8")
jpg_as_juliaStr = pyconvert(String, jpg_as_pyStr) # for base64, python string or julia string is the same
@@ -56,7 +56,7 @@ vecToDict(vec::Vector{UInt8}) = copy(JSON3.read(String(vec)))
img_str = payload["img"] # payload received thru mqtt
buf = base64.b64decode(img_str)
buffer = np.frombuffer(buf, dtype=np.uint8)
frame_1 = cv.imdecode(buffer, 1)
frame_1 = cv2.imdecode(buffer, 1)
frame_1_julia = pyconvert(Array, frame_1);
img_julia_RGB = imageUtils.np2juliaImage(frame_1_julia)