我正在使用Tensorflow对象检测API来检测respberry pi上的对象,它是实时的对象检测,并且我让它工作得很好。它可以绘制带有标签的边界框和它检测到的类的会议分数。所以我的问题是:
当检测到特定的类时,我如何将GPIO引脚设置为高,假设特定的类是“person”,而我希望引脚11为高,我该如何做?
下面是我认为相关的代码:
# Perform the actual detection by running the model with the image as input
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: frame_expanded})
# Draw the results of the detection (aka 'visulaize the results')
vis_util.visualize_boxes_and_labels_on_image_array(
frame,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=3,
min_score_thresh=0.40)
cv2.putText(frame,"FPS: {0:.2f}".format(frame_rate_calc),(30,50),font,1,(255,255,0),2,cv2.LINE_AA)
# All the results have been drawn on the frame, so it's time to display it.
cv2.imshow('Object detector', frame)np.squeeze(classes).astype(np.int32)可能是获取检测到的类的一种方法吗?
发布于 2019-02-28 19:40:57
您可以通过/sys/class/gpio接口控制GPIO。在我的例子中,我使用了另一个嵌入式系统。但它的工作原理应该大同小异。我正在使用bash命令。但是您可以很容易地将它们替换为Python文件操作。
ubuntu@localhost:/sys/class/gpio$ ls
export gpiochip1008 gpiochip1016 gpiochip890 unexport可以有多个gpio接口。要使用这些接口:
启用前两位
echo 1008 > export
echo 1009 > export这将为新IO文件创建一个编号:
root@localhost:/sys/class/gpio# ls -al
total 0
drwxr-xr-x 2 root root 0 Feb 11 17:05 .
drwxr-xr-x 45 root root 0 Feb 11 16:45 ..
--w------- 1 root root 4096 Feb 11 17:08 export
lrwxrwxrwx 1 root root 0 Feb 11 16:53 gpio1008 -> ../../devices/soc0/amba_pl/41200000.gpio/gpiochip1/gpio/gpio1008
lrwxrwxrwx 1 root root 0 Feb 11 17:02 gpio1009 -> ../../devices/soc0/amba_pl/41200000.gpio/gpiochip1/gpio/gpio1009
--w------- 1 root root 4096 Feb 11 17:05 unexport将输出方向设置为'out‘('in’是默认值)
echo out > gpio1008/direction
echo out > gpio1009/direction使大头针升高:
echo 1 > gpio1016/value
echo 1 > gpio1017/value发布于 2019-02-28 20:10:35
您可以使用.3或其他方法过滤检测分数。如果检测类在过滤后的索引中包含该类,则可以将high发送到pin
from gpiozero import LED
led = LED(11) #pin you plug led
filter=0.3 #filter of scores if you decrease it program finds more item
selected_class=4 #you want to find class
isledhigh=False
...
makeledhigh=False
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: frame_expanded})
for i in range(int(num[0])):
if classes[i]==selected_class and scores[i]>=filter:
makeledhigh=True
if makeledhigh and !isledhigh:
led.on()
isledhigh=True
if isledhigh and !makeledhigh:
led.off()
isledhigh=False发布于 2019-02-28 20:19:35
代码非常简单:
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(13, GPIO.OUT, initial=GPIO.LOW)
if object_detected_class==1:
GPIO.output(11, GPIO.HIGH)
else: #other class
GPIO.output(13, GPIO.HIGH)https://stackoverflow.com/questions/54924733
复制相似问题