Tensorflow to Arduino



我想向arduino发送数据python。事实上,我可以用另一个代码发送。沟通对我来说不是问题。我为两个标志(开和关(训练了一个模型。当我显示在标志上时,led会打开,当我显示标志时,led就会关闭。但我的问题是我不能呼叫标志和发送数据。如何用代码调用标志?有人知道吗?偏离标志

我的代码:

while True: 

ret, frame = cap.read()
frame = cv2.flip(frame, 1)
image_np = np.array(frame)
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections = detect_fn(input_tensor)

num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy()
for key, value in detections.items()}
detections['num_detections'] = num_detections
# detection_classes should be ints.
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
label_id_offset = 1
image_np_with_detections = image_np.copy()

viz_utils.visualize_boxes_and_labels_on_image_array(
image_np_with_detections,
detections['detection_boxes'],
detections['detection_classes']+label_id_offset,
detections['detection_scores'],
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=1,
min_score_thresh=.5,
agnostic_mode=False)   

cv2.imshow('object detection',  cv2.resize(image_np_with_detections, (800, 600)))

if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
ArduinoSerial.close() 
break

如果你试图让python代码来控制Arduino,一种简单的方法可能是串行的。我在这里找到了一个很好的讨论,他们谈到需要PySerial,所以要准备好至少需要安装一个额外的库。

你可以发送任何你想要的东西到Arduino(通过串行(,当Arduino接收到串行数据时,它可以简单地切换其末端的led。

最新更新