You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
797 B
Python
24 lines
797 B
Python
# Copyright (C) 2021 Intel Corporation
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
import hashlib
|
|
import cv2 as cv
|
|
from av import VideoFrame
|
|
|
|
def rotate_image(image, angle):
|
|
height, width = image.shape[:2]
|
|
image_center = (width/2, height/2)
|
|
matrix = cv.getRotationMatrix2D(image_center, angle, 1.)
|
|
abs_cos = abs(matrix[0,0])
|
|
abs_sin = abs(matrix[0,1])
|
|
bound_w = int(height * abs_sin + width * abs_cos)
|
|
bound_h = int(height * abs_cos + width * abs_sin)
|
|
matrix[0, 2] += bound_w/2 - image_center[0]
|
|
matrix[1, 2] += bound_h/2 - image_center[1]
|
|
matrix = cv.warpAffine(image, matrix, (bound_w, bound_h))
|
|
return matrix
|
|
|
|
def md5_hash(frame):
|
|
if isinstance(frame, VideoFrame):
|
|
frame = frame.to_image()
|
|
return hashlib.md5(frame.tobytes()).hexdigest() # nosec |