Exemple #1
0
def test_remove_extension():
    f1 = removeExtension("dfjhskhfefjhkjsfe.mp4") == "dfjhskhfefjhkjsfe"
    f2 = removeExtension("3iz5böovulz.mkv") == "3iz5böovulz"
    f3 = removeExtension("jdjfhgsekbc47i.webm") == "jdjfhgsekbc47i"
    f4 = removeExtension("aei3ucoröiu3.mov") == "aei3ucoröiu3"
    f5 = removeExtension("adjfhsluhw3o.avi") == "adjfhsluhw3o"

    assert f1 and f2 and f3 and f4 and f5
Exemple #2
0
def download_list(l, options, logger: Logger, index=1, list_count=1):
    """downloads list l with options"""
    videos_without_format_avail = []
    keep_file = options.get("keep_file", False)
    options.pop("keep_file", None)
    try:
        with youtube_dl.YoutubeDL(options) as ydl:
            for i in l:
                logger.debug(
                    f"[{str(l.index(i) + 1)}/{str(index + 1)}/{str(list_count)}] downloading {i}",
                    options.get("verbose", False))
                ydl.download([i])
    except DownloadError:
        videos_without_format_avail.append(i)
        video_format = options["format"]
        del options["format"]
    finally:
        with youtube_dl.YoutubeDL(options) as ydl:
            for i in videos_without_format_avail:
                video_name = "notafile.txt"
                ydl.download([i])
                files = os.listdir()
                files.sort()
                for i in files:
                    if not utils.is_video(i):
                        files.pop(files.index(i))
                    else:
                        video_name = i
                os.system("ffmpeg -i '" + video_name + "' '" +
                          removeExtension(video_name) + "." + video_format +
                          "'")
                if not keep_file and video_name != "notafile.txt":
                    os.remove(video_name)
def matlab2PointCorrespondences(filename):
    '''Loads and converts the point correspondences saved 
    by the matlab camera calibration tool'''
    from numpy.lib.io import loadtxt, savetxt
    from numpy.lib.function_base import append
    points = loadtxt(filename, delimiter=',')
    savetxt(utils.removeExtension(filename)+'-point-correspondences.txt',append(points[:,:2].T, points[:,3:].T, axis=0))
 def __init__(self,
              name,
              startTime,
              duration,
              cameraView,
              databaseFilename=None,
              virtual=False):
     '''startTime is passed as string in utils.datetimeFormat, eg 2011-06-22 10:00:39
     duration is a timedelta object'''
     self.name = name
     if isinstance(startTime, str):
         self.startTime = datetime.strptime(startTime, datetimeFormat)
     else:
         self.startTime = startTime
     self.duration = duration
     self.cameraView = cameraView
     if databaseFilename is None and len(self.name) > 0:
         self.databaseFilename = removeExtension(self.name) + '.sqlite'
     else:
         self.databaseFilename = databaseFilename
     self.virtual = virtual
import numpy as np

import cv
import utils
import cvutils
import ubc_utils
import moving

# use something like getopt to manage arguments if necessary

if len(sys.argv) < 3:
    print('Usage: {0} <video-filename> <n-objects>'.format(sys.argv[0]))
    sys.exit()

if sys.argv[1].endswith('.avi'):
    videoFilenamePrefix = utils.removeExtension(sys.argv[1],'.')
else:
    videoFilenamePrefix = sys.argv[1]

objectNum = int(sys.argv[2])

objects = ubc_utils.loadTrajectories(videoFilenamePrefix+'-objects.txt', objectNum+1)
obj = objects[objectNum]
features = ubc_utils.loadTrajectories(videoFilenamePrefix+'-features.txt', max(obj.featureNumbers)+1)
h = np.loadtxt(videoFilenamePrefix+'-homography.txt')

invh = cvutils.invertHomography(h)

def computeGroundTrajectory(features, homography, timeInterval = None):
    '''Computes a trajectory for the set of features as the closes point to the ground
    using the homography in image space'''
