def segment(image, addr, extras): clone = cv.CloneImage(image) log = cap.logger(extras, image) components = cap.findCCs(image, erasecol=255, doContinue=lambda col: col == 255, doSkip=lambda comp: comp[0] <= 20) #components = cap.spltCCs(components, cap.partsFromSegW(components, 20), projRadius=5, thresh=1) log.log(cap.drawComponents(clone, components)) while len(components) > nSegs: smallest = cap.argmin(components, itemgetter(0)) del(components[smallest]) assert(len(components) == nSegs) log.log(cap.drawComponents(clone, components)) segments = map(lambda comp: comp[3], components) log.log(cap.joinImagesH(segments)) segments = map(deRotate, segments) log.log(cap.joinImagesH(segments)) cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT) return segments
def segment(image, addr, extras): clone = cv.CloneImage(image) log = cap.logger(extras, image) components = cap.findCCs(image, erasecol=255, doContinue=lambda col: col == 255, doSkip=lambda comp: comp[0] <= 20) #components = cap.spltCCs(components, cap.partsFromSegW(components, 20), projRadius=5, thresh=1) log.log(cap.drawComponents(clone, components)) while len(components) > nSegs: smallest = cap.argmin(components, itemgetter(0)) del (components[smallest]) assert (len(components) == nSegs) log.log(cap.drawComponents(clone, components)) segments = map(lambda comp: comp[3], components) log.log(cap.joinImagesH(segments)) segments = map(deRotate, segments) log.log(cap.joinImagesH(segments)) cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT) return segments
def makeLUT(): lut = cv.CreateMat(1, 256, cv.CV_8UC1) colors = mycolors + (white, ) for i in xrange(256): lut[0, i] = colors[cap.argmin(map(lambda col: abs(i - col), colors))] return lut