Debian Codegraph @

planetary_system_stacker/Test_programs/detect_bayer.py

raw symbols SCIP
1 import matplotlib
2 matplotlib.use('Agg')
3 import matplotlib.pyplot as plt
4 from cv2 import VideoCapture, cvtColor, COLOR_RGB2GRAY
5 from numpy import uint8, uint16
6
7 from frames import detect_bayer, detect_rgb_bgr
8
9
10 def show_image(frame, comment):
11 """
12 Use Matplotlib to show a given frame.
13
14 :param frame: Color or B/W image.
15 :param comment: Text string (to be displayed as window title)
16 :return: -
17 """
18 print(comment + ", shape: " + str(frame.shape) + ", type: " + str(frame.dtype))
19
20 # If image is 16bit, reduce it to 8bit for display.
21 if frame.dtype == uint16:
22 frame_shown = (frame >> 8).astype(uint8)
23 else:
24 frame_shown = frame
25
26 plt.title(comment)
27 if len(frame_shown.shape) == 3:
28 plt.imshow(frame_shown)
29 else:
30 plt.imshow(frame_shown, cmap='gray')
31 plt.show()
32
33
34 filename = 'D:\SW-Development\Python\PlanetarySystemStacker\Examples\AVI_Chris-Garry\\20110929_005012_jupiter_gbrg_DIB.avi'
35 # filename = 'D:\SW-Development\Python\PlanetarySystemStacker\Examples\Saturn\sat_c11_ser_F0001-1731_short.avi'
36 # filename = 'D:/SW-Development/Python/PlanetarySystemStacker/Examples/Moon_2018-03-24/another_short_video.avi'
37
38 # Create the VideoCapture object.
39 cap = VideoCapture(filename)
40
41 # Read the first frame.
42 ret, first_frame_read = cap.read()
43 show_image(first_frame_read, "First frame of Video")
44
45 frames_bayer_max_noise_diff_green = 2.
46 frames_bayer_min_distance_from_blue = 99.5
47 frames_color_difference_threshold = 0
48 debayer_code = detect_bayer(first_frame_read, frames_bayer_max_noise_diff_green,
49 frames_bayer_min_distance_from_blue,
50 frames_color_difference_threshold)
51 print ("Debayer code found: " + debayer_code)
52
53 if debayer_code == 'Color':
54 rgb_order = detect_rgb_bgr(first_frame_read)
55 print ("Color order detected: " + rgb_order)