Esempio n. 1
0
def main():
    
    cv.NamedWindow("Result", 1)
    
    for name in os.listdir(os.getcwd()):
        try:
            print 'Start processing ' + str(name)
            print '##############################'

            animal = cv.LoadImage(name, cv.CV_LOAD_IMAGE_GRAYSCALE)
            cv.Threshold(animal, edge, 128 ,255, cv.CV_THRESH_BINARY_INV) 
            ncas = cv.FindContours(edge, cv.CreateMemStorage(), cv.CV_RETR_LIST, cv.CV_CHAIN_APPROX_NONE,(0,0))
   
            croped, ratio, box = cropRoi(animal, ncas)         
            cv.Threshold(croped,croped,128,255, cv.CV_THRESH_BINARY)

            del ncas
            cv.ShowImage("Result", croped)
            cv.WaitKey(0)
            saveImage(croped, name, savepath, animalpath)
            
            print '##############################'
                                     
        except IOError, e:
            print "Problem opening: ", e
Esempio n. 2
0
def cropImages(nc, image):
    print 'Croping images starts'
    images  =[]
    ratios  =[]
    boxes=[]

    # Checks if the clusterization was performed correctly so that there is a white figure on black beckground
    # After this block the image in all the cases should be WHITE on the BLACK background.
    check = checkBlack(image, nc)
    if check == 'blackonwhite':
        cv.Threshold(image,image,128,255, cv.CV_THRESH_BINARY_INV)
    elif check == 'whiteonblack':
        cv.Threshold(image,image,128,255, cv.CV_THRESH_BINARY)

    for i in range(countContours(nc)):
        contour = getContour(nc, i)
        if len(contour)> minconlength:
            croped, ratio, box = cropRoi(image, contour)
            ratios.append(ratio)
            images.append(croped)
            boxes.append(box)

    print 'Croping images finished'
    return images, ratios, boxes