def test_get_adj_boxes(self, kn005): kn = KnPage(kn005) boxes = [box01, box02, box03, box04, box05, box06, box11, box12, box13, box14, box15, box16] result = kn.get_adj_boxes(boxes, box01) assert list(set(result) - set([box01, box02, box03, box04, box05, box06])) == []
def test_get_chars(self, kaisetu): kn = KnPage(params=kaisetu) kn.get_chars() assert len(kn.chars) == 12 assert len(kn.chars[0]) == 5 assert len(kn.chars[1]) == 36 assert len(kn.chars[2]) == 35 assert len(kn.chars[3]) == 33 assert len(kn.chars[4]) == 34
def test_sweep_included_boxes(self, kn005): box1 = (20, 30, 10, 10) box2 = (25, 35, 15, 15) box3 = (35, 45, 10, 10) box4 = (35, 20, 20, 20) box5 = (10, 45, 20, 20) box6 = (27, 37, 10, 10) kn = KnPage(params=kn005) result = kn.sweep_included_boxes([box1, box2, box3, box4, box5, box6]) assert len(result) == 5
def test_get_boundingBox(self, kn005): box1 = (20, 30, 10, 10) box2 = (25, 35, 15, 15) box3 = (35, 45, 10, 10) box4 = (35, 20, 20, 20) box5 = (10, 45, 20, 20) kn = KnPage(params=kn005) outer_box = kn.get_boundingBox([box1, box2,box3]) assert outer_box == (20,30,25,25) outer_box = kn.get_boundingBox([box1, box2,box3,box4,box5]) assert outer_box == (10,20,45,45)
def test_get_boundingBox(self, kn005): box1 = (20, 30, 10, 10) box2 = (25, 35, 15, 15) box3 = (35, 45, 10, 10) box4 = (35, 20, 20, 20) box5 = (10, 45, 20, 20) kn = KnPage(params=kn005) outer_box = kn.get_boundingBox([box1, box2, box3]) assert outer_box == (20, 30, 25, 25) outer_box = kn.get_boundingBox([box1, box2, box3, box4, box5]) assert outer_box == (10, 20, 45, 45)
def test_include(self, kn005): box1 = (20, 30, 10, 10) box2 = (25, 35, 15, 15) box3 = (35, 45, 10, 10) box4 = (35, 20, 20, 20) box5 = (10, 45, 20, 20) box6 = (27, 37, 10, 10) kn = KnPage(params=kn005) assert not kn.include(box1, box2) assert not kn.include(box1, box3) assert not kn.include(box1, box4) assert kn.include(box2, box6)
def test_save_char_img_to_file(self, kaisetu): kn = KnPage(params=kaisetu) kn.clear_noise() kn.get_line_imgs() kn.get_chars() kn.check_chars() save_char_img_to_file(kn, DATA_DIR, 0, 0) save_char_img_to_file(kn, DATA_DIR, 1, 1) save_char_img_to_file(kn, DATA_DIR, line=2) save_char_img_to_file(kn, DATA_DIR, count=2) save_char_img_to_file(kn, DATA_DIR) assert kn != None
def test_get_line_imgs(self, kaisetu): kn = KnPage(params=kaisetu) kn.clear_noise() kn.get_line_imgs() for i, img in enumerate(kn.line_imgs): kn.write(DATA_DIR + "/1062973/k009/00/line_img_{0}.jpeg".format(i), img)
def test_new(self, knp): kn = KnPage(params=knp) assert kn.img != None assert kn.img.shape != (100, 100, 3) assert kn.height == 2789 assert kn.width == 3466 assert kn.depth == 3 return kn
def test_get_adj_boxes(self, kn005): box01 = (20, 30, 10, 10) box02 = (25, 35, 15, 15) box03 = (35, 45, 10, 10) box04 = (35, 20, 20, 20) box05 = (10, 45, 20, 20) box06 = (27, 37, 10, 10) box11 = (120, 30, 10, 10) box12 = (125, 35, 15, 15) box13 = (135, 45, 10, 10) box14 = (135, 20, 20, 20) box15 = (110, 45, 20, 20) box16 = (127, 37, 10, 10) boxes = [box01,box02,box03,box04,box05,box06, box11,box12,box13,box14,box15,box16] kn = KnPage(params=kn005) result = kn.get_adj_boxes(boxes, box01) assert list( set(result) - set([box01,box02,box03,box04,box05,box06]) ) == []
def test_get_adj_boxes(self, kn005): box01 = (20, 30, 10, 10) box02 = (25, 35, 15, 15) box03 = (35, 45, 10, 10) box04 = (35, 20, 20, 20) box05 = (10, 45, 20, 20) box06 = (27, 37, 10, 10) box11 = (120, 30, 10, 10) box12 = (125, 35, 15, 15) box13 = (135, 45, 10, 10) box14 = (135, 20, 20, 20) box15 = (110, 45, 20, 20) box16 = (127, 37, 10, 10) boxes = [ box01, box02, box03, box04, box05, box06, box11, box12, box13, box14, box15, box16 ] kn = KnPage(params=kn005) result = kn.get_adj_boxes(boxes, box01) assert list( set(result) - set([box01, box02, box03, box04, box05, box06])) == []
def test_boxes_coodinates_data_to_textfile(self, kn005): kn = KnPage(params=kn005) write_boxes_coordinates_data_to_textfile(kn, DATA_DIR, ext=".when_zero.txt") kn.getContours() write_boxes_coordinates_data_to_textfile(kn, DATA_DIR, ext=".after_getContour.txt") kn.getCentroids() write_boxes_coordinates_data_to_textfile(kn, DATA_DIR, ext=".after_getCentroids.txt") assert kn != None
def test_get_tenth(self, kaiten): kn = KnPage(params=kaiten) kn.clear_noise() result = kn.get_tenth(2) assert result == 1.8
def test_check_chars(self, kaisetu): kn = KnPage(params=kaisetu) kn.get_chars() kn.check_chars() assert len(kn.chars) == 12 assert len(kn.chars[4]) == 35
def test_one_degree_plus(self, kaiten): kn = KnPage(params=kaiten) kn.clear_noise() result = kn.one_degree_plus(0) assert result == 240
def test_clear_noise(self, knp): kn = KnPage(params=knp) kn.clear_noise() kn.write(DATA_DIR + '/knp_bw_not_tozero.jpeg', kn.bw_not_tozero)
def test_get_height_median(self, kaisetu): kn = KnPage(params=kaisetu) kn.get_chars() result = kn.get_height_median(kn.chars[1]) assert result == 35
def test_get_line_imgs(self, kaisetu): kn = KnPage(params=kaisetu) kn.clear_noise() kn.get_line_imgs() for i, img in enumerate(kn.line_imgs): kn.write(DATA_DIR+"/1062973/k009/00/line_img_{0}.jpeg".format(i), img)
def test_sweep_included_boxes_2(self, kn005): kn = KnPage(params=kn005) kn.sweep_included_boxes() kn.write_boxes_to_file(DATA_DIR)
def test_intersect(self, kn005): box1 = (20, 30, 10, 10) box2 = (25, 35, 15, 15) box3 = (35, 45, 10, 10) box4 = (35, 20, 20, 20) box5 = (10, 45, 20, 20) kn = KnPage(params=kn005) assert kn.intersect(box1, box2) assert kn.intersect(box1, box3) assert not kn.intersect(box1, box3, 0, 0) assert kn.intersect(box1, box3) assert kn.intersect(box1, box4) assert not kn.intersect(box1, box4, 0, 0) assert kn.intersect(box1, box5) assert not kn.intersect(box1, box5, 0, 0) assert kn.intersect(box2, box3) assert kn.intersect(box2, box4) assert kn.intersect(box2, box5) assert kn.intersect(box3, box4) assert not kn.intersect(box3, box4, 0, 0) assert kn.intersect(box3, box5) assert not kn.intersect(box3, box5, 0, 0) assert kn.intersect(box4, box5) assert not kn.intersect(box4, box5, 0, 0)
def test_getCentroids(self, kn005): kn = KnPage(params=kn005) kn.getCentroids() assert kn.centroids != None assert len(kn.centroids) == 3160
def test_get_x_zero(self, kaiten): kn = KnPage(params=kaiten) kn.clear_noise() result = kn.get_x_zero(kn.bw_not_tozero) assert result == 112
def test_getContours(self, kn005): kn = KnPage(params=kn005) kn.getContours() assert kn.gray != None assert kn.contours != None assert kn.hierarchy != None
def test_write(self, kn005): #dataDirectory = tmpdir.mkdir('data') #sampleFile = dataDirectory.join("sample.jpeg") kn = KnPage(params=kn005) #kn.write(sampleFile) kn.write("/tmp/outfile.jpeg")
def test_adust_rotation(self, kaiten): kn = KnPage(params=kaiten) kn.clear_noise() result = kn.adjust_rotation() assert result == 2.2
def test_write_original_with_collected_boxes_to_file(self, kn005): kn = KnPage(params=kn005) write_original_with_collected_boxes_to_file(kn, DATA_DIR) assert kn != None
def test_write_original_with_contour_and_rect_to_file(self, kn005): kn = KnPage(params=kn005) write_original_with_contour_and_rect_to_file(kn, DATA_DIR) assert kn != None
def test_clear_noise(self, knp): kn = KnPage(params=knp) kn.clear_noise() kn.write(DATA_DIR+'/knp_bw_not_tozero.jpeg', kn.bw_not_tozero)
def test_intersect(self, knp): box01 = (20, 30, 10, 10) box02 = (25, 35, 15, 15) box03 = (35, 45, 10, 10) box04 = (35, 20, 20, 20) box05 = (10, 45, 20, 20) kp = KnPage(params=knp) assert kp.intersect(box01, box02) assert kp.intersect(box01, box03) assert not kp.intersect(box01, box03, 0, 0) assert kp.intersect(box01, box03) assert kp.intersect(box01, box04) assert not kp.intersect(box01, box04, 0, 0) assert kp.intersect(box01, box05) assert not kp.intersect(box01, box05, 0, 0) assert kp.intersect(box02, box03) assert kp.intersect(box02, box04) assert kp.intersect(box02, box05) assert kp.intersect(box03, box04) assert not kp.intersect(box03, box04, 0, 0) assert kp.intersect(box03, box05) assert not kp.intersect(box03, box05, 0, 0) assert kp.intersect(box04, box05) assert not kp.intersect(box04, box05, 0, 0)
def test_sweep_included_boxes_2(self, kn005): kn = KnPage(kn005) kn.getBoxesAndCentroids() kn.sweep_boxes_in_page_margin() kn.sweep_included_boxes() kn.sort_boxes() kn.write_boxes_to_file(fix='_no_inclusion')
def test_sweep_included_boxes(self, knp): kp = KnPage(knp) result = kp.sweep_included_boxes( [box01, box02, box03, box04, box05, box06]) assert len(result) == 5
def test_include(self, b1g101): knp = KnPage(b1g101) assert not knp.include(box01, box02) assert not knp.include(box01, box03) assert not knp.include(box01, box04) assert knp.include(box02, box06)
def test_writeContour(self, kn005): kn = KnPage(params=kn005) kn.getContours() writeContour(kn) assert kn != None
def test_write_gradients(self, kn005): kn = KnPage(params=kn005) kn.getGradients() write_gradients(kn, DATA_DIR) assert kn != None
def test_get_boundingBox(self, b1g101): knp = KnPage(b1g101) outer_box = knp.get_boundingBox([box01, box02, box03]) assert outer_box == (20, 30, 25, 25) outer_box = knp.get_boundingBox([box01, box02, box03, box04, box05]) assert outer_box == (10, 20, 45, 45)
def test_write_contours_bounding_rect_to_file(self, kn005): kn = KnPage(params=kn005) write_contours_bounding_rect_to_file(kn, DATA_DIR) assert kn != None
def test_write_binarized_to_file(self, kn005): kn = KnPage(params=kn005) kn.getBinarized() write_binarized_to_file(kn, DATA_DIR) assert kn != None
def test_write_contours_and_hierarchy_data_to_textfile(self, kn005): kn = KnPage(params=kn005) fpath = write_contours_and_hierarchy_data_to_textfile(kn, DATA_DIR, ext='.txt') assert kn != None assert os.path.exists(fpath)
def test_sweep_boxes_in_page_margin(self, kn005): kn = KnPage(params=kn005) kn.getBoxesAndCentroids() kn.sweep_boxes_in_page_margin() kn.sort_boxes() kn.write_boxes_to_file(fix='_trimed')