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)
threshold2 = int(sys.argv[3]) else: threshold1 = 100 image = highgui.cvLoadImage (filename) if not image: print "Error loading image '%s'" % filename print "" sys.exit(-1) print "Finding edges using Canny" bwe = cv.cvCreateImage(cv.cvGetSize(image), 8, 1) out = cv.cvCreateImage(cv.cvGetSize(image), 8, 3) #edgeDetector.findEdges(image, out, threshold1, threshold2) edgeDetector.findBWEdges(image, bwe, threshold1, threshold2) #set if you need the image and the Edges togeter #cv.cvNot(bwe, bwe) cv.cvCopy(image, out, bwe) outname = "edgeDetectorTest" orgname = "Original" nystr = str(str(threshold1)+'-'+str(threshold2)+'.png') print nystr highgui.cvNamedWindow (outname, highgui.CV_WINDOW_AUTOSIZE) highgui.cvNamedWindow (orgname, highgui.CV_WINDOW_AUTOSIZE) highgui.cvSaveImage(nystr, out) while True: