2

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?

  • 1
    Check this [link]https://stackoverflow.com/questions/72260457/cv2-drawcontoursframe-c-1-0-255-0-1-opencv-showing-error-nameerror-name You needed to add GPIO. – toyota Supra May 18 '22 at 02:55
  • @toyotaSupra In this case I have to use the object class name to drive the servo. Will it be the same? It seems his/her program is a little different from mine. But still I'm stuck :v – Irham Khalifah Putra May 18 '22 at 10:49
  • @toyotaSupra You know ANPR/ALPR to open the gate automatically? The gate will open if the detected number plate is registered in the system/program. That's roughly what I meant – Irham Khalifah Putra May 18 '22 at 10:54
  • Yes. I know about it. Actually, I haven't used yet. I don't have gate in my house. I am thinking about matching template. – toyota Supra May 18 '22 at 11:00
  • Ah, okay. I'm also still looking for a similar reference. Hopefully we can find the solution. Thank you very much for your help! – Irham Khalifah Putra May 18 '22 at 11:25

0 Answers0