code for python script and servo give below :(link to entire code https://github.com/aswinr22/waste-model ... camera2.py)
Code: Select all
(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=8,
min_score_thresh=0.40)
for i in range (classes.size): # here is my classes id is retrieved
if(classes[0][i] == 2 and scores[0][i]>0.5): # this is my condition , if class id =2 then servo should workThis is the servo code:
Code: Select all
import RPi.GPIO as GPIO
import time
servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
p.start(2.5) # Initialization
try:
p.ChangeDutyCycle(5)
time.sleep(4)
p.ChangeDutyCycle(10)
time.sleep(4)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()
How to combine these both code to work the servo whenever my class id =2 detected