Skip to content
Snippets Groups Projects
Commit d7cfe300 authored by Erlend Sørhus's avatar Erlend Sørhus
Browse files

Merge branch 'ViBe'

parents c071a368 8798c5a2
No related branches found
No related tags found
No related merge requests found
......@@ -3,5 +3,5 @@
### Meeting with NINA: 24.01 15:00
### Working Mondays & Thursdays 10:00 - 15:00
Testing Git push
test
# Expecting two lists of several pairs representing the start and end of each interval.
# EXAMPLE:
# Observed: [ (3, 4), (5, 9), (6, 11) ]
# True: [ (2, 4), (5, 10), (10, 12) ]
def calculateSuccess(observedIntervalsList, trueIntervalsList):
# List of success rates / similarity indices per observed interval.
indices = []
for obsInt in observedIntervalsList:
# Calculates the similarity index by considering the index of each observed interval with respect to how many true intervals are overlapping it.
# This means they are initially overweighted (producing indices that are too low), which is fixed by multiplying by the count of overlaps.
obsIntIndex = 0
overlappingTrueInts = 0
for i in range(len(trueIntervalsList)):
# Checks if true interval overlaps with observed. No bias in direction, meaning observed interval too low has same error as too high.
# Can be changed by adding more if statements based on the condition, so that having observed intervals too high is punished less than too low.
if not (obsInt[0] > trueIntervalsList[i][1] or obsInt[1] < trueIntervalsList[i][0]):
overlappingTrueInts += 1
intersection = min(obsInt[1], trueIntervalsList[i][1]) - max(obsInt[0], trueIntervalsList[i][0])
union = max(obsInt[1], trueIntervalsList[i][1]) - min(obsInt[0], trueIntervalsList[i][0])
obsIntIndex += intersection / union
if overlappingTrueInts > 0:
obsIntIndex *= overlappingTrueInts
indices.append(obsIntIndex)
# Pads with zeroes if there is an excess of true intervals that do not overlap with any observed intervals.
while len(indices) < len(trueIntervalsList):
indices.append(0)
print(indices)
def main():
test = ((101, 167), (480, 520), (700, 710))
real = ((70, 180), (300,400), (500, 510), (705, 720))
calculateSuccess(test, real)
if __name__ == "__main__":
main()
from moviepy.editor import VideoFileClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from os import listdir
from time import sleep
import os
import csv
import logging
import sys
import ffmpeg
# Logger for logging purposes (seeing which file is currently being processed)
logFormat = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(stream = sys.stdout,
filemode = "w",
format = logFormat,
level = logging.INFO)
# Trims input video file according to interval of timestamps given in CSV.
# Uses ffmpeg-python, which builds a command-line call to ffmpeg that trims parts and finally concatenates them.
# Does NOT delete input video file yet.
def trim(inputVideo, csvTimestamps):
paddingSecs = 1
movieClip = VideoFileClip(inputVideo)
trims = []
# Pads intervals with an extra second, and checks for edge cases.
for timestampNo in range(0, len(csvTimestamps)-1, 2):
startTime = int(csvTimestamps[timestampNo]) - paddingSecs
endTime = int(csvTimestamps[timestampNo+1]) + paddingSecs
if startTime < 0:
startTime = 0
if endTime > movieClip.duration:
endTime = movieClip.duration
# Trims the source video for each interval. 'setpts' filter is used so timestamps are handled correctly; without it,
# still frames will appear in the final video, as it trims based on closest keyframes and fills the gap with stills.
trims.append(ffmpeg.input(inputVideo).trim(start=startTime, end=endTime).filter('setpts', expr='PTS-STARTPTS'))
(
ffmpeg
.concat(*trims)
.filter('setpts', expr='PTS-STARTPTS')
.output("trimmed/%s" % inputVideo)
.run(quiet=False)
)
def main():
# Changes working directory to the specified path. CHANGE DURING STANDALONE BUILD.
os.chdir("gitlab repo/nina-thesis")
if "trimmed" not in os.listdir():
os.mkdir("trimmed")
while(True):
for file in os.listdir():
if file.endswith(".csv"):
with open(file) as csvFile:
reader = csv.reader(csvFile, delimiter=",")
for row in reader:
logging.getLogger().info("Trimming file %s" % row[0])
trim(row[0], row[1:])
sleep(900)
if __name__ == "__main__":
main()
testingDetection.mp4, 101, 167, 480, 520, 700, 710
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment