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)
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')
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')
print "Test plot and line scanner methods" points = lineScanner.naiveLineScanner(out, image, cut) out = highgui.cvLoadImage (filename) (out, components) = featureDetector.floodFillLine(image, out, points, cut, lo, up) print components[0].area # Test comp = cv.CvConnectedComp() seed = cv.cvPoint(200, 20) cv.cvFloodFill(image, seed, lib.COL_RED, cv.CV_RGB(lo,lo,lo), cv.CV_RGB(up,up,up),comp)# ,flags, None); print comp.area lib.drawBoundingBoxes(out, components) #lib.drawLines(out) winname1 = "Find regions" winname2 = "original" highgui.cvNamedWindow (winname1, highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow (winname2, highgui.CV_WINDOW_AUTOSIZE) while True: highgui.cvShowImage (winname1, out) highgui.cvShowImage (winname2, image) c = highgui.cvWaitKey(0)
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) #lib.drawLines(out) winname = "Find regions" highgui.cvNamedWindow (winname, highgui.CV_WINDOW_AUTOSIZE) while True: highgui.cvShowImage (winname, out) c = highgui.cvWaitKey(0) if c == 'q': print "Exiting ..." print ""