Example #1
0
def main():
    image = cv2.imread('test_images/simple_grid.png')
    image_HSV = utils.BGR_to_HSV(image)
    
    # NOTE HSV IN PYTHON
    # range from [0, 0, 0] to [180, 255, 255]
    # MIN = np.array([0, 0, 200], np.uint8)
    # MAX = np.array([10, 10, 255], np.uint8)
    
    min_max = utils.get_HSV_range(utils.HSV_BLACK)
    print "max : %s" % min_max['max']
    print "min : %s" % min_max['min']
    # MIN = np.array([0, 0, 0], np.uint8)
    # MAX = np.array([10, 10, 10], np.uint8)
    
    # below = utils.get_colored_image(image_HSV.shape, utils.HSV_BLACK)
    #     above = utils.get_colored_image(image_HSV.shape, utils.HSV_BLACK)
    
    # below = utils.get_colored_image(image_HSV.shape, (0, 0, 90))
    # above = utils.get_colored_image(image_HSV.shape, (10, 10, 100))
    
    thresh = cv2.inRange(image_HSV, min_max['min'], min_max['max'])
    cv.NamedWindow('a_window', cv.CV_WINDOW_AUTOSIZE)
    cv2.imshow('a_window', thresh)
    cv.WaitKey(1000)
Example #2
0
 def find_regions_by_border_color(cls, image_BGR, hsv_border_color=utils.HSV_BLACK):
     image_HSV = utils.BGR_to_HSV(image_BGR)
     min_max = utils.HSV_BLACK_RANGE if cls.BLACK_BORDER else utils.get_HSV_range(hsv_border_color)
     thresh = utils.gray_to_BGR(cv2.inRange(image_HSV, min_max['min'], min_max['max']))
     
     # utils.show_image(thresh, 2000, 'debug')
 
     contours = Contour.find_contours(thresh)
     contours = Contour.remove_frame(contours)
     contours = Contour.without_small_contours(contours,         
                                     utils.image_size(image_BGR)*cls.MIN_RATIO)
     regions = []
     for contour in contours:
         regions.append(Region.from_contour(contour))        
     
     return regions