Beispiel #1
0
def getSettingsForRunId(runId):
	"""Return the settings instance for a given run"""
	runInstance = Run.selectBy(id=runId)[0]

	# Get the cut ratios
	cutRatios = getCutRatiosForRunId(runId)

	settings = Settings(cutRatios)
	settings.setThresholds(runInstance.trsh1, runInstance.trsh2)
	settings.setLo(runInstance.lo)
	settings.setUp(runInstance.up)
	settings.setMarginPercentage(runInstance.marginPercentage)

	return settings
Beispiel #2
0
def main():
	"""
	Just the test
	This method is a good resource on how to handle the results.
	Save images in this method if you have to.
	"""

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

	cutRatios = [lib.PHI]
	#cutRatios = [0.618]
	settings = Settings(cutRatios)
	image = highgui.cvLoadImage (filename)
	thickness = 4
	settings.setMarginPercentage(0.025)
	settings.setMethod(sys.argv[3])
	cut = int(sys.argv[2])
	winname = sys.argv[1]
	#settings.setThresholds(100,150)
	# Set the color for the boxes
	#color = lib.COL_BLACK
	#color = lib.COL_WHITE
	#color = lib.COL_RED
	color = lib.COL_GREEN
	#color = lib.COL_BLUE

	blobImg = blobResult(image, settings, cut)
	boxxImg = boundingBoxResult(image, settings, cut, thickness, color)
	cutt = lib.findMeans(cv.cvGetSize(image), settings.cutRatios[0])[cut]
	# cuttet verdi, dog skal det vi generaliseres lidt
	oriantesen = cutt.getPoints()[0].x == cutt.getPoints()[1].x
	if oriantesen:
		cutPixel = cutt.getPoints()[1].x
	else:
		cutPixel = cutt.getPoints()[1].y
	
	if oriantesen:
	#	print 'hej'
		cv.cvLine(boxxImg, cv.cvPoint(cutPixel, cutt.getPoints()[0].y), cv.cvPoint(cutPixel, cutt.getPoints()[1].y), lib.COL_RED)
	else:
		cv.cvLine(boxxImg, cv.cvPoint(cutt.getPoints()[0].x, cutPixel), cv.cvPoint(cutt.getPoints()[1].x, cutPixel), lib.COL_RED)
	# Save images
	highgui.cvSaveImage('flood_cut_%s.png' % cut, boxxImg)
	highgui.cvSaveImage('blobs_cut_%s.png' % cut, blobImg)

	# Show images
	compareImages(blobImg, boxxImg, "blob", winname)
Beispiel #3
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.61]
	settings = Settings(cutRatios)
	image = highgui.cvLoadImage (filename)
	thickness = 4
	settings.setMarginPercentage(0.025)
	cutNo = int(sys.argv[2])
	
	cut = lib.findMeans(cv.cvGetSize(image), settings.cutRatios[0])[cutNo]
	
	# Get the BW edge image
	edgeImage = naiveMethod.getEdgeImage(image, settings)

	(blobImg, comp) = naiveMethod.analyzeCut(image, edgeImage, cut, settings, 'True')
	#liste af liste 
	
	gridPointsList = grid.gridIt(blobImg, comp)
	#print gridPointsList
	points = centerOfMass(gridPointsList)
	#(x,y)
	for point in points:
		cv.cvLine(image, cv.cvPoint(point, 0), cv.cvPoint(point,600), COL_GREEN)
	lib.drawBoundingBoxes(image, comp)
	
	#highgui.cvSaveImage('floodfillbilledet.png', blobImg)
	#highgui.cvSaveImage('boindingboxbilledet.png', boxxImg)
	
	showImage(image, 'name')
Beispiel #4
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')
def main():
	"""
	Just the test
	This method is a good resource on how to handle the results.
	Save images in this method if you have to.
	"""

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

	cutRatios = [lib.PHI]
	#cutRatios = [0.75]
	ratios = (0.51803398874999995, 0.56803398875, 0.61803398875000004, 0.66666000000000003, 0.71803398875000002, 0.76803398874999995, 0.81803398875, 0.86803398875000004 , 0.91803398874999997, 0.96803398875000002)
	settings = Settings(cutRatios)
	image = highgui.cvLoadImage (filename)
	thickness = 4
	settings.setMarginPercentage(0.024)
	cuts = (0,1,2,3)
	cut = int(sys.argv[2])
	winname = sys.argv[3]+".png"
	#settings.setThresholds(100,150)
	# Set the color for the boxes
	#color = lib.COL_BLACK
	#color = lib.COL_WHITE
	#color = lib.COL_RED
	color = lib.COL_GREEN
	#color = lib.COL_BLUE
	tmp = 0
	for r in cuts:
		cut = r
		print str(r), '---------------------------------'
		for i in ratios:
			#settings = Settings(cutRatios)
			print i
			cutd = lib.findMeans(cv.cvGetSize(image), i)[cut]
			edgeImage = naiveMethod.getEdgeImage(image, settings)
			components = naiveMethod.analyzeCut(image, edgeImage, cutd, settings)
			print len(components)		
			tmp = tmp + len(components)
	print tmp
	blobImg = blobResult(image, settings, cut)
	boxxImg = boundingBoxResult(image, settings, cut, thickness, color)
	cutt = lib.findMeans(cv.cvGetSize(image), settings.cutRatios[0])[cut]
	# cuttet verdi, dog skal det vi generaliseres lidt
	oriantesen = cutt.getPoints()[0].x == cutt.getPoints()[1].x
	if oriantesen:
		cutPixel = cutt.getPoints()[1].x
	else:
		cutPixel = cutt.getPoints()[1].y
	
	if oriantesen:
	#	print 'hej'
		cv.cvLine(boxxImg, cv.cvPoint(cutPixel, cutt.getPoints()[0].y), cv.cvPoint(cutPixel, cutt.getPoints()[1].y), lib.COL_RED)
	else:
		cv.cvLine(boxxImg, cv.cvPoint(cutt.getPoints()[0].x, cutPixel), cv.cvPoint(cutt.getPoints()[1].x, cutPixel), lib.COL_RED)
	# Save images
	highgui.cvSaveImage('floodfillbilledet.png', blobImg)
	highgui.cvSaveImage(winname, boxxImg)

	# Show images
	compareImages(blobImg, boxxImg, "blob", winname)