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 fa606e88 authored by SoleneDc's avatar SoleneDc

Merge remote-tracking branch 'origin/master'

parents d2447054 9b1b5275
......@@ -8,28 +8,29 @@ url = 'https://api.themoviedb.org/3/discover/movie?api_key=e4c6a6f5fbd60b0316b7f
#il faut ajouter l'année après
url_get_video = "http://api.themoviedb.org/3/movie/" #157336/videos?api_key=e4c6a6f5fbd60b0316b7ff30e73bec74
API = 'api_key=e4c6a6f5fbd60b0316b7ff30e73bec74&language=en-US'
#API = 'api_key=e4c6a6f5fbd60b0316b7ff30e73bec74&language=en-US'
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'
def get_movie_ids(year):
now1 = datetime.datetime.now()
url_final = url + 'page=1&year=' + str(year)
req = requests.get(url_final)
# url_final = url + 'page=1&year=' + str(year)
# req = requests.get(url_final)
dict_movies = {}
nb_of_pages = req.json()['total_pages']
print(nb_of_pages)
for item in req.json()['results']:
movie_id = item['id']
video_link = get_video_link(movie_id)
dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
f = open("./Link-dictionnaries/Link-dictionnary2005.txt", "w")
f.write(str(dict_movies))
f.close()
for page in range(2, nb_of_pages+1):
time.sleep(5)
nb_of_pages = 550
# nb_of_pages = req.json()['total_pages']
# for item in req.json()['results']:
# movie_id = item['id']
# video_link = get_video_link(movie_id)
# dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
# f = open("./Link-dictionnaries/Link-dictionnary" + str(year) + ".txt", "w")
# f.write(str(dict_movies))
# f.close()
for page in range(163, nb_of_pages+1): #TODO: changer la page if needed
time.sleep(7)
print(dict_movies)
print(len(dict_movies))
print(f"taking care of page # {page}...")
print(f"taking care of page # {page}... / ", nb_of_pages)
url_final = url + 'page=' + str(page) +'&year=' + str(year)
req = requests.get(url_final)
for item in req.json()['results']:
......@@ -37,7 +38,7 @@ def get_movie_ids(year):
video_link = get_video_link(movie_id)
if video_link != '':
dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
f = open("./Link-dictionnaries/Link-dictionnary2005.txt", "w")
f = open("./Link-dictionnaries/Link-dictionnary" + str(year) + "-2.txt", "w")
f.write(str(dict_movies))
f.close()
return dict_movies
......@@ -54,4 +55,4 @@ def get_video_link(movie_id):
print(get_movie_ids(2005))
print(get_movie_ids(2010))
import ast
#L = ['Sithad108Og.','fBNpSRtfIUA', '2e-eXJ6HgkQ', 'tN1A2mVnrOM', 'myTaigPrbsg', 'b75lZw8nkvo']
def get_genre_from_link():
path = "./Link-dictionnaries/Link-dictionnary2000.txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_inverse = {}
links_to_be_removed = []
for movie_id in dictyear.keys():
if dictyear[movie_id][1] != []:
dict_inverse[dictyear[movie_id][2]] = dictyear[movie_id][1][0]
else:
print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
links_to_be_removed += [dictyear[movie_id][2]]
return dict_inverse, links_to_be_removed
def get_output_list(L):
dict_inverse, links_to_be_removed = get_genre_from_link()
output = []
for link in L:
if link in links_to_be_removed:
L.remove(link)
else:
output += [dict_inverse[link]]
return output
print(get_output_list(L))
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import cv2
import os
def valid_spectrums():
ok_files = []
for file in os.listdir("Spectrums_sample"):
img = cv2.imread('./Spectrums_sample/' + file, 1)
image = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
length, width, lab = image.shape
colors = []
for i in range(width):
tuple = (image[0][i][0], image[0][i][1], image[0][i][2])
if tuple not in colors:
colors += [tuple]
if len(colors) >= 10:
ok_files += [file]
break
f = open("spectrums_to_keep.txt", "w")
f.write(str(ok_files))
f.close()
print(valid_spectrums())
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-dictionnaries/Link-dictionnary" + 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:
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([2001, 2003, 2004, 2005, 2006])
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()
# 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)
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