Пример #1
0
def analyzeImage(original):
	scaleImage = cv.cvCreateImage(cv.cvSize(int(original.width*scale), int(original.height*scale)), 8, 3)
	cv.cvResize(original, scaleImage)

	# Create 1-channel image for the egdes
	edgeImage = cv.cvCreateImage(cv.cvGetSize(scaleImage), 8, 1)

	# Retrieve edges
	edgeDetector.findBWEdges(scaleImage, edgeImage, edgeThreshold1, edgeThreshold2)

	# Get cuts
	cuts = lib.findGoldenMeans(cv.cvGetSize(scaleImage))

	# Run along
	allComponents = []
	for cut in cuts:
		cutComponents = analyzeCut(scaleImage, edgeImage, cut)
		allComponents.append(cutComponents)

	# Get the collected component_dictionaries
	for dict in allComponents:
		lib.drawBoundingBoxes(original, dict, scale)

	# Draw the margins
	for cut in cuts:
		lib.drawMargin(original, cut, margin, scale)
		#include if super margen is need to drawn
		#lib.drawMargin(original, cut, superMargin, scale)

	return (original, allComponents)
Пример #2
0
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)

	cutRatios = [0.75]
	#cutRatios = [lib.PHI]
	settings = Settings(cutRatios)
	image = highgui.cvLoadImage (filename)
	thickness = 4
	settings.setMarginPercentage(0.025)
	cutNo = int(sys.argv[2])
	
	#udtrak af cut
	cut = lib.findMeans(cv.cvGetSize(image), settings.cutRatios[0])[cutNo]
	
	# cuttet verdi, dog skal det vi generaliseres lidt
	oriantesen = cut.getPoints()[0].x == cut.getPoints()[1].x
	
	if oriantesen:
		cutPixel = cut.getPoints()[1].x
	else:
		cutPixel = cut.getPoints()[1].y
	

	
	#Get the BW edge image
	edgeImage = expandedMethod.getEdgeImage(image, settings)

	(blobImg, comp) = expandedMethod.analyzeCut(image, edgeImage, cut, settings, 'True')
	#Liste af liste 
	
	# Find the margin
	margin = marginCalculator.getPixels(image, cut, settings.marginPercentage)

	lib.drawMargin(image, cut, margin)
	
	#Udregning af gridet
	gridPointsList = grid.gridIt(blobImg, comp)
	#hvor mange pixel der er pa den ende side i forhold til den anden, i procent
	
	pixelRatio = pixelSideCounter(gridPointsList, cutPixel, oriantesen)
	print pixelRatio
	#Udregning af center og mass
	points = centerOfMass(gridPointsList, oriantesen)
	#Draw the cut
	#print cut.getPoints()[0].y
	#print cut.getPoints()[1].y
	#print cut.getPoints()[0].x
	#print cut.getPoints()[1].x
	#print cutPixel
	
	if oriantesen:
	#	print 'hej'
		cv.cvLine(image, cv.cvPoint(cutPixel, cut.getPoints()[0].y), cv.cvPoint(cutPixel, cut.getPoints()[1].y), COL_RED)
	else:
		cv.cvLine(image, cv.cvPoint(cut.getPoints()[0].x, cutPixel), cv.cvPoint(cut.getPoints()[1].x, cutPixel), COL_RED)
	
	#Draw center of mass
	for point in points:
		if oriantesen:
	#		print 'hej'
	#		print point
			cv.cvLine(image, cv.cvPoint(point, cut.getPoints()[0].y), cv.cvPoint(point, cut.getPoints()[1].y), COL_GREEN)
		else:
	#		print point
			cv.cvLine(image, cv.cvPoint(cut.getPoints()[0].x, point), cv.cvPoint(cut.getPoints()[1].x, point), COL_GREEN)
	lib.drawBoundingBoxes(image, comp, 4, COL_GREEN)
	#highgui.cvSaveImage('floodfillbilledet.png', blobImg)
	highgui.cvSaveImage('centerOfMass.png', image)
	
	showImage(image, 'name')
Пример #3
0
# Define cut
cut = lines[0]

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

out = highgui.cvLoadImage (filename)

comp_dict = {}
featureDetector.floodFillLine(image, out, points, cut, lo, up, comp_dict)

# Set margin
margin = 15

# Draw margin
lib.drawMargin(out, cut, margin)

# Set up constraints
constraints = regionSelector.Constraints(cv.cvGetSize(image), cut, margin, 0.002, 0.25)

# Prune components
newComponents = regionSelector.pruneRegions(comp_dict, constraints)

# Draw boxes of selected components
#lib.drawBoundingBoxes(out, newComponents)
# Get grids
grid = grid.gridIt(out, newComponents, 5)
for point in grid:
	lib.plot(image, point, 1)

#lib.drawLines(out)