在Raspberry Pi上集成/连接对象检测(网络摄像头)4

发布于 2025-01-29 17:12:17 字数 1137 浏览 3 评论 0原文

我正在尝试使用Python语言进行对象检测程序,并希望将其连接到Raspberry Pi的GPIO。

for code in decode(frame):
        decoded_data = code.data.decode("utf-8")
        rect_pts = code.rect
        print("\nID:", code.data.decode("utf-8"))
        
        if decoded_data in reg_qr:
            infoOut = 'Authorized'
            bbColor = (0,255,0)
            
        else:
            infoOut = 'Un-Authorized'
            bbColor = (0,0,255)
        
        pts = np.array([code.polygon], np.int32)
        cv2.polylines(frame, [pts], True, bbColor, 3)
        cv2.putText(frame, infoOut, (rect_pts[0], rect_pts[1]), cv2.FONT_HERSHEY_SIMPLEX, 1, bbColor,3)

那就是Python代码段。 根据算法,它运行良好。但是,当我想使用此语法驾驶伺服器时,我

if decoded_data in reg_qr:
            angle = 90
            servo1.ChangeDutyCycle(2+(angle/18))
            servo1.ChangeDutyCycle(0)
            time.sleep(2)

if distance <= 5.01:
            angle = 90
            servo1.ChangeDutyCycle(2+(angle/18))
            time.sleep(2)
            servo1.ChangeDutyCycle(0)

认为这与用超声波传感器的输入驾驶伺服器相同。原来我错了。有人知道解决方案吗?

I'm trying an object detection program using Python language, and want to connect it to the Raspberry Pi's GPIO.

for code in decode(frame):
        decoded_data = code.data.decode("utf-8")
        rect_pts = code.rect
        print("\nID:", code.data.decode("utf-8"))
        
        if decoded_data in reg_qr:
            infoOut = 'Authorized'
            bbColor = (0,255,0)
            
        else:
            infoOut = 'Un-Authorized'
            bbColor = (0,0,255)
        
        pts = np.array([code.polygon], np.int32)
        cv2.polylines(frame, [pts], True, bbColor, 3)
        cv2.putText(frame, infoOut, (rect_pts[0], rect_pts[1]), cv2.FONT_HERSHEY_SIMPLEX, 1, bbColor,3)

That is the Python code snippet.
It runs fine, according to the algorithm. But when I want to drive the servo with this syntax, I can't

if decoded_data in reg_qr:
            angle = 90
            servo1.ChangeDutyCycle(2+(angle/18))
            servo1.ChangeDutyCycle(0)
            time.sleep(2)

if distance <= 5.01:
            angle = 90
            servo1.ChangeDutyCycle(2+(angle/18))
            time.sleep(2)
            servo1.ChangeDutyCycle(0)

I think it would be the same as driving the servo with the input from the ultrasonic sensor. Turns out I was wrong. Anyone know the solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文