Source code for holypipette.vision.findpipette

'''
Methods to find the pipette in an image
'''
from .crop import cardinal_points, crop_cardinal
from numpy import dot, array, sign

__all__ = ['pipette_cardinal', 'pipette_cardinal2', 'up_direction']

[docs]def pipette_cardinal(image): ''' Determines the cardinal direction of the pipette (N, NW, S, etc) in the image. ''' xmin = None for direction in cardinal_points: cropped = crop_cardinal(image, direction) # Find the darkest subimage x = cropped.flatten().sum() if (xmin is None) or (x<xmin): xmin=x result = direction return result
#####HOANG
[docs]def pipette_cardinal2(image1, image2): xmax = None for direction in cardinal_points.iterkeys(): x = crop_cardinal(image1, direction).flatten().sum() - crop_cardinal(image2, direction).flatten().sum() if (xmax is None) or (abs(x) > xmax): xmax = abs(x) result = direction return result
[docs]def up_direction(pipette_position, positive_move): ''' Determines the direction (+1 or -1) of the pipette going up. Parameters --------- pipette_position : cardinal position of the pipette positive_move : vector of image movement for a positive displacement along the axis ''' y,x = cardinal_points[pipette_position] # position of pipette in square (0..2, 0..2) pipette_vector = array((1,1)) - array((x,y)) return -sign(dot(pipette_vector,positive_move[:2]))