| 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 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
cap = VideoCapture(filename) |
| 40 |
|
| 41 |
|
| 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) |