import cv2 from video_loader import VideoLoader from background_heatmap import BackgroundHeatmap import numpy as np if __name__ == '__main__': params = cv2.SimpleBlobDetector_Params() params.minThreshold = 60 params.maxThreshold = 255 # Filter by Area. params.filterByArea = True params.minArea = 20 params.maxArea = 25000 params.filterByCircularity = False params.filterByColor = False params.filterByConvexity = False params.filterByInertia = False params.blobColor = 255 detector = cv2.SimpleBlobDetector_create(params) projects_path = "C:\\UntrackedGit\\opencv_test\\him_projects" loader = VideoLoader(projects_path) groups = loader.get_recordings_grouped() # out = cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourc\c('M','J','P','G'), 30, (512, 424), isColor=False) for group in groups: heatmaps = [] for recording in group[1]: first = True frames = VideoLoader.extract_frames(recording) bgh = BackgroundHeatmap(VideoLoader.extract_frames(recording)) for frame in frames: bgh.update(frame) cv2.imshow("IR", frame) # out.write(converted) # cv2.imshow("Heatmap", heatmap.heatmap) cv2.imshow("Background filter", bgh.lastframe) diff = bgh.bgf_diff # Erode dilate kernel = np.ones((5,5),np.uint8) diff = cv2.morphologyEx(diff, cv2.MORPH_OPEN, kernel) keypoints = detector.detect(diff) frame_with_keypoints = cv2.drawKeypoints(diff, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) cv2.imshow("BGF diff", frame_with_keypoints) cv2.moveWindow("Background filter", 600, 100) cv2.moveWindow("BGF diff", 1200, 100) if cv2.waitKey(1) & 0xFF == ord('q'): break heatmaps.append(bgh.heatmap) cv2.destroyAllWindows() for i, bgh in enumerate(heatmaps): imname = "Heatmap " + str(i) cv2.imshow(imname, bgh) cv2.moveWindow(imname, 500 * i, 0) cv2.waitKey(2000) cv2.destroyAllWindows() # out.release() cv2.destroyAllWindows()