예제 #1
0
def getBlobImage(original, settings, cutNo):
	"""Show the colored blobs in an image at the cut specified
	by cutNo as int. The cut ratio are placed in the settings and only
	the first cut in this ratio-list will be analyzed.
	original should be the image data
	settings should be of class Settings
	cutNo as int"""

	# Get the cut defined by cutNo from the cuts from the first cut ratio in settings
	cut = lib.findMeans(cv.cvGetSize(original), settings.cutRatios[0])[cutNo]

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

	# Find the margin
	margin = marginCalculator.getPixels(original, cut, settings.marginPercentage)

	# Clever hack for putting the cut in an array
	tmp = []
	tmp.append(cut)

	# Get results
	(blobImage, components) = analyzeCut(original, edgeImage, cut, settings, True)
	lib.drawLines(blobImage, blobImage, tmp)
	lib.drawMargin(blobImage, cut, margin)

	# Return result, what a surprise
	return blobImage
예제 #2
0
def getBoundingBoxImage(original, settings, cutNo, thickness=1, color=None):
	"""Same as above but will paint the bounding boxes
	original should be the image data
	settings should be of class Settings
	cutNo as int
	color as CV_RGB"""

	# Get the cut defined by cutNo from the cuts from the first cut ratio in settings
	cut = lib.findMeans(cv.cvGetSize(original), settings.cutRatios[0])[cutNo]

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

	# Find the margin
	margin = marginCalculator.getPixels(original, cut, settings.marginPercentage)

	tmp = []
	tmp.append(cut)
	components = analyzeCut(original, edgeImage, cut, settings)
	lib.drawMargin(original, cut, margin)

	# Draw the components
	lib.drawBoundingBoxes(original, components, thickness, color)

	return original
예제 #3
0
def analyzeCut(original, edgeImage, cut, settings, showBlobs=False):
	"""Extract the interesting features in the vicinity of a given cut"""
	# Get all data from the settings
	lo = settings.lo
	up = settings.up

	# Set up the margin with respect to the cut
	margin = marginCalculator.getPixels(original, cut, settings.marginPercentage)
	superMargin = 0
	# ^^ We don't use superMargin

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

	# Create temporary images
	blurImage = cv.cvCreateImage(cv.cvGetSize(original), 8, 3)
	workImage = cv.cvCreateImage(cv.cvGetSize(original), 8, 3)

	# Create a blurred copy of the original
	cv.cvSmooth(original, blurImage, cv.CV_BLUR, 3, 3, 0)

	# Superimpose the edges onto the blured image
	cv.cvNot(edgeImage, edgeImage)
	cv.cvCopy(blurImage, workImage, edgeImage)

	# We're done with the blurred image now
	cv.cvReleaseImage(blurImage)

	# Get the edges back to white
	cv.cvNot(edgeImage, edgeImage)

	# Retrive the regions touching the cut
	component_dictionary = featureDetector.ribbonFloodFill(original, edgeImage, workImage, cut, margin, lo, up)

	#start expanded

	# Prune components BEFORE we delete the workImage
	tmpnewComponents = regionSelector.pruneExpandedRegions(component_dictionary, constraints)
	newComponents = regionSelector.pruneExpandedRagionsto(tmpnewComponents, constraints, cut, workImage)

	# Clean up only if we do not return the image
	if not showBlobs:
		cv.cvReleaseImage(workImage)

	# Return the dictionary of accepted components or both
	if not showBlobs:
		return newComponents
	else:
		return (workImage, newComponents)