# Draw it on image rect = self._frame_rect(box) blob = Blob(f"{self.name}:{str(i)}", rect, fps=self.fps.fps()) blobs.append(blob) i += 1 except Exception as e: print(f"model {self.name}: tracking exit Exception: {e}") self.blobs.track_blobs(blobs) self.fps.update() def clear(self): super(CamShift, self).clear() # clear selected tracing boxes self.boxes.clear() self.boxes_hist.clear() if __name__ == '__main__': cam = Camera(device=0).start() model = CamShift() cam.register_models(model) # test Model instance cam.test()
87: 'scissors', 88: 'teddy bear', 89: 'hair drier', 90: 'toothbrush' } def detect(self, image): # grab the frame dimensions and convert it to a blob image = image if len(image.shape) == 3 else cv2.cvtColor( image, cv2.COLOR_GRAY2BGR) roi = self._init_roi(image) h, w = roi.shape[:2] # pass the blob through the webcam and obtain the detections and predictions blob = cv2.dnn.blobFromImage(roi, size=(300, 300), swapRB=True) self.net.setInput(blob) blobs = self.net_blobs(h, w) self.blobs.track_blobs(blobs) self.fps.update() if __name__ == '__main__': cam = Camera(device=1, sync=False).start() cam_plus = CamPlus(camera=cam) model = Caffe() # test Model instance cam_plus.register_models(model) cam_plus.test()
self.hog = cv2.HOGDescriptor() self.hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) def detect(self, image): blobs = [] image = image if len(image.shape) == 3 else cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) roi = self._init_roi(image) roi_rectangles, w = self.hog.detectMultiScale(roi, winStride=(8, 8), padding=(32, 32), scale=1.05) for i, roi_rect in enumerate(roi_rectangles): rect = self._frame_rect(roi_rect) blob = Blob(f"{self.name}:{str(i)}", rect, fps=self.fps.fps()) blobs.append(blob) self.blobs.track_blobs(blobs) self.fps.update() if __name__ == '__main__': video = ["airport.mp4", "weco.mp4", "count1.mp4", "overpass.mp4", "cars.mp4", "walk.avi", "run.mp4"] v0 = f"{CWD}//data//Sample//videos//{video[5]}" cam = Camera(device=v0).start() cam_plus = CamPlus(camera=cam) model = HOGDescriptor() # test Model instance cam_plus.register_models(model) cam_plus.test()
# for nose detect # if abs(w / 2 - x2 - w2 / 2) < 20: rect = self._frame_rect(eye) blob = Blob(f"eye:{str(j)}", rect, fps=self.fps.fps()) blobs.append(blob) self.blobs.track_blobs(blobs) self.fps.update() # face-mask detect and sound alert count = [] for blob in self.blobs.blobs: if 'eye' in blob.label: count.append(blob.age) self.bool_alert = True if len(count) < 2 else False if __name__ == '__main__': # camera instance, started before assigning to Model cam = Camera(device=1).start() cam_plus = CamPlus(camera=cam) # assigning camera to Model model = CascadeClassifier() # test Model instance cam_plus.register_models(model) cam_plus.test()