Skip to content

Instantly share code, notes, and snippets.

@heaven00
heaven00 / sift_example.py
Created December 17, 2014 13:10
SIFT test script
import numpy as np
import cv2
from matplotlib import pyplot as plt
def show_img(img1, img2, p1, p2, status):
h1, w1 = img1.shape[:2]
h2, w2 = img2.shape[:2]
vis = np.zeros((max(h1, h2), w1+w2), np.uint8)
vis[:h1, :w1] = img1
vis[:h2, w1:w1+w2] = img2
@heaven00
heaven00 / numpy_row_contains.py
Created December 20, 2014 21:57
A way to check if a value exists in a single row in a numpy array
def row_contains(data, query):
"""
Checks row of the matrix for the given condition
and returns a list of rows that satisfies the condition
"""
condition = np.any(query, axis=1)
return np.compress(condition, data, axis=0)
@heaven00
heaven00 / template_matching
Created December 24, 2014 05:52
Template matching trial
#sign to be detected
template = cv2.imread('sign.png')
#image in which it is to be directed
image = cv2.imread('iamge.jpg')
template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(image_gray, template_gray, cv2.TM_CCOEFF_NORMED)
threshold = 0.7
@heaven00
heaven00 / show_contours
Created December 24, 2014 06:26
Function to display contours
def show_contours(contours, img):
"""
Draw and display contours on the img provided.
:contours: - list of contours
:img: - on which the contour is suppose to be drawn
"""
color = np.random.randint(0, 255, (3)).tolist()
for cnt in contours:
cv2.drawContours(img, [cnt], 0, color, 2)
show_img(img)
@heaven00
heaven00 / Prime Generator
Created January 17, 2015 22:28
A prime generator algorithm, it is buggy because beyond starting point 2 nothing is handled and it hangs in range 2 to 1billion
def getprimes(start=2, upto=100):
"""
Generate primes between a given range defined by
:start: and :upto: vars.
"""
#NOTE: np.arrange is faster then python for loop
primes = np.arange(2, upto+1)
isprime = np.ones(upto-1, dtype=bool)
#find the first prime before starting this loop to optimize
for factor in primes[:int(upto**0.5)]:
@heaven00
heaven00 / theano-win-install.md
Created August 31, 2015 14:14
Installing Theano on windows with Anaconda

3 Steps to setup theano on windows

  1. Install Anaconda
  2. run "conda install mingw libpython"
  3. run "pip install theano"
@heaven00
heaven00 / julia_setup
Created September 15, 2015 09:42
Setting Up Julia
1. Download Julia.exe
2. copy paste the following:
run(`git config --global url."https://".insteadOf git://`)
this is because the git:// causes an error.
@heaven00
heaven00 / bobp-python.md
Created November 18, 2015 20:51 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@heaven00
heaven00 / gist:4593340
Created January 22, 2013 09:34
Web Link Crawler
import mechanize
from urlparse import urlparse, urljoin
"""Mechanize will open the link given to it and get the links without breaking much sweat,
I am not sure what kind of repository setup you have so i am just going to use a global list named master to store all the succesfully crawled links, I also added a failed_link list that will store the links that the mechanize model was unable to open for further crawling. """
"""I wasn't sure about the links that the program needs to handle or how those links needed to be handled, so this program assumes that the link given to it is a valid link and i tried to make the program such that it doest not fail without warning"""
"""to form the repository of sites, the master and failed_links lists needs to be stored. Personally I would prefer storing the data in Mongo in the structure:
{'site' : site,
redis-cli -n [DB] keys "pattern" | xargs -d '\n' redis-cli -n [DB] del