def preprocess(image):
    image = cv2.GaussianBlur(image, (5, 5), 0)  # Blurring the image
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)  # Grey scaling the image
    image = cv2.adaptiveThreshold(
        image,
        255,
        cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
        cv2.THRESH_BINARY,
        11, 10)
    ''' Thresholding the image (Converts greyscale to binary),
        using adaptive threshold for best results '''
    im2, contours, hierarchy = cv2.findContours(
        image,
        cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)
    ''' Finding the contours in the image'''
    image.fill(255)
    cv2.drawContours(image, contours, -1, (0, 0, 255))
    ''' Drawing the contours on the image before displaying'''
    contours.reverse()
    segments = segments_to_numpy([cv2.boundingRect(c) for c in contours])
    segments = numpy.delete(segments, 0, 0)
    euler_list, inner_segments = find_euler_and_inner_segments(segments, 1)
    segments, euler_list, central_x, central_y = segment_blocks(
        segments, inner_segments, euler_list)
    return image, segments, euler_list, central_x, central_y
Esempio n. 2
0
 def _segment( self, image ):
     self.image= image
     image= cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
     image = cv2.adaptiveThreshold(image, maxValue=255, adaptiveMethod=cv2.ADAPTIVE_THRESH_GAUSSIAN_C, thresholdType=cv2.THRESH_BINARY, blockSize=self.block_size, C=self.c)
     contours,hierarchy = cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
     segments= segments_to_numpy( [cv2.boundingRect(c) for c in contours] )
     self.contours, self.hierarchy= contours, hierarchy #store, may be needed for debugging
     return segments
Esempio n. 3
0
def read_boxfile(path):
    classes = []
    segments = []
    with open(path) as f:
        for line in f:
            s = line.split(" ")
            assert len(s) == 6
            assert s[5] == '0\n'
            classes.append(s[0].decode('utf-8'))
            segments.append(map(int, s[1:5]))
    return classes_to_numpy(classes), segments_to_numpy(segments)
Esempio n. 4
0
def read_boxfile( path ):
    classes=  []
    segments= []
    with open(path) as f:
        for line in f:
            s= line.split(" ")
            assert len(s)==6
            assert s[5]=='0\n'
            classes.append( s[0].decode('utf-8') )
            segments.append( map(int, s[1:5]))
    return classes_to_numpy(classes), segments_to_numpy(segments)
def read_boxfile(path):
    classes = []
    segments = []
    with io.open(path, encoding="utf-8") as f:
        for line in f:
            s = line.split(" ")
            assert len(s) == 6
            assert s[5] == '0\n'
            classes.append(s[0])
            segments.append(list(map(int, s[1:5])))
    return classes_to_numpy(classes), segments_to_numpy(segments)
Esempio n. 6
0
 def _segment(self, image):
     self.image = image
     image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
     image = cv2.adaptiveThreshold(
         image,
         maxValue=255,
         adaptiveMethod=cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
         thresholdType=cv2.THRESH_BINARY,
         blockSize=self.block_size,
         C=self.c)
     contours, hierarchy = cv2.findContours(image, cv2.RETR_LIST,
                                            cv2.CHAIN_APPROX_SIMPLE)
     segments = segments_to_numpy([cv2.boundingRect(c) for c in contours])
     self.contours, self.hierarchy = contours, hierarchy  #store, may be needed for debugging
     return segments
def preprocess_with_display(image):
    copy = image.copy()
    cv2.imshow('Display', image)
    cv2.waitKey(0)
    image = cv2.GaussianBlur(image, (5, 5), 0)  # Blurring the image
    cv2.imshow('Display', image)
    print "After Guassian blurring"
    cv2.waitKey(0)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)  # Grey scaling the image
    cv2.imshow('Display', image)  # Displaying the image
    print "After Greyscaling"
    cv2.waitKey(0)
    image = cv2.adaptiveThreshold(
        image,
        255,
        cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
        cv2.THRESH_BINARY,
        11, 10)
    ''' Thresholding the image (Converts greyscale to binary),
        using adaptive threshold for best results '''
    cv2.imshow('Display', image)
    im2, contours, hierarchy = cv2.findContours(
        image,
        cv2.RETR_LIST,
        cv2.CHAIN_APPROX_SIMPLE)
    ''' Finding the contours in the image'''
    image.fill(255)
    cv2.drawContours(image, contours, -1, (0, 0, 255))
    ''' Drawing the contours on the image before displaying'''
    cv2.imshow('Display', image)
    print "After detecting Contours"
    cv2.waitKey(0)
    contours.reverse()
    segments = segments_to_numpy([cv2.boundingRect(c) for c in contours])
    segments = numpy.delete(segments, 0, 0)
    euler_list, inner_segments = find_euler_and_inner_segments(segments, 1)
    segments, euler_list, central_x, central_y = segment_blocks(
        segments, inner_segments, euler_list)
    draw_segments(copy, segments)
    '''Draw the segments on the copy image (cant add color to greyscaled image)'''
    cv2.imshow('Display', copy)
    print "After Segmentation"
    cv2.waitKey(0)
    return image, segments, euler_list, central_x, central_y