import serial_module import cv2 import numpy as np import time 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) # 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) pass