├── output.png ├── README.md ├── .gitignore └── ColorsOfFilm.py /output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sacert/Colors-of-Film/HEAD/output.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Colors Of Film 2 | 3 | Parses the average colors per frame of a movie and compress it into an email 4 | 5 | #### How to use: 6 | `python colorsOfFilm.python [file path] [width] [height]` 7 | 8 | #### Requirements: 9 | - Numpy 10 | - OpenCV 11 | 12 | #### Example: 13 | 14 | ##### Harry Potter and the Prizoner of Azkaban (Can you guess when the patronus is used?) 15 | 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /ColorsOfFilm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | import os 4 | import sys 5 | 6 | # make sure the user enters in the needed values 7 | if len(sys.argv) < 2: 8 | print 'Please enter video path' 9 | sys.exit() 10 | elif len(sys.argv) < 3: 11 | print 'Please enter output image height' 12 | sys.exit() 13 | elif len(sys.argv) < 4: 14 | print 'Please enter output image width' 15 | sys.exit() 16 | 17 | # set user variables 18 | path = os.path.expanduser(sys.argv[1]) 19 | imgWidth = int(os.path.expanduser(sys.argv[2])) 20 | imgHeight = int(os.path.expanduser(sys.argv[3])) 21 | 22 | def colorsOfFilm(path, imgWidth, imgHeight): 23 | vidcap = cv2.VideoCapture(path) 24 | success,image = vidcap.read() 25 | 26 | frames = [] 27 | 28 | # while there is still a frame, process it 29 | success = True 30 | while success: 31 | try: 32 | success,image = vidcap.read() 33 | avg_row_col = np.average(image, axis=0) 34 | avg_color = np.average(avg_row_col, axis=0) 35 | avg_color = np.uint8(avg_color) 36 | frames.append(avg_color) 37 | except IndexError: 38 | break 39 | 40 | # get the average of the bucket size 41 | new_image = [] 42 | frame_per_bucket = len(frames) / imgWidth 43 | for frames in np.split(frames, range(frame_per_bucket, len(frames), frame_per_bucket)): 44 | av = np.average(frames, axis=0) 45 | new_image.append(av) 46 | 47 | new_image = np.array(new_image) 48 | 49 | n,d = new_image.shape 50 | image = np.repeat(new_image, imgHeight, axis=0) 51 | image = np.reshape(image, (n, imgHeight, d)) 52 | cv2.imwrite('output.png', image.transpose(1,0,2)) 53 | 54 | # run the program 55 | colorsOfFilm(path, imgWidth, imgHeight) 56 | --------------------------------------------------------------------------------