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)
def main():
	"""
	Just the test
	This method is a god resource on how to handle the results
	"""

	filename = sys.argv[1]
	image = highgui.cvLoadImage (filename)

	print "DO NOT EXPECT THE RUNNING TIME OF THIS TEST TO BE REPRESENTATIVE!"
	print ""
	print "THRESHOLDS AND EVERYTHING ELSE ARE HARDCODED!"

	cutRatios = [0.6667, lib.PHI, 0.6]
	settings = Settings(cutRatios)

	# Run the analysis with the above settings
	comps = naiveMethod.analyzeImage(image, settings)

	# This is just for drawing the results
	# The below methods can probably be combined but don't bother
	# {{{
	# Get and draw the cuts
	cuts = {}
	for ratio in settings.cutRatios:
		cuts[str(ratio)] = lib.findMeans(cv.cvGetSize(image), ratio)

	for ratio in cuts:
		lib.drawLines(image, None, cuts[ratio], lib.getRandomColor())

	# Get and draw the components
	for ratio in comps:
		for cut in comps[ratio]:
			lib.drawBoundingBoxes(image, comps[ratio][cut])
	# }}}

	winname = "Failure"

	highgui.cvNamedWindow (winname, highgui.CV_WINDOW_AUTOSIZE)

	while True:
		highgui.cvShowImage (winname, image)

		c = highgui.cvWaitKey(0)

		if c == 'q':
			print "Exiting ..."
			print ""
			sys.exit(0)