sorry i can ask for help, i'm having trouble solving my code where i have to detect object only on green line, and if object outside green line it can't be detected. can anyone help me... thanks, all input welcome... enter image description here
import cv2
import numpy as np
thres = 0.50
classNames = []
classFile = 'data/coco.names'
with open(classFile, 'rt') as f:
classNames = f.read().rstrip("\n").split("\n")
configPath = 'data/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightsPath = 'data/frozen_inference_graph.pb'
net = cv2.dnn_DetectionModel(weightsPath, configPath)
net.setInputSize(320, 320)
net.setInputScale(1.0 / 127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
cap = cv2.VideoCapture('data.mp4')`
`
while True:
ret, img = cap.read()
classIds, confs, bbox = net.detect(img, confThreshold=thres)
area = [(30, 200), (220, 200), (160, 120), (130, 120)]
if len(classIds) != 0:
for classId, confidence, box in zip(classIds.flatten(), confs.flatten(), bbox):
(x, y, x2, y2) = box
class_name = classNames[classId-1]
if class_name in ["car", "truck"]:
cv2.rectangle(img, box, color=(0, 255, 0), thickness=1)
cv2.putText(img, class_name, (box[0]+2, box[1]+10), cv2.FONT_HERSHEY_COMPLEX, 0.3, (0, 255, 0), 1)
cv2.putText(img, str(round(confidence*100, 2)),(box[0]+20, box[1]+30), cv2.FONT_HERSHEY_COMPLEX, 0.3, (0, 255, 0), 1)
cv2.polylines(img, [np.array(area, np.int32)], True, (15, 220, 20), 1)
cv2.imshow('video', img)
if cv2.waitKey(1) == 27:
break
cv2.destroyAllWindows()