Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
jayrambhia / gist:4559834
Last active December 11, 2015 06:29
SIFT match keypoints and draw.
def matchSIFTKeyPoints(self, template, quality=200):
try:
import cv2
except ImportError:
logger.warning("OpenCV >= 2.3.0 required")
if template == None:
return None
detector = cv2.FeatureDetector_create("SIFT")
descriptor = cv2.DescriptorExtractor_create("SIFT")
img = self.getNumpyCv2()
compiling opencv_webcam.cpp
opencv_webcam.cpp: In function ‘int main()’:
opencv_webcam.cpp:8:9: error: ‘cap’ was not declared in this scope
opencv_webcam.cpp:11:9: error: ‘k’ was not declared in this scope
opencv_webcam.cpp:11:23: error: ‘waitkey’ was not declared in this scope
opencv_webcam.cpp:12:9: error: expected ‘;’ before ‘if’
Output file => opencv_webcam
@jayrambhia
jayrambhia / capture_util.py
Created August 14, 2012 07:07
Utilities for capture in OpenCV
import cv2
import cv2.cv as cv
"""
Got the idea from http://newpathprep.wordpress.com/2012/08/13/opencv-forward-and-rewind-avi/
He has done it in C++.
"""
def start(capture, n):
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, n-1)
def rewind(capture):
@jayrambhia
jayrambhia / LKTrack.py
Created August 8, 2012 14:56
Lucas Kanade Tracker (OpenCV)
import cv2
import numpy as np
import itertools
lk_params = dict( winSize = (10, 10),
maxLevel = 5,
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))
feature_params = dict( maxCorners = 3000,
qualityLevel = 0.5,
@jayrambhia
jayrambhia / houghlines.py
Created August 3, 2012 15:15
Hough Lines test
from SimpleCV import *
import time, cv2
import cv2.cv as cv
i = Image("Python/SimpleCV/line1.jpg")
g = i.getGrayNumpyCv2()
em = cv2.Canny(g, 70, 100)
l = cv2.HoughLines(em, 1.0, cv.CV_PI/180.0, 100)
print l.shape
l = l[0]
@jayrambhia
jayrambhia / Makefile
Created June 27, 2012 10:42
Comparison between run time of SimpleCV, OpenCV(python) and OpenCV(C++) Boost::Python bindings.
PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
# compile mesh classes
TARGET = opencvtest
echo "Install SimpleCV"
echo "Installing pre-reqisites"
sleep 1
echo "Installing OpenCV..."
sudo apt-get install libopencv-*
sudo apt-get install python-opencv
echo "OpenCV installed"
echo "Installing numpy and scipy"
sudo apt-get install python-numpy python-scipy
echo "numpy and scipy installed"
@jayrambhia
jayrambhia / track1.py
Created June 1, 2012 20:31
mf tracker (doesn't work properly)
from SimpleCV import *
from cv2.cv import *
from cv2 import *
import time
import math
from copy import deepcopy
def fbtrack(imgI, imgJ, bb):
numM = 10
numN = 10
@jayrambhia
jayrambhia / bb.py
Created May 30, 2012 15:08
mf-tracker
from math import sqrt
def calculateBBCenter(bb):
center = (0.5*(bb[0] + bb[2]),0.5*(bb[1]+bb[3]))
return center
def getFilledBBPoints(bb, numM, numN, margin):
pointDim = 2
bb_local = (bb[0] + margin, bb[1] + margin, bb[2] - margin, bb[3] - margin)
if numM == 1 and numN == 1 :
@jayrambhia
jayrambhia / xkcd_comic_viewer.py
Created March 12, 2012 12:26
xkcd viewer (fetches images online)
import pygtk
import gtk
import os
from random import randint
import urllib2
import os
from BeautifulSoup import BeautifulSoup
from threading import Thread
import gobject
gtk.gdk.threads_init()