Ejemplo n.º 1
0
def get_nearest_feature( image, this_point, n=2000 ):
	"""
	Get the n-nearest features to a specified image coordinate.
	Features are determined using cvGoodFeaturesToTrack.
	"""

	_red = cv.cvScalar (0, 0, 255, 0);
	_green = cv.cvScalar (0, 255, 0, 0);
	_blue = cv.cvScalar (255,0,0,0);
	_white = cv.cvRealScalar (255)
	_black = cv.cvRealScalar (0)

	quality = 0.01
	min_distance = 4
	N_best = n
	win_size = 11

	grey = cv.cvCreateImage (cv.cvGetSize (image), 8, 1)
	eig = cv.cvCreateImage (cv.cvGetSize (image), 32, 1)
	temp = cv.cvCreateImage (cv.cvGetSize (image), 32, 1)

	# create a grey version of the image
	cv.cvCvtColor ( image, grey, cv.CV_BGR2GRAY)

	points = cv.cvGoodFeaturesToTrack ( 
		grey, eig, temp,
		N_best,
		quality, min_distance, None, 3, 0, 0.04)

	# refine the corner locations
	better_points = cv.cvFindCornerSubPix (
		grey,
		points,
		cv.cvSize (win_size, win_size), cv.cvSize (-1, -1),
		cv.cvTermCriteria (cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS,
						   20, 0.03))

	eigs = []
	for i in range(len(points)):
		eigs.append(cv.cvGetMat(eig)[int(points[i].y)][int(points[i].x)])

	mypoints = np.matrix(np.zeros((len(points)*2),dtype=float)).reshape(len(points),2)
	dists = []
	for i,point in enumerate(points):
		mypoints[i,0]=point.x
		mypoints[i,1]=point.y
		dists.append( np.linalg.norm(mypoints[i,:]-this_point) )

	dists = np.array(dists)
	sorteddists = dists.argsort()

	cv.cvDrawCircle ( image, points[ sorteddists[0] ], 5, _green, 2, 8, 0 )

	return better_points[ sorteddists[0] ]
Ejemplo n.º 2
0
def get_nearest_feature(image, this_point, n=2000):
    """
	Get the n-nearest features to a specified image coordinate.
	Features are determined using cvGoodFeaturesToTrack.
	"""

    _red = cv.cvScalar(0, 0, 255, 0)
    _green = cv.cvScalar(0, 255, 0, 0)
    _blue = cv.cvScalar(255, 0, 0, 0)
    _white = cv.cvRealScalar(255)
    _black = cv.cvRealScalar(0)

    quality = 0.01
    min_distance = 4
    N_best = n
    win_size = 11

    grey = cv.cvCreateImage(cv.cvGetSize(image), 8, 1)
    eig = cv.cvCreateImage(cv.cvGetSize(image), 32, 1)
    temp = cv.cvCreateImage(cv.cvGetSize(image), 32, 1)

    # create a grey version of the image
    cv.cvCvtColor(image, grey, cv.CV_BGR2GRAY)

    points = cv.cvGoodFeaturesToTrack(grey, eig, temp, N_best, quality,
                                      min_distance, None, 3, 0, 0.04)

    # refine the corner locations
    better_points = cv.cvFindCornerSubPix(
        grey, points, cv.cvSize(win_size, win_size), cv.cvSize(-1, -1),
        cv.cvTermCriteria(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 20, 0.03))

    eigs = []
    for i in range(len(points)):
        eigs.append(cv.cvGetMat(eig)[int(points[i].y)][int(points[i].x)])

    mypoints = np.matrix(np.zeros((len(points) * 2),
                                  dtype=float)).reshape(len(points), 2)
    dists = []
    for i, point in enumerate(points):
        mypoints[i, 0] = point.x
        mypoints[i, 1] = point.y
        dists.append(np.linalg.norm(mypoints[i, :] - this_point))

    dists = np.array(dists)
    sorteddists = dists.argsort()

    cv.cvDrawCircle(image, points[sorteddists[0]], 5, _green, 2, 8, 0)

    return better_points[sorteddists[0]]
Ejemplo n.º 3
0
	def get_thresholded(self,gray_source,threshold):
		#Allocate a new image
		threshed=cv.cvCreateImage(cv.cvGetSize(gray_source),gray_source.depth,1)

		#Subtract 255 from all values in the image?
		cv.cvSubRS(gray_source,cv.cvRealScalar(255),threshed,None)

		#Apply a binary threshold to the image
		cv.cvThreshold(gray_source,threshed,threshold,255,cv.CV_THRESH_BINARY)

		#Release the source image
		cv.cvReleaseImage(gray_source)

		return threshed
Ejemplo n.º 4
0
#! /usr/bin/env python

print "OpenCV Python version of contours"

# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui

# some default constants
_SIZE = 500
_DEFAULT_LEVEL = 3

# definition of some colors
_red = cv.cvScalar (0, 0, 255, 0);
_green = cv.cvScalar (0, 255, 0, 0);
_white = cv.cvRealScalar (255)
_black = cv.cvRealScalar (0)

# the callback on the trackbar, to set the level of contours we want
# to display
def on_trackbar (position):

    # create the image for putting in it the founded contours
    contours_image = cv.cvCreateImage (cv.cvSize (_SIZE, _SIZE), 8, 3)

    # compute the real level of display, given the current position
    levels = position - 3

    # initialisation
    _contours = contours
    
Ejemplo n.º 5
0
#! /usr/bin/env python

print "OpenCV Python version of contours"

# import the necessary things for OpenCV
from opencv import cv
from opencv import highgui

# some default constants
_SIZE = 500
_DEFAULT_LEVEL = 3

# definition of some colors
_red = cv.cvScalar(0, 0, 255, 0)
_green = cv.cvScalar(0, 255, 0, 0)
_white = cv.cvRealScalar(255)
_black = cv.cvRealScalar(0)


# the callback on the trackbar, to set the level of contours we want
# to display
def on_trackbar(position):

    # create the image for putting in it the founded contours
    contours_image = cv.cvCreateImage(cv.cvSize(_SIZE, _SIZE), 8, 3)

    # compute the real level of display, given the current position
    levels = position - 3

    # initialisation
    _contours = contours
Ejemplo n.º 6
0
	def read(self):
		frame=self.input.read()
		if self.enabled:
			cv.cvSubRS(frame, cv.cvRealScalar(255), frame)
		return frame