This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pre_process(img): | |
""" Prepare image to be feed to a Keras convolutive model. | |
img: 3-channel Numpy array image of size. | |
Returns a resized and smoothed 250x70 RGB image. | |
""" | |
# Crop relevant area from input image | |
img = crop(img,600,1080,0,1800) | |
# Resize to model's input size (250,70) | |
img = cv2.resize(img,(250,70), interpolation = cv2.INTER_LANCZOS4)#INTER_CUBIC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get numpy array from matplotlib figure | |
target_map = get_figure(target_map, cmap='inferno').astype('uint8') | |
# Crop unnecessary regions from canvas | |
target_map = crop(target_map,9,63,33,232) | |
# Resize to original image size | |
target_map = cv2.resize(target_map,(1800,480), interpolation = cv2.INTER_CUBIC) | |
# Create a binary mask. You may want to change the binary threshold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create video writer | |
writer = cv2.VideoWriter("sample_output.avi", | |
cv2.VideoWriter_fourcc(*"MJPG"), | |
30,(1800,480)) | |
for frame in tqdm(merged_maps): | |
writer.write(frame.astype('uint8')) | |
writer.release() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert RGB to BGR. (optional) | |
dst_map = cv2.cvtColor(dst_map, cv2.COLOR_RGB2BGR) | |
# Add feature map and original image | |
merged_img = cv2.add(dst_map, cropped_img) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Default Python's libraries | |
import os | |
import numpy as np | |
import pandas as pd | |
from tqdm import tqdm | |
import keras.backend as K | |
# Graphic libraries |