检测到边界框时如何向 arduino 发送命令?



我正在研究一个检测用户并跟随的机器人。 我正在使用来自暗流存储库的 YOLOv2 作为对象检测模块。

截至目前,我想制作Arduino微控制器,以便在检测到时将机器人向前移动到边界框。没有距离或立体摄像头。只是如果检测到边界框,然后驱动电机前进。

这是我通过相机检测边界框的代码。 如果有人可以将我引导到任何资源或教程的正确路径,那将很有帮助。谢谢。

import cv2
from darkflow.net.build import TFNet
import numpy as np
import time
options = {
'model': 'cfg/yolov2.cfg',
'load': 'bin/yolov2.weights',
'threshold': 0.8,
'gpu': 0.8
}
tfnet = TFNet(options)
colors = [tuple(255 * np.random.rand(3)) for _ in range(10)]
capture = cv2.VideoCapture(0)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
stime = time.time()
ret, frame = capture.read()
if ret:
results = tfnet.return_predict(frame)
for color, result in zip(colors, results):
tl = (result['topleft']['x'], result['topleft']['y'])
br = (result['bottomright']['x'], result['bottomright']['y'])
label = result['label']
confidence = result['confidence']
text = '{}: {:.0f}%'.format(label, confidence * 100)
frame = cv2.rectangle(frame, tl, br, color, 5)
frame = cv2.putText(frame, text, tl, cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)
cv2.imshow('frame', frame)
print('FPS {:.1f}'.format(1 / (time.time() - stime)))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()

如果我能得到边界的中心位置,那将会很有帮助 箱

由于边界框的左上角和右下角,中心是两个位置的平均值。

如何向 arduino 发送命令?

通过Arduino的虚拟COM端口使用串行通信。 网上有一百万个教程。

https://www.arduino.cc/reference/en/language/functions/communication/serial/

https://pyserial.readthedocs.io/en/latest/

https://www.instructables.com/id/Interface-Python-and-Arduino-with-pySerial/

最新更新