60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
import cv2
|
|
import os
|
|
import math
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
# Create the temp dir
|
|
if not os.path.exists('data'):
|
|
os.makedirs('data')
|
|
|
|
# Define the color spaces
|
|
Red_lower2 = np.array([,100,100])
|
|
Red_upper2 = np.array([,255,255])
|
|
Red_lower1 = np.array([0,100,100])
|
|
Red_upper1 = np.array([6,255,255])
|
|
Orange_lower = np.array([7,100,100])
|
|
Orange_upper = np.array([22,255,255])
|
|
Yellow_lower = np.array([23,100,100])
|
|
Yellow_upper = np.array([32,255,255])
|
|
Green_lower = np.array([33,100,100])
|
|
Green_upper = np.array([75,255,255])
|
|
Cyan_lower = np.array([76,100,100])
|
|
Cyan_upper = np.array([97,255,255])
|
|
Blue_lower = np.array([93,100,100])
|
|
Blue_upper = np.array([130,255,255])
|
|
Purple_lower = np.array([130,100,100])
|
|
Purple_upper = np.array([,255,255])
|
|
Pink_lower = np.array([,100,100])
|
|
Pink_upper = np.array([,255,255])
|
|
White_lower = np.array([,100,100])
|
|
White_upper = np.array([,255,255])
|
|
Black_lower = np.array([,100,100])
|
|
Black_upper = np.array([,255,255])
|
|
|
|
# loop through video files
|
|
videopath = '/media/vm/HDD/freeloops/3D/'
|
|
imagepath = 'data/'
|
|
videos = os.listdir(videopath)
|
|
for video in videos:
|
|
cap = cv2.VideoCapture(videopath + video)
|
|
framerate = cap.get(cv2.CAP_PROP_FPS)
|
|
while cap.isOpened():
|
|
frameId = cap.get(1)
|
|
ret, frame = cap.read()
|
|
if not ret:
|
|
break
|
|
if frameId % math.floor(framerate) == 0:
|
|
filename = imagepath + "/screenshot_" + str(int(frameId)) + ".jpg"
|
|
cv2.imwrite(filename, frame)
|
|
del cap
|
|
# analyze each screenshot for colors
|
|
images = os.listdir(imagepath)
|
|
for image in images:
|
|
cap = cv2.imread(imagepath + image, cv2.COLOR_BGR2HSV)
|
|
plt.imshow(cap)
|
|
|
|
|
|
|
|
# move video file according to results
|