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 2de7315f authored by Hachemin Pierre-Yves's avatar Hachemin Pierre-Yves

Merge branch 'sd/lstm' into 'master'

Sd/lstm

See merge request !23
parents d385dc67 388e7a4e
File deleted
......@@ -21,3 +21,4 @@ spectrumImages2015/
spectrumImages2016/
spectrumImages2017/
spectrumImages/
Spectrums_sample/
import ast
import os
import cv2
import requests
import matplotlib.pyplot as plt
#L = ['Sithad108Og.','fBNpSRtfIUA', '2e-eXJ6HgkQ', 'tN1A2mVnrOM', 'myTaigPrbsg', 'b75lZw8nkvo']
......@@ -91,3 +93,56 @@ for file in eligible_links:
dict_inverse[file]['image'] += [img]
print('coucocu')
url = "https://api.themoviedb.org/3/genre/movie/list?"
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'
def get_genres(year):
path = "./Link-dictionaries/Link-dictionary" + str(year) +".txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_genres = {}
for movie_id in dictyear.keys():
genre_ids = dictyear[movie_id][1]
for genre_id in genre_ids:
if genre_id in dict_genres.keys():
dict_genres[genre_id] += 1
else:
dict_genres[genre_id] = 1
return dict_genres
def translate_genre():
url_final = url + API
req = requests.get(url_final)
print(req.json()["genres"])
def sum_genre(list_years):
final_dict_genre = {}
for year in list_years:
print(f'dealing with {year}...')
dict_genre = get_genres(year)
for key in dict_genre.keys():
if key in final_dict_genre.keys():
final_dict_genre[key] += dict_genre[key]
else:
final_dict_genre[key] = dict_genre[key]
return final_dict_genre
# print(get_genres(2001).keys())
# #print(get_genres(2002).keys())
# print(get_genres(2003).keys())
# print(get_genres(2004).keys())
# print(get_genres(2005).keys())
#print(translate_genre())
sum_genre = sum_genre(range(2003, 2014))
L = []
for key in sum_genre.keys():
L += [str(key)]
print(L, list(sum_genre.values()))
print(sum(list(sum_genre.values())))
plt.bar(L, list(sum_genre.values()))
plt.show()
......@@ -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 source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
import ast
import requests
import matplotlib.pyplot as plt
url = "https://api.themoviedb.org/3/genre/movie/list?"
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'
def get_genres(year):
path = "./Link-dictionaries/Link-dictionary" + str(year) +".txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_genres = {}
for movie_id in dictyear.keys():
genre_ids = dictyear[movie_id][1]
for genre_id in genre_ids:
if genre_id in dict_genres.keys():
dict_genres[genre_id] += 1
else:
dict_genres[genre_id] = 1
return dict_genres
def translate_genre():
url_final = url + API
req = requests.get(url_final)
print(req.json()["genres"])
def sum_genre(list_years):
final_dict_genre = {}
for year in list_years:
print(f'dealing with {year}...')
dict_genre = get_genres(year)
for key in dict_genre.keys():
if key in final_dict_genre.keys():
final_dict_genre[key] += dict_genre[key]
else:
final_dict_genre[key] = dict_genre[key]
return final_dict_genre
# print(get_genres(2001).keys())
# #print(get_genres(2002).keys())
# print(get_genres(2003).keys())
# print(get_genres(2004).keys())
# print(get_genres(2005).keys())
#print(translate_genre())
sum_genre = sum_genre(range(2003, 2014))
L = []
for key in sum_genre.keys():
L += [str(key)]
print(L, list(sum_genre.values()))
print(sum(list(sum_genre.values())))
plt.bar(L, list(sum_genre.values()))
plt.show()
No preview for this file type
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
_jQKeqCmdGk
\ No newline at end of file
# import the necessary packages
import numpy as np
import cv2
def is_contour_bad(c):
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
# the contour is 'bad' if it is not a rectangle
return not len(approx) == 4
# load the shapes image, convert it to grayscale, and edge edges in
# the image
image = cv2.imread("Image1.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edged = cv2.Canny(gray, 200, 600)
cv2.imshow("Original", image)
# find contours in the image and initialize the mask that will be
# used to remove the bad contours
(_,cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
mask = np.ones(image.shape[:2], dtype="uint8") * 255
# loop over the contours
for c in cnts:
dictV={}
dictH={}
for pix in c:
if pix[0][0] in dictH.keys():
dictH[pix[0][0]]+=1
else:
dictH[pix[0][0]]=1
if pix[0][1] in dictV.keys():
dictV[pix[0][1]]+=1
else:
dictV[pix[0][1]]=1
print("dictH {}".format(dictH))
print("dictV {}".format(dictV))
# if the contour is bad, draw it on the mask
if is_contour_bad(c):
cv2.drawContours(mask, [c], -1, 0, -1)
# remove the contours from the image and show the resulting images
image = cv2.bitwise_and(image, image, mask=mask)
cv2.imshow("Mask", mask)
cv2.imshow("After", image)
cv2.imwrite("Image1_After.jpg", image)
cv2.waitKey(0)
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)
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