Created
October 20, 2020 08:43
-
-
Save aliyevorkhan/e53f10e0c28a9f689e1477b71bc1ad4f to your computer and use it in GitHub Desktop.
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
import os | |
import cv2 | |
src_path = os.path.abspath(os.path.join(os.getcwd(), "bolu_tunnel_nvr")) | |
print(src_path) | |
ch1_dst_path = os.path.abspath(os.path.join(os.getcwd(), "ch1")) | |
ch2_dst_path = os.path.abspath(os.path.join(os.getcwd(), "ch2")) | |
print(ch1_dst_path) | |
print(ch2_dst_path) | |
all_files = os.listdir(src_path) | |
print(all_files) | |
ch1_videos = [] | |
ch2_videos = [] | |
print('[INFO] Reading ch1 videos..') | |
print(50*'-') | |
print() | |
for file in all_files: | |
if file.startswith('Ch1'): | |
ch1_videos.append(file) | |
else: | |
ch2_videos.append(file) | |
print('[INFO] Done!') | |
print(50*'*') | |
print() | |
print('[INFO] Processing ch1 videos..') | |
print(50*'*') | |
print() | |
for video in ch1_videos: | |
cap = cv2.VideoCapture(os.path.join(src_path, video)) | |
i = 0 | |
counter = 0 | |
while cap.isOpened(): | |
ret, frame = cap.read() | |
if not ret: | |
print('[INFO] {'+video+'} completed!') | |
print(50*'-') | |
print() | |
break | |
if counter % 10 == 0: | |
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
cv2.imwrite(ch1_dst_path+'/'+video.split('.')[0]+'_'+str(i)+'.jpg',gray_frame) | |
i+=1 | |
counter +=1 | |
cap.release() | |
#cv2.destroyAllWindows() | |
print('[INFO] Done!') | |
print(50*'*') | |
print() | |
print('[INFO] Reading ch2 videos..') | |
print(50*'*') | |
print() | |
for video in ch2_videos: | |
cap = cv2.VideoCapture(os.path.join(src_path, video)) | |
i = 0 | |
counter = 0 | |
while cap.isOpened(): | |
ret, frame = cap.read() | |
if not ret: | |
print('[INFO] {'+video+'} completed!') | |
print(50*'-') | |
print() | |
break | |
if counter % 10 == 0: | |
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
cv2.imwrite(ch2_dst_path+'/'+video.split('.')[0]+'_'+str(i)+'.jpg',gray_frame) | |
i+=1 | |
counter +=1 | |
cap.release() | |
#cap.destroyAllWindows() | |
print('[INFO] Done!') | |
print(50*'*') | |
print() | |
print('[INFO] Dataset is ready!') | |
print(50*'*') | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment