def __init__(self, video_path): self.cap = cv2.VideoCapture(video_path) self.height, self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)), int( self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)) self.resize_size = (int(self.width * resize_ratio), int(self.height * resize_ratio)) self.IP = HumanDetection(self.resize_size) if opt.out_video_path: self.out = cv2.VideoWriter(opt.out_video_path, fourcc, 10, store_size)
def __init__(self, path, queueSize=3000): self.path = path # self.video = UMatFileVideoStream(self.path, 128).start() # self.rgb = cv2.UMat(self.height, self.width, cv2.CV_8UC3) self.cap = cv2.VideoCapture(path) self.stopped = False # # initialize the queue used to store frames read from # # the video file self.Q = Queue(maxsize=queueSize) self.fgbg = cv2.createBackgroundSubtractorMOG2(history=500, varThreshold=200, detectShadows=False) self.height, self.width = int(self.cap.get( cv2.CAP_PROP_FRAME_HEIGHT)), int( self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)) self.resize_size = (int(self.width * resize_ratio), int(self.height * resize_ratio)) self.IP = HumanDetection(self.resize_size)
from src.human_detection import HumanDetection import cv2 import os from config.config import img_folder, gray import numpy as np IP = HumanDetection() if __name__ == '__main__': src_folder = img_folder dest_folder = src_folder + "_cut" os.makedirs(dest_folder, exist_ok=True) cnt = 0 for img_name in os.listdir(src_folder): cnt += 1 print("Processing pic {}".format(cnt)) frame = cv2.imread(os.path.join(src_folder, img_name)) kps, boxes, _ = IP.process_img(frame, gray=gray) img_rgb, img_black = IP.visualize() # cv2.imwrite(os.path.join(dest_folder, img_name), img) frame = img_black if boxes is not None: for idx, box in enumerate(boxes): x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int( box[3]) x1 = 0 if x1 < 0 else x1 y1 = 0 if y1 < 0 else y1 x2 = frame.shape[1] if x2 > frame.shape[1] else x2 y2 = frame.shape[0] if y2 > frame.shape[0] else y2 img = np.asarray(frame[y1:y2, x1:x2]) cv2.imshow("img", img)