update
This commit is contained in:
20
test_recv.py
20
test_recv.py
@@ -1,21 +1,35 @@
|
||||
import serial_module
|
||||
import cv2
|
||||
import numpy as np
|
||||
import time
|
||||
|
||||
serial_module.init("/dev/ttyUSB1")
|
||||
serial_module.init("/dev/ttyUSB0")
|
||||
while True:
|
||||
try:
|
||||
# time.sleep(1);
|
||||
data = serial_module.receive()
|
||||
if data == None:
|
||||
continue
|
||||
# print("Received data:", data)
|
||||
if data:
|
||||
print(f"size of data: {len(data)}")
|
||||
frame = np.frombuffer(data, np.uint8)
|
||||
# 将数据转换为图像
|
||||
print(2)
|
||||
image = cv2.imdecode(frame, cv2.IMREAD_COLOR)
|
||||
|
||||
print(f"Image shape: {image.shape}")
|
||||
|
||||
print(3)
|
||||
# 显示图像
|
||||
cv2.imshow('Received Image', image)
|
||||
# cv2.imshow('Received Image', image)
|
||||
# print(4)
|
||||
cv2.imwrite('test_recv.jpg', image)
|
||||
print(5)
|
||||
# 等待按键输入
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
pass
|
||||
except Exception as e:
|
||||
print("Error:", e)
|
||||
# print("Error:", e)
|
||||
pass
|
||||
Reference in New Issue
Block a user