Debian Codegraph @

planetary_system_stacker/dark_flat_test.py

raw symbols SCIP
1 import matplotlib
2 matplotlib.use('Agg')
3 import matplotlib.pyplot as plt
4 from cv2 import VideoCapture, VideoWriter_fourcc, VideoWriter
5 from numpy import full, zeros, uint8, clip
6
7
8 def create_dark(dark):
9 dark[700:800, 700:800, :] += 15
10 return dark
11
12
13 def create_flat(image):
14 type = image.dtype
15 image[100:200, 100:200, :] = (image[100:200, 100:200, :] * 0.9).astype(type)
16 return image
17
18
19 original_video = 'Videos/short_video.avi'
20 processed_video = 'D:/SW-Development/Python/PlanetarySystemStacker/Examples/Darks_and_Flats/short_video_dark-flat-processed.avi'
21 video_dark = "D:/SW-Development/Python/PlanetarySystemStacker/Examples/Darks_and_Flats/artificial_dark.avi"
22 video_flat = "D:/SW-Development/Python/PlanetarySystemStacker/Examples/Darks_and_Flats/artificial_flat.avi"
23 ny = 960
24 nx = 1280
25
26 dark = create_dark(zeros((ny, nx, 3), uint8))
27 flat = (create_flat(full((ny, nx, 3), 128)) + dark).astype(uint8)
28
29 plt.imshow(dark)
30 plt.show()
31 plt.imshow(flat)
32 plt.show()
33
34 # Create the VideoCapture object.
35 cap = VideoCapture(original_video)
36 # Define the codec and create VideoWriter object
37 fourcc = VideoWriter_fourcc(*'XVID')
38 out = VideoWriter(processed_video, fourcc, 20.0, (nx, ny))
39 out_dark = VideoWriter(video_dark, fourcc, 20.0, (nx, ny))
40 out_flat = VideoWriter(video_flat, fourcc, 20.0, (nx, ny))
41
42 while (True):
43 # Capture frame-by-frame
44 ret, frame = cap.read()
45 if ret is True:
46 frame_flat_applied = create_flat(frame)
47 frame_dark_added = frame_flat_applied + dark
48 frame_processed = clip(frame_dark_added, 0, 255)
49 out.write(frame_processed)
50 out_dark.write(dark)
51 out_flat.write(flat)
52 else:
53 break
54
55 # When everything done, release the capture
56 cap.release()
57 out.release()
58 out_dark.release()
59 out_flat.release()