Coverage for skcvideo/video_incrustation.py: 45%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-02 14:10 +0200

1import cv2 

2import numpy as np 

3 

4from skcvideo.video_capture import StoredImagesVideoCapture 

5 

6 

7class VideoIncrustation(StoredImagesVideoCapture): 

8 def __init__(self, video_path, box=None, **kwargs): 

9 if box is None: 

10 box = [0, 575, 720, 575 + 1280] 

11 self.box = box 

12 colormap = kwargs.get("colormap", "bgr") 

13 super().__init__(video_path, colormap=colormap, **kwargs) 

14 self.max_frame = self.get_max_frame() 

15 

16 def build(self, *args, **kwargs): 

17 pass 

18 

19 def get_image(self, frame): 

20 if frame >= self.max_frame: 

21 y1, x1, y2, x2 = self.box 

22 box_height, box_width = y2 - y1, x2 - x1 

23 image = np.zeros((box_height, box_width, 3), dtype=np.uint8) 

24 else: 

25 image = self.seek(frame).copy() 

26 return image 

27 

28 def process_image(self, image, frame): 

29 return image 

30 

31 def incrust_image(self, big_image, image): 

32 y1, x1, y2, x2 = self.box 

33 box_height, box_width = y2 - y1, x2 - x1 

34 im_height, im_width = image.shape[:2] 

35 if im_height != box_height or im_width != box_width: 

36 image = cv2.resize(image, (box_width, box_height)) 

37 big_image[y1:y2, x1:x2, :] = image 

38 

39 def refresh(self, big_image, frame): 

40 image = self.get_image(frame) 

41 image = self.process_image(image, frame) 

42 self.incrust_image(big_image, image)