Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 309a06b0 authored by SoleneDc's avatar SoleneDc

spectrums 2015

parent d385dc67
No preview for this file type
......@@ -6,6 +6,7 @@ from threading import Thread
from queue import Queue
from ast import literal_eval
from skimage.transform import resize
import datetime
from time import time
from math import floor
import numpy as np
......@@ -17,11 +18,11 @@ import moviepy.editor as mp
follow = True
queue = Queue()
linkFile = './link-dictionaries/link-dictionary20082.txt' # Input dict of trailers
linkFile = './link-dictionaries/link-dictionary2015-1.txt' # Input dict of trailers #TODO; change path
linkDict = {}
exceptDict = {}
videoDir = './video/' # Folder to store temporarely the videos
spectrumDir = '../spectrumImages/spectrumImages2008/' # Output folder to store the spectrums
spectrumDir = './spectrumImages/spectrumImages2015/' # Output folder to store the spectrums #TODO; change path
countDownload = 1
countSpectrum = 1
......@@ -55,7 +56,9 @@ def downloadTrailer(): # called by main()
'save_path': videoDir}
for key in linkDict.keys():
if not os.path.isfile(spectrumDir + linkDict[key][2] + '.jpg'):
#time1 = datetime.datetime.now()
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
#while (datetime.datetime.now() - time1).seconds < 190:
try:
ydl.download(['https://www.youtube.com/watch?v=' + linkDict[key][2]])
info_dict = ydl.extract_info('https://www.youtube.com/watch?v=' + linkDict[key][2], download=False)
......@@ -66,8 +69,8 @@ def downloadTrailer(): # called by main()
except Exception as e: # catch *all* exceptions
exceptDict[linkDict[key][2]] = str(e)
"""f = open("Exception-dictionnary.txt", "w")
f.write(str(exceptDict))
f.close()"""
f.write(str(exceptDict))
f.close()"""
print("{}/{} downloads".format(countDownload, len(linkDict)))
else:
......@@ -86,7 +89,11 @@ def createSpectrum(): # called by main()
global countDownload
print("{}/{} spectrum".format(countSpectrum, len(linkDict)))
countSpectrum += 1
os.remove(videoDir + item)
try:
os.remove(videoDir + item)
except FileNotFoundError:
pass
queue.task_done()
......@@ -126,17 +133,18 @@ def tableSpectrum(video): # called by imgSpectrum()
"""Find if the trailer is in 4:3 or 21:9 --> borders to crop"""
success, image = vidcrop.read()
cropdim = (0, image.shape[0], 0, image.shape[1])
countcrop=0
while success and countcrop<240:
success,image=vidcrop.read()
countcrop+=1
if success==True:
if success:
cropdim = (0, image.shape[0], 0, image.shape[1])
countcrop = 0
while success and countcrop < 240:
success, image = vidcrop.read()
countcrop += 1
if success == True:
try:
cropdim=crop_image_dim(image,0)
cropdim = crop_image_dim(image, 0)
except cv2.error:
cropdim = (0, image.shape[0], 0, image.shape[1])
print("image size : {}".format(image.shape))
print("image size : {}".format(image.shape))
print("cropped dim : {}".format(cropdim))
"""Read every images of the trailer and out the mean color of each"""
......@@ -196,9 +204,11 @@ def meanImage(img, cropdim): # called by tableSpectrum()
for j in range(cropdim[2], cropdim[3]):
res0 = res0 + lab[i][j]
sumpix=(cropdim[1]-cropdim[0]+1)*(cropdim[3]-cropdim[2]+1)
res0[0]= res0[0] / sumpix
res0[1]= res0[1] / sumpix
res0[2]= res0[2] / sumpix
if sumpix == 0:
sumpix = 1
res0[0] = res0[0] / sumpix
res0[1] = res0[1] / sumpix
res0[2] = res0[2] / sumpix
res[0] = int(res0[0])
res[1] = int(res0[1])
res[2] = int(res0[2])
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
import cv2
import os
def valid_spectrums(path):
def valid_spectrums(year):
path = f'./spectrumImages/spectrumImages{year}'
ok_files = []
for file in os.listdir(path):
if str(file)[-4:] == '.jpg':
print(file)
img = cv2.imread('./'+ path + '/' + file, 1)
image = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
length, width, lab = image.shape
......@@ -24,5 +24,5 @@ def valid_spectrums(path):
os.remove(path + "/" + file)
print(ok_files)
print(valid_spectrums('spectrumImages2005'))
# valid_spectrums(year)
No preview for this file type
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# RNN"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"import numpy\n",
"import matplotlib.pyplot as plt\n",
"import pandas\n",
"import math\n",
"from keras.models import Sequential\n",
"from keras.layers import Dense\n",
"from keras.layers import LSTM\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from sklearn.metrics import mean_squared_error"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
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