This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imageio | |
reader = imageio.get_reader(os.path.join(folder_videos, video)) | |
nframes = reader.get_meta_data()['nframes'] | |
for j,im in enumerate(reader): | |
print (j, im) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import sys | |
from PIL import Image | |
def img_read_save(url, quality, format_='PNG'): | |
img = Image.open(url) | |
output = io.BytesIO() | |
img.save(output, format=format_, subsampling=0, quality=quality) | |
contents = output.getvalue() | |
print (type(contents)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
if __name__ == "__main__": | |
r = requests.get(remote_url) | |
with open(local_url, 'wb') as fp: | |
fp.write(r.content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import colorsys | |
def get_random_color(): | |
h,s,l = random.random(), 0.5 + random.random()/2.0, 0.4 + random.random()/5.0 | |
r,g,b = [int(256*i) for i in colorsys.hls_to_rgb(h,l,s)] | |
person_color1 = '#%02x%02x%02x' % (r,g,b) | |
person_color2 = "#" + "%06x" % random.randint(0, 0xFFFFFF) | |
return [(r,g,b), person_color1], person_color2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
def get_framecount(url): | |
sess = requests.Session() | |
r = sess.get(url) | |
soup = BeautifulSoup(r.text, "lxml") | |
div = soup.find_all('div', {'class' : 'raw-block'}) | |
frames_count = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
if __name__ == "__main__": | |
a = datetime.datetime.strptime('2011-09-26 14:14:11.124700931'[:-3], '%Y-%m-%d %H:%M:%S.%f') | |
b = datetime.datetime.strptime('2011-09-26 14:15:16.432700931'[:-3], '%Y-%m-%d %H:%M:%S.%f') | |
diff = (b-a) | |
print (diff.seconds, diff.microseconds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import zipfile | |
import requests | |
def download_data(url_local, url_remote, root_dir): | |
with open(url__local, 'wb') as fp: | |
r = requests.get(url_remote) | |
fp.write(r.content) | |
zip_ref = zipfile.ZipFile(url_local, 'r') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
def run(command): | |
process = Popen(command, stdout=PIPE, shell=True) | |
while True: | |
line = process.stdout.readline().rstrip() | |
if not line: | |
break | |
yield line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
# References | |
- https://docs.opencv.org/3.0.0/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a | |
- https://docs.opencv.org/3.0.0/d4/d73/tutorial_py_contours_begin.html | |
- contours :: Detected contours. Each contour is stored as a vector of points. | |
- len(contours) == total no. of contours | |
- hierarchy :: as many elements as the number of contours | |
- [[next_contour, prev_contour, child_contour, parent_countour], [], [], .. , []] | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import site | |
import numpy as np | |
if __name__ == "__main__": | |
print (sys.executable) | |
print (site.getsitepackages()) | |
print (np.__file__) |