Exemple #6
0
def AddPlaylistToPlaylist(title, image, url, mode, isFirst=False):
    src = url

    playlist = []
    root     = ''

    while not sfile.exists(src):
        loc = utils.getDownloadLocation()

        client = utils.GetClient() + s3.DELIMETER        
        dst    = os.path.join(loc, url.replace(client, ''))

        if sfile.exists(dst):
            if utils.DialogYesNo(GETTEXT(30101), GETTEXT(30100)):
                src = dst
                break
            else:
                utils.delete(dst, APPLICATION)

        src = urllib.quote_plus(src)
        src = s3.getURL(src)
        src = s3.convertToCloud(src)
        src = utils.GetHTML(src, maxAge=7*86400)

        src = src.replace('\r', '')
        src = src.split('\n')

        content = ''
        root    = 'AMAZON@'

        for video in src:
            if len(video.strip()) > 0:
                content += root
                content += video
                content += '\r\n'
        sfile.write(dst, content)

        src  = utils.removeExtension(url)
        root = utils.removeExtension(dst)

        plotFile = root + '.%s' % DSC
        plot     = utils.getAmazonContent(url, DSC)
        sfile.write(plotFile, plot)

        imageTypes = IMG_EXT
        imageTypes.append('.gif')

        for ext in imageTypes: 
            image = src + ext
            image = s3.getURL(urllib.quote_plus(image))
            image = s3.convertToCloud(image)

            utils.DownloadIfExists(image, root+ext)


        return AddPlaylistToPlaylist(title, image, dst, mode, isFirst)

    playlist = utils.getPlaylistFromLocalSrc(src)

    for video in playlist:
        utils.Log('Adding to playlist: %s' % video)
        title, thumb = utils.GetTitleAndImage(video)
        if not thumb:
            thumb = image

        try:    AddToPlaylist(title, thumb, video, mode=mode, isFirst=isFirst)
        except: pass

        isFirst = False
else:
    directoryName = matchingPaths[0]
    if directoryName.endswith('/'):
        directoryName = directoryName[:-1]
    if os.path.exists(directoryName + '/../tracking.cfg'
                      ) and not os.path.exists('./tracking.cfg'):
        f = storage.openCheck(directoryName + '/../tracking.cfg')
        out = storage.openCheck('./tracking.cfg', 'w')
        for l in f:
            if 'video-filename' in l:
                tmp = l.split('=')
                out.write(tmp[0] + '= ' + args.videoFilename + '\n')
            elif 'database-filename' in l:
                tmp = l.split('=')
                out.write(tmp[0] + '= ' +
                          utils.removeExtension(args.videoFilename) +
                          '.sqlite\n')
            else:
                out.write(l)
        f.close()
        out.close()
        print(
            'Configuration file tracking.cfg successfully copied to the current directory with video and database filename adapted'
        )

# extract image from video
image = getImagesFromVideo(args.videoFilename,
                           saveImage=True,
                           outputPrefix='frame')
print('first video frame successfully copied to the current directory')
import numpy as np

import cv
import utils
import cvutils
import ubc_utils
import moving

# use something like getopt to manage arguments if necessary

if len(sys.argv) < 3:
    print('Usage: {0} <video-filename> <n-objects>'.format(sys.argv[0]))
    sys.exit()

if sys.argv[1].endswith('.avi'):
    videoFilenamePrefix = utils.removeExtension(sys.argv[1], '.')
else:
    videoFilenamePrefix = sys.argv[1]

objectNum = int(sys.argv[2])

objects = ubc_utils.loadTrajectories(videoFilenamePrefix + '-objects.txt',
                                     objectNum + 1)
obj = objects[objectNum]
features = ubc_utils.loadTrajectories(videoFilenamePrefix + '-features.txt',
                                      max(obj.featureNumbers) + 1)
h = np.loadtxt(videoFilenamePrefix + '-homography.txt')

invh = cvutils.invertHomography(h)