comment here

This commit is contained in:
ton
2023-03-18 20:19:39 +07:00
parent 4739e41362
commit 012fe5a8dd

View File

@@ -41,9 +41,11 @@ vecToDict(vec::Vector{UInt8}) = copy(JSON3.read(String(vec)))
_, frame_1 = webcam.read() # julia's PythonCall python-obj numpy array
# frame_1 = cv.imread("20.jpg")
_, buffer = cv.imencode(".jpg", frame_1)
# compress image data formats in order to make network transfer easier.
_, buffer = cv.imencode(".jpg", frame_1)
jpg_as_pyStr = base64.b64encode(buffer).decode("utf-8")
jpg_as_juliaStr = pyconvert(String, jpg_as_pyStr)
jpg_as_juliaStr = pyconvert(String, jpg_as_pyStr) # for base64, python string or julia string is the same
juliaDict = Dict("img"=> jpg_as_juliaStr)
publish(mqttClient, "sometopic", JSON3.write(juliaDict)) # mqtt publish
@@ -52,7 +54,7 @@ vecToDict(vec::Vector{UInt8}) = copy(JSON3.read(String(vec)))
# server - receive image #
# ---------------------------------------------------------------------------- #
img_str = payload["img"] # payload received thru mqtt
buf = base64.b64decode(juliaDict["img"])
buf = base64.b64decode(img_str)
buffer = np.frombuffer(buf, dtype=np.uint8)
frame_1 = cv.imdecode(buffer, 1)
frame_1_julia = pyconvert(Array, frame_1);