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
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)