This file contains hidden or 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 necessary libraries | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import cv2 | |
# Load image and convert it from BGR to RGB | |
image = cv2.cvtColor(cv2.imread("folder/imageName.jpg"), cv2.COLOR_BGR2RGB) |
This file contains hidden or 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
def resize(img, height=800): | |
""" Resize image to given height """ | |
rat = height / img.shape[0] | |
return cv2.resize(img, (int(rat * img.shape[1]), height)) | |
# Resize and convert to grayscale | |
img = cv2.cvtColor(resize(image), cv2.COLOR_BGR2GRAY) | |
# Bilateral filter preserv edges | |
img = cv2.bilateralFilter(img, 9, 75, 75) |
This file contains hidden or 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
# Getting contours | |
im2, contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) | |
# Finding contour of biggest rectangle | |
# Otherwise return corners of original image | |
# Don't forget on our 5px border! | |
height = edges.shape[0] | |
width = edges.shape[1] | |
MAX_COUNTOUR_AREA = (width - 10) * (height - 10) |
This file contains hidden or 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
def fourCornersSort(pts): | |
""" Sort corners: top-left, bot-left, bot-right, top-right """ | |
# Difference and sum of x and y value | |
# Inspired by http://www.pyimagesearch.com | |
diff = np.diff(pts, axis=1) | |
summ = pts.sum(axis=1) | |
# Top-left point has smallest sum... | |
# np.argmin() returns INDEX of min | |
return np.array([pts[np.argmin(summ)], |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 ipywidgets as widgets | |
# Import display function | |
from IPython.display import display | |
# Create costume widget | |
w = widgets.IntProgress(value = 50, description='Loading:') | |
# Display widget | |
display(w) |
This file contains hidden or 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 IPython.display import display, clear_output | |
# Creating and Displaying button | |
button = widgets.Button(description="Button Text!") | |
display(button) | |
# Callback function with button parameter | |
def clicked(b): | |
clear_output() | |
print("Result of button click: ") |
This file contains hidden or 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
#!/bin/bash | |
# Update | |
apt-get update && apt-get upgrade -y | |
# Install python+packages and curl | |
apt-get install -y python3 python3-pip python3-numpy python3-scipy python3-matplotlib ipython3 ipython3-notebook python3-pandas python3-nose curl wget | |
# Update pip | |
python3 -m easy_install -U pip | |
# Correctinng python file | |
# which causes stuck during package installation |
This file contains hidden or 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 tensorflow as tf | |
### Linear Regression ### | |
# Input placeholders | |
x = tf.placeholder(tf.float32, name='x') | |
y = tf.placeholder(tf.float32, name='y') | |
# Model parameters | |
W1 = tf.Variable([0.1], tf.float32) | |
W2 = tf.Variable([0.1], tf.float32) | |
W3 = tf.Variable([0.1], tf.float32) | |
b = tf.Variable([0.1], tf.float32) |
This file contains hidden or 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
sess = tf.Session() | |
# Import graph from the path and recover session | |
saver = tf.train.import_meta_graph('models/model_name.meta', clear_devices=True) | |
saver.restore(sess, 'models/model_name') | |
# There are TWO options how to access the operation (choose one) | |
# FROM SAVED COLLECTION: | |
activation = tf.get_collection('activation')[0] | |
# BY NAME: |