I've a video of 3 minutes, and in that video I have 10-15 different object that can be detected using my model.
I can get the total of the object in one frame, but I would like to increment each time a new object detect.
for example in the first 30 seconds 3 persons detect, and then after 15 seconds another 2 persons detect, I would like to sum up this into totalcount = 5 persons and save into csv files etc.
those few lines of the code would count the detect object continuously but i would like to increment each object that counted.
final_count = [] filescore = np.squeeze(scores) count = 0 for i in range(100): if scores is None or filescore[i] > 0.5: count = count + 1 final_count.append(count) ymin = int(max(1,(boxes[i][0] * imH))) xmin = int(max(1,(boxes[i][1] * imW))) ymax = int(min(imH,(boxes[i][2] * imH))) xmax = int(min(imW,(boxes[i][3] * imW)))
cv2.rectangle(frame, (xmin,ymin), (xmax,ymax), (10, 255, 0), 2)
# Draw label
object_name = category_index[int(classes[i])]['name'] # Look up object name from "labels" array using class index
label = '%s: %d%%' % (object_name, int(scores[i]*100)) # Example: 'person: 72%'
labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2) # Get font size
label_ymin = max(ymin, labelSize[1] + 10) # Make sure not to draw label too close to top of window
cv2.rectangle(frame, (xmin, label_ymin-labelSize[1]-10), (xmin+labelSize[0], label_ymin+baseLine-10), (255, 255, 255), cv2.FILLED) # Draw white box to put label text in
cv2.putText(frame, label, (xmin, label_ymin-7), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 2) # Draw label text
if(len(new_name)> 0):
cv2.putText (frame,'Total Detections : ' + str(count),(10,25),cv2.FONT_HERSHEY_SIMPLEX,1,(70,235,52),2,cv2.LINE_AA)
cv2.imshow("loading videos", frame)
#print('These are total', total_object)
if cv2.waitKey(1) & 0xFF == ord('q'):
break`
I tried both way. but I didnt get how I can increment each object that has been detect it.