Skip to content

Instantly share code, notes, and snippets.

View Breta01's full-sized avatar
🤹
All over the place

Bretislav Hajek Breta01

🤹
All over the place
View GitHub Profile
@Breta01
Breta01 / ipywidgets_event_handlers.py
Created February 23, 2017 19:49
Handling click on button widget
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: ")
@Breta01
Breta01 / display_widget.py
Last active July 2, 2017 16:51
Display only one widget
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)
@Breta01
Breta01 / Interact_from_ipywidgets.ipynb
Last active July 27, 2019 12:42
Example of using interact from ipywidgets
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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)],
# 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)
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)
# 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)
@Breta01
Breta01 / Example_page.tex
Last active January 8, 2017 15:17
Example LaTeX page
\documentclass{article}
\begin{document}
\title{Example Page}
\author{Breta}
\maketitle
\begin{abstract}
This is the example page.
\end{abstract}
@Breta01
Breta01 / scripts.json
Created November 16, 2016 21:46
Include in package.json > scripts
"postinstall": "install-app-deps",
"dist": "npm run build && build --publish onTagOrDraft"
@Breta01
Breta01 / .travis.yml
Created November 16, 2016 20:58
Simplified .travis.yml
sudo: required
dist: trusty
language: c
matrix:
include:
- os: osx
- os: linux
env: CC=clang CXX=clang++ npm_config_clang=1