Пример #1
0
def identify_actors(video_path, clf, clf_th, out_name):

	""" Identifies the actors using a classifier and generates an output video

	Arguments:
	----------
		video_path:
			type: string
			info: path to where the video is stored

		clf:
			type: FaceRecognizer object
			info: trained classifier to identify faces

		clf_th:
			type: int / float
			info: threshold to identify a face as 'Unknown'

		out_name:
			type: string
			info: name of the generated video file
	"""

	video = cv2.VideoCapture(video_path)

	# The new generated video is prepared to be saved
	video_w = int(video.get(3))
	video_h = int(video.get(4))
	video_fps = int(video.get(5))

	out_path = compute_path(out_name + '.mp4', 'video')
	out = cv2.VideoWriter(
		filename=out_path,
		fourcc=cv2.VideoWriter_fourcc('X', '2', '6', '4'),
		fps=video_fps,
		frameSize=(video_w, video_h)
	)

	not_finished, frame = video.read()
	while not_finished:

		# Modify the frame for each detected face
		frame = modify_frame(frame, clf, clf_th)

		# Write the frame into the new video file
		out.write(frame)
		not_finished, frame = video.read()

	video.release()
	out.release()
Пример #2
0
def save_image(image, output_folder, output_name):
    """ Stores the given image in the output path with the output name

	Arguments:
	----------
		image:
			type: PIL image
			info: image to store

		output_path:
			type: string
			info: folder to store the image

		output_name:
			type: string
			info: name of the image file
	"""

    folder_path = compute_path(output_folder, 'dataset')
    os.makedirs(folder_path, exist_ok=True)

    file_path = os.path.join(folder_path, output_name + '.png')
    image.save(file_path)
Пример #3
0
 def testComputePath(self):
     self.assertEqual('dc=example,dc=com', utils.compute_path('OU=somewhere,DC=example,DC=com'))
     self.assertEqual('', utils.compute_path('DC=com'))