Esempio n. 1
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)
Esempio n. 2
0
def splitOpBlob(floodFillImage, copy, points, line):
"""
Flood fill on bots side of are line, and return the 2 areas
"""
	comp = cv.CvConnectedComp()
	# Get start and stop points
	sizeSplitBlobs = []
	(start_point, stop_point) = line.getPoints()
	for point in points:
		# Get new random color
		color = lib.getRandomColor()
		if (start_point.x == stop_point.x):
			slice1 = floodFillImage[:,0:start_point.x+1]
			cv.cvFloodFill(slice1, cv.cvPoint(start_point.x, start_point.y+1), color, cv.CV_RGB(2,2,2), cv.CV_RGB(2,2,2),comp)
			#removes blobs that have are area under 3
			if (comp.area > 2):
				sizeSplitBlobs.append(comp.area)
				slice2 = copy[:,start_point.x:]
				cv.cvFloodFill(slice2, cv.cvPoint(0, start_point.y+1), color, cv.CV_RGB(2,2,2), cv.CV_RGB(2,2,2),comp)
				sizeSplitBlobs.append(comp.area)
			start_point = point
	return sizeSplitBlobs
Esempio n. 3
0
cut = lines[0]

print "Test plot and line scanner methods"
points = lineScanner.naiveLineScanner(out, image, cut)

out = highgui.cvLoadImage (filename)

(out, components) = featureDetector.floodFillLine(image, out, points, cut, lo, up)

print components[0].area

# Test
comp = cv.CvConnectedComp()
seed = cv.cvPoint(200, 20)
cv.cvFloodFill(image, seed, lib.COL_RED, cv.CV_RGB(lo,lo,lo), cv.CV_RGB(up,up,up),comp)# ,flags, None);
print comp.area

lib.drawBoundingBoxes(out, components)

#lib.drawLines(out)

winname1 = "Find regions"
winname2 = "original"

highgui.cvNamedWindow (winname1, highgui.CV_WINDOW_AUTOSIZE)
highgui.cvNamedWindow (winname2, highgui.CV_WINDOW_AUTOSIZE)

while True:
	highgui.cvShowImage (winname1, out)
	highgui.cvShowImage (winname2, image)