def main(): args = parse_args() tracker = Tracker(path=args.path, showResult=True, saveData=args.saveData, border=10) cap = cv2.VideoCapture(args.input) bbox = None objectID = args.id if args.output is not None: fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter(os.path.join(args.output, args.id + '.avi'), fourcc, 30.0, (1280, 720)) while True: ret, frame = cap.read() if not ret: break frame = cv2.resize(frame, dsize=(1280, 720)) key = cv2.waitKey(1) & 0xFF tracked_frame, bbox = tracker.update(frame, objectID, bbox) cv2.imshow('image', frame) if args.output is not None: out.write(frame) if key == ord('s'): bbox = cv2.selectROI('image', frame, fromCenter=False) tracker.init(frame, bbox) print('Selected {}'.format(bbox)) continue if key == ord('q'): break cap.release() cv2.destroyAllWindows() if args.output is not None: out.release()
boxes.append([x, y, w, h]) # 배열로 계속 넣어줌. confidences.append(float(confidence)) indexes = cv2.dnn.NMSBoxes(boxes, confidences, min_confidence, 0.4) # 박스 중복을 줄여주는 거. for i in range(len(boxes)): if i in indexes: x, y, w, h = boxes[i] rects.append([x, y, x+w, y+h]) # 이 박스안에 중복된 내용이 있을수도 없을수도. label = '{:,.2%}'.format(confidences[i]) cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 1) # 박스처리해줌. cv2.putText(frame, label, (x + 5, y + 15), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1) # use Tracker objects = tracker.update(rects) total = len(objects) # loop over the trackable objects # 아디하고 centroid 좌표가 온다. for (objectID, centroid) in objects.items(): # check if a trackable object exists with the object ID # 트랙킹 되고 있는 알고리즘. trackable = trackables.get(objectID, None) # 아디 값 오면 trackable이라는 객체가 생성됨. if trackable is None: trackable = Trackable(objectID, centroid) # store the trackable object in our dictionary trackables[objectID] = trackable