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

with crop of the image

parent 5e0b1a87
......@@ -16,11 +16,11 @@ import moviepy.editor as mp
follow = True
queue = Queue()
linkFile = './link-dictionnaries/link-dictionnary2004.txt'
linkFile = './link-dictionnaries/link-dictionnary2003.txt'
linkDict = {}
exceptDict = {}
videoDir = './video/'
spectrumDir = '../spectrumImages/spectrumImages2004/'
spectrumDir = '../spectrumImages/spectrumImages2003/'
countDownload = 1
countSpectrum = 1
......@@ -90,13 +90,37 @@ def resizeVideo(vidIn, vidOut):
return vidOut
return vidOut
def meanImage(img): # Return the mean LAB array
def crop_image_dim(img,tol):
"""Find the dimensions cropped if this is a 4:3 or 21:9 trailer"""
# img is image data
# tol is tolerance
mask = img>tol
midV=floor(mask.shape[0]/2)
midH=floor(mask.shape[1]/2)
upBorder=0
downBorder=mask.shape[0]
leftBorder=0
rightBorder=mask.shape[1]
for i in range(1,mask.shape[0]):
if mask[i-1][midH]!=mask[i][midH] and mask[i][midH]==True:
if upBorder==mask[0][midH]:
upBorder=i-1
if mask[i-1][midH]!=mask[i][midH] and mask[i][midH]==False:
downBorder=i
for j in range(1,mask.shape[1]):
if mask[midV][j-1]!=mask[midV][j] and mask[midV][j]==True:
if leftBorder==mask[midV][0]:
leftBorder=j-1
if mask[midV][j-1]!=mask[midV][j] and mask[midV][j]==False:
rightBorder=j
return (upBorder,downBorder, leftBorder, rightBorder)
def meanImage(img,cropdim): # Return the mean LAB array
res0 = [0, 0, 0]
res = [0, 0, 0]
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
for i in range(0, lab.shape[0]):
for j in range(0, lab.shape[1]):
for i in range(cropdim[0], cropdim[1]):
for j in range(cropdim[2], cropdim[3]):
res0 = res0 + lab[i][j]
res0 = res0 / (img.shape[0] * img.shape[1])
res[0] = int(res0[0])
......@@ -110,6 +134,16 @@ def tableSpectrum(video):
count = 0
ratioFrame = 6
countFrame = 0
vidcrop=cv2.VideoCapture(video)
success, image = vidcrop.read()
success = True
countcrop=0
while success and countcrop<240:
success,image=vidcrop.read()
countcrop+=1
cropdim=crop_image_dim(image,0)
vidcap = cv2.VideoCapture(video)
length = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT) / ratioFrame)
width = int(length * 3 / 16)
......@@ -121,7 +155,7 @@ def tableSpectrum(video):
while success:
if countFrame == ratioFrame:
countFrame = 0
res[0][count] = meanImage(image)
res[0][count] = meanImage(image,cropdim)
for i in range(1, res.shape[0]):
res[i][count] = res[0][count]
count += 1
......@@ -139,8 +173,8 @@ def imgSpectrum(vidPath, spectrumOut):
res2 = tableSpectrum(resizeVideo(vidPath, vidPath))
else:
res2 = tableSpectrum(vidPath)
output= cv2.cvtColor(res2, cv2.COLOR_LAB2BGR)
cv2.imwrite(spectrumOut, output)
output = cv2.cvtColor(res2, cv2.COLOR_LAB2BGR)
cv2.imwrite(spectrumOut, res2)
print()
print("--------------------------------------------------------")
print("Duration : {} s".format(time() - start))
......@@ -153,8 +187,7 @@ def main():
global linkDict
global linkFile
global follow
if not os.path.isdir(spectrumDir):
os.makedirs(spectrumDir)
linkDict = reading(linkFile)
TRAILER = Thread(target=downloadTrailer)
SPECTRUM = Thread(target=createSpectrum)
......
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