21 lines
632 B
Python
21 lines
632 B
Python
import serial_module
|
|
import cv2
|
|
import numpy as np
|
|
|
|
serial_module.init("/dev/ttyUSB1")
|
|
while True:
|
|
try:
|
|
data = serial_module.receive()
|
|
# print("Received data:", data)
|
|
if data:
|
|
frame = np.frombuffer(data, np.uint8)
|
|
# 将数据转换为图像
|
|
image = cv2.imdecode(frame, cv2.IMREAD_COLOR)
|
|
# 显示图像
|
|
cv2.imshow('Received Image', image)
|
|
cv2.imwrite('test_recv.jpg', image)
|
|
# 等待按键输入
|
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
break
|
|
except Exception as e:
|
|
print("Error:", e) |