Commit 2dc76a7e authored by Mia Fornes's avatar Mia Fornes
Browse files

added some test frames

parent 9cd242f6
%% 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
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_rear_1.avi
Done!
%% Cell type:code id: tags:
```
count = 0
for root, directories, files in os.walk("test-data"):
for file in files:
videoFile = "test-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 ="test-data-frames/test_frame%d.jpg" % count
count+=1
cv2.imwrite(filename, frame)
open(txt, 'a').close()
cap.release()
print ("Done!")
```
%% Output
test-data/ranheim_sun_front_3.avi
Done!
%% Cell type:code id: tags:
```
count = 0
file_name_length = len("test_frame")
for root, directories, files in os.walk("test-data-frames"):
for file in files:
if file.endswith(".jpg"):
count += 1
frames = "test-data-frames/" + file
txt_file = frames[:-4] + ".txt"
if not os.path.exists(txt_file):
with open(txt_file, 'w+') as f:
f.write('0 0 0 0 0')
f.close()
else:
continue
print ("Done!")
```
%% Output
Done!
%% Cell type:code id: tags:
```
```
......
import tensorflow as tf
import numpy as np
"""
with open("test-data-frames/test_frame44.txt", 'r') as file:
data = file.read().splitlines()
line_count = len(data)
yo = []
for line in data:
_, xc, yc, w, h = line.split(' ')
#line_count += 1
#print("xc %s yc %s w %s h %s" % (xc, yc, w, h))
xmin = int((float(xc) - float(w) / 2) * 608)
xmax = int((float(xc) + float(w) / 2) * 608)
ymin = int((float(yc) - float(h) / 2) * 480)
ymax = int((float(yc) + float(h) / 2) * 480)
if xmin < 0:
xmin = 0
if xmax > 608 - 1:
xmax = 608 - 1
if ymin < 0:
ymin = 0
if ymax > 480 - 1:
ymax = 480 - 1
yo.append([xmin, ymin, xmax, ymax])
yo.append(tf.constant([xc, yc, w, h]))
print(tf.convert_to_tensor(yo))
print(line_count)
"""
y = np.zeros((1,1,1))
y[0][0:2] = 1
print(y)
y = tf.convert_to_tensor(y)
print(y)
0 0.106481 0.562500 0.049383 0.070833
0 0.114969 0.566667 0.050926 0.070833
0 0.127315 0.571875 0.060185 0.081250
0 0.141204 0.577083 0.069444 0.087500
0 0.158951 0.586458 0.077160 0.102083
0 0.179784 0.592708 0.087963 0.106250
0 0.210648 0.606250 0.106481 0.133333
0 0.247685 0.620833 0.137346 0.145833
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