Commit c7f78f80 authored by Mia Fornes's avatar Mia Fornes
Browse files

labels

parent c759ddb3
%% Cell type:code id: tags:
```
import cv2 # for capturing videos
import math # for mathematical operations
import os
```
%% Cell type:code id: tags:
```
count = 0
for root, directories, files in os.walk("video-data"):
for file in files:
videoFile = "video-data/" + file
print(videoFile)
cap = cv2.VideoCapture(videoFile) # capturing the video from the given path
frameRate = cap.get(cv2.CAP_PROP_FPS) / 100 # returns frame rate divided by hundred
while cap.isOpened():
frameId = cap.get(1) #current frame number
ret, frame = cap.read()
if (ret != True):
break
if (frameId % math.floor(frameRate) == 0):
filename ="video-frames/frame%d.jpg" % count;count+=1
cv2.imwrite(filename, frame)
cap.release()
print ("Done!")
```
%% Output
video-data/front_regular_1.avi
video-data/front_regular_2.avi
video-data/front_regular_3.avi
video-data/front_regular_4.avi
video-data/ranheim_snow_1.avi
video-data/ranheim_snow_2.avi
video-data/ranheim_snow_3.avi
video-data/ranheim_snow_4.avi
video-data/ranheim_snow_5.avi
video-data/ranheim_snow_rear_1.avi
video-data/ranheim_snow_rear_2.avi
video-data/ranheim_snow_rear_3.avi
video-data/rear_regular_1.avi
video-data/rear_regular_2.avi
video-data/rear_regular_3.avi
video-data/rear_regular_4.avi
Done!
%% Cell type:code id: tags:
```
print(frameId)
print(frameRate)
print(math.floor(frameRate))
print(frameId % math.floor(frameRate))
```
%% Output
810.0
6.0
6
0.0
2983.0\n3.0\n3\n1.0
%% Cell type:code id: tags:
```
count = 1767
for root, directories, files in os.walk("new-video-data"):
for file in files:
videoFile = "new-video-data/" + file
print(videoFile)
cap = cv2.VideoCapture(videoFile) # capturing the video from the given path
frameRate = cap.get(cv2.CAP_PROP_FPS) / 10 # returns frame rate divided by hundred
while cap.isOpened():
frameId = cap.get(1) #current frame number
ret, frame = cap.read()
if (ret != True):
break
if (frameId % math.floor(frameRate) == 0):
filename ="new-video-frames/frame%d.jpg" % count;count+=1
cv2.imwrite(filename, frame)
cap.release()
print ("Done!")
```
%% Output
new-video-data/front_light-intersection_3_Trim.avi
new-video-data/front_light_intersection_1_Trim.avi
new-video-data/front_light_intersection_2_Trim.avi
new-video-data/front_light_intersection_4_1_Trim.avi
new-video-data/front_light_intersection_4_2_Trim.avi
new-video-data/front_light_intersection_4_Trim.avi
new-video-data/front_regular_5.avi
new-video-data/rear_regular_5_301_Trim.avi
Done!
%% Cell type:code id: tags:
```
count = 4646
for root, directories, files in os.walk("empty-road-vid"):
for file in files:
videoFile = "empty-road-vid/" + file
print(videoFile)
cap = cv2.VideoCapture(videoFile) # capturing the video from the given path
frameRate = cap.get(cv2.CAP_PROP_FPS) / 10 # returns frame rate divided by hundred
while cap.isOpened():
frameId = cap.get(1) #current frame number
ret, frame = cap.read()
if (ret != True):
break
if (frameId % math.floor(frameRate) == 0):
filename ="empty-road-frames/frame%d.jpg" % count
txt = "empty-road-frames/frame%d.txt" % count
count+=1
cv2.imwrite(filename, frame)
open(txt, 'a').close()
cap.release()
print ("Done!")
```
%% Cell type:code id: tags:
```
count = 5762
for root, directories, files in os.walk("new-video-data-2"):
for file in files:
videoFile = "new-video-data-2/" + file
print(videoFile)
cap = cv2.VideoCapture(videoFile) # capturing the video from the given path
frameRate = cap.get(cv2.CAP_PROP_FPS) / 10 # returns frame rate divided by hundred
while cap.isOpened():
frameId = cap.get(1) #current frame number
ret, frame = cap.read()
if (ret != True):
break
if (frameId % math.floor(frameRate) == 0):
filename ="new-video-frames-2/frame%d.jpg" % count
count+=1
cv2.imwrite(filename, frame)
open(txt, 'a').close()
cap.release()
print ("Done!")
```
%% Output
new-video-data-2/ranheim_front_4.avi
new-video-data-2/ranheim_rear_3.avi
new-video-data-2/ranheim_sun_front_1.avi
new-video-data-2/ranheim_sun_front_2.avi
new-video-data-2/ranheim_sun_front_3.avi
new-video-data-2/ranheim_sun_rear_1.avi
new-video-data-2/ranheim_sun_rear_2.avi
Done!
%% Cell type:code id: tags:
```
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment