foreground = cv2.GaussianBlur(foreground, (5, 5), 0) # It would be better to apply morphological opening to the result to remove the noises foreground = cv2.morphologyEx(foreground, cv2.MORPH_OPEN, (3, 3)) foreground = cv2.morphologyEx(foreground, cv2.MORPH_CLOSE, (3, 3)) ret, foreground_thresh = cv2.threshold(foreground, self.trackbar.value[0], 255.0, cv2.THRESH_BINARY) # move_points = cv2.countNonZero(roi_thresh_image) # this is total difference number blobs = self.contour_blobs(foreground_thresh) 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_diff2frame = Diff2frame() model_background = Background() cam_plus.register_models(model_background) # cam_plus.register_models(model_diff2frame, model_background) # test Model instance cam_plus.test()
# # # # text = "{} ({})".format('QR', ) # # cv2.putText(image, f'QR ({str(self.code_data)})', # # (hull[0][0], hull[0][1] - 10), # # cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # # return image def clear(self): # clear detected Blobs super(BarCode, self).clear() # clear bar code initial data self.code_data, self.code_points = None, None print(f"Model {self.name}: bar code data cleared") if __name__ == '__main__': # camera instance, started before assigning to Model cam = Camera(device=0).start() cam_plus = CamPlus(camera=cam) # assigning camera to Model model = BarCode() # test Model instance cam_plus.register_models(model) # test Model instance cam_plus.test()
cv2.putText(image, f"{distance:.2f}", foot[i], cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 1) if self.left_lane is not None: draw(self.left_lane, self.left_foot) if self.right_lane is not None: draw(self.right_lane, self.right_foot) # image1 * α + image2 * β + λ # image1 and image2 must be the same shape. return image def clear(self): super(Lane, self).clear() # clear lane initial data self.left_lane, self.right_lane = None, None self.left_foot, self.right_foot = None, None print(f"Model {self.name}: Lanes data cleared") if __name__ == '__main__': cam = Camera(device=0).start() cam_plus = CamPlus(camera=cam) model_lane = Lane() model_color = Color() # test Model instance cam_plus.register_models(model_lane, model_color) cam_plus.test()