in generate_side_by_side_standalone.py [0:0]
def remove_orange_frames(video):
"""Removes orange frames."""
try:
from matplotlib import pyplot as plt
except:
print("Missing matplotlib, please install")
raise
allframes = []
orange_pixind = 0
orange_frameind = 0
frame_count = 0
check_for_orange = True
while video.isOpened():
ret, frame = video.read()
if ret:
# Convert to gray to simplify the process
allframes.append(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY))
# Check if it's orange still
if check_for_orange:
frame = allframes[-1]
histo, _, _ = plt.hist(np.asarray(frame).flatten(), bins=255)
maxi = np.argmax(histo)
if not orange_pixind:
if maxi > 130:
continue
orange_pixind = maxi
elif maxi == orange_pixind:
orange_frameind = frame_count
else:
check_for_orange = False
frame_count += 1
else:
video.release()
break
return allframes[orange_frameind:], orange_frameind