Ejemplo n.º 1
0
def gridIt(image, component_dictionary, step=1):
	#print len(component_dictionary), 'len'
	gridcordinates = []
	for entry in component_dictionary:
		tmpgridcondinates = []
		color = component_dictionary[entry][0]
		#print color, 'color'
		component = component_dictionary[entry][1]
		points = 0

		rect = component.rect
		lower_x = rect.x
		lower_y = rect.y
		upper_x = lower_x + rect.width
		upper_y = lower_y + rect.height
		#print lower_x, 'lower_x'
		#print upper_x, 'upper_x'
		#print step, 'step'
		#print lower_y, 'lower_y'
		#print upper_y, 'upper_y'
		for i in range(lower_x, upper_x, step):
			for j in range(lower_y, upper_y, step):
				if lib.isSameColor(color, image[j][i]):
					points = points + 1
					tmpgridcondinates.append(cv.cvPoint(i, j))
		gridcordinates.append(tmpgridcondinates)
		#print points, 'points'
	return gridcordinates
Ejemplo n.º 2
0
def floodFillBetweenPoints(out, lo, up, line, component_dict):
	"""Floofill the image at point x,y whit are lower and upper thres hold namt lo and up
Start and stop point is the point that the def runs from to"""
	#Sets the flag
	flags = 4 + (255 << 8) + cv.CV_FLOODFILL_FIXED_RANGE

	# Set the region to None, as we haven't found any yet
	comp = None
	
	(p1, p2) = line.getPoints()
	
	if p1.x == p2.x:
		# Initialize the seed and set deltas for increasing the seed
		dx = 0
		dy = 1
		min = p1.y
		max = p2.y - 1
	elif p1.y == p2.y:
		# Initialize the seed and set deltas for increasing the seed
		dx = 1
		dy = 0
		min = p1.x
		max = p2.x - 1
	else:
		raise lib.OrientationException("Unknown orientation")

	seed = p1

	# Get a new color that is not in the component dictionary
	color = lib.getRandomColor()
	inDict = colorString(color) in component_dict
	while inDict:
		color = lib.getRandomColor(color)
		inDict = colorString(color) in component_dict

	#Color between start_point+1 and point-1
	#Tmp is the tims we find new color that lie in component_dict. 
	#This giv are indekeder that telle os have mots time we save whit the check
	for i in range(min, max):
		seed = cv.cvPoint(seed.x + dx, seed.y + dy)
		#Check if the color of the next pixel equals color 
		if not (lib.isSameColor(out[seed.y][seed.x], color)):
			#Check if the color of the next pixel are in component_dict
			if not (colorString(out[seed.y][seed.x]) in component_dict):
				comp = cv.CvConnectedComp()
				cv.cvFloodFill(out, seed, color, cv.CV_RGB(lo,lo,lo), cv.CV_RGB(up,up,up),comp)# ,flags, None);

				# Color the pixel again to make sure we return the entire region
				cv.cvFloodFill(out, seed, color, cv.CV_RGB(lo,lo,lo), cv.CV_RGB(up,up,up),comp)# ,flags, None);

	# Put the results in the component dictionary if we have found a region
	if not (comp is None):
		component_dict[colorString(color)] = (color, comp)
Ejemplo n.º 3
0
def naiveLineScanner(edgeImage, line):
	"""Scan for edges along a line in a edge-detected image
	This is _very_ naive
	Traverse a line, put the coordinate in a list if the pixel is white
"""
	# Get the points from the line
	(p1, p2) = line.getPoints()

	# We check the direction of the line then
	# get the appropriate row or column.
	# XXX: Any smarter way around this problem??
	if p1.y == p2.y:
		# Get the row, defined by y
		dx = 1
		dy = 0
		slice = edgeImage[p1.y]
	elif p1.x == p2.x:
		# Get the column, defined by x
		dx = 0
		dy = 1
		slice = edgeImage[:,p1.x]
	else:
		raise lib.OrientationException("The orientation is f****d up")

	p = p1
	points = []
	# Now we can traverse every point in the row/column
	for point in slice:
		thisColor = cv.CV_RGB(int(point[0]), int(point[1]), int(point[2]))
		if not lib.isSameColor(lib.COL_BLACK, thisColor):
			# Save this point
			points.append(p)
		# Update the coordinate
		p = (cv.cvPoint(p.x + dx, p.y + dy))

	return points