Python Tensorflow至Arduino
我想把python数据发送到arduino。实际上,我可以用另一个代码发送它。沟通对我来说不是问题。Python Tensorflow至Arduino,python,tensorflow,opencv,arduino,tensorflow2.0,Python,Tensorflow,Opencv,Arduino,Tensorflow2.0,我想把python数据发送到arduino。实际上,我可以用另一个代码发送它。沟通对我来说不是问题。 我训练了一个模型来做两个标志(开和关)。当我显示on标志时,led将打开,当我显示off标志时,led将关闭。但我的问题是我不能呼叫信号和发送数据。如何在代码中调用符号?有人知道吗 我的代码: while True: ret, frame = cap.read() frame = cv2.flip(frame, 1) image_np = np.array(f
我训练了一个模型来做两个标志(开和关)。当我显示on标志时,led将打开,当我显示off标志时,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即可。呼叫符号是什么意思?据我所知,符号可以是
0
或1
,我为两个符号(开和关)训练了一个模型。我上传了签名图像。我想用我的手在网络摄像头上显示标志并控制arduino led。你想让你的模型在arduino上运行,还是将数据发送给arduino?我已经训练过模型。我只想当我在网络摄像头上显示时,arduino的led将亮起。是的,我想发送数据。我可以发送数据到arduino这里没有问题。我训练模特做双手手势。我的问题是当我在网络摄像头上显示arduinos led指示灯时。我试过那样的东西,但没用。如果(detections['detection\u classes']==“open”):ardinoserial.write('1.encode()),我想我是误传了自己。我想在屏幕上打印检测到的标志。啊,你想在运行tensorflow程序的机器的显示器上显示“打开”或“关闭”吗?如果是这种情况,那么请尝试pygame以获得简单的弹出窗口,您可以在其中绘制(或写入打开/关闭)。在我发布本文之前,我看到您正在使用opencv,并且可能已经打开了显示网络摄像头的窗口,在这种情况下,您可以在其中一个窗口中键入一些文本。