for fname in glob.glob("/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/*.JPG")[:40]: fname = "/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/Bear-AG-29-1940-0009.JPG" img = active_weather.__extract_region__(fname) id_ = fname.split("/")[-1][:-4] print(id_) # set a baseline for performance with otsu's binarization mask = active_weather.__create_mask__(img) horizontal_grid, vertical_grid = active_weather.__cell_boundaries__(img) pca_image, threshold, inverted = active_weather.__pca__(img, active_weather.__otsu_bin__) masked_image = active_weather.__mask_lines__(pca_image, mask) # plt.imshow(masked_image) # plt.show() im2, contours, hierarchy = cv2.findContours(masked_image.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) for cnt,h in zip(contours,hierarchy[0]): if h[0] == -1: continue leftmost = tuple(cnt[cnt[:, :, 0].argmin()][0])[0] rightmost = tuple(cnt[cnt[:, :, 0].argmax()][0])[0] topmost = tuple(cnt[cnt[:, :, 1].argmax()][0])[1] bottommost = tuple(cnt[cnt[:, :, 1].argmin()][0])[1] perimeter = cv2.arcLength(cnt, True)
for fname in glob.glob( "/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/*.JPG" )[:40]: fname = "/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/Bear-AG-29-1940-0005.JPG" img = __extract_region__(fname) id_ = fname.split("/")[-1][:-4] print(id_) # set a baseline for performance with otsu's binarization horizontal_grid, vertical_grid = __cell_boundaries__(img) thres_alg = __binary_threshold_curry__(60) mask = __create_mask__(img) pca_image, threshold, inverted = __pca__(img, thres_alg) masked_image = __mask_lines__(pca_image, mask) plt.imshow(masked_image, cmap="gray") plt.show() for h_index in range(len(horizontal_grid) - 1): row = masked_image[horizontal_grid[h_index]:horizontal_grid[h_index + 1], :] for v_index in range(len(vertical_grid) - 1): cell = row[:, vertical_grid[v_index]:vertical_grid[v_index + 1]] if len(np.where(cell < 255)[0]) < 30: continue x_pts = np.where(cell < 255)[1]
import numpy as np for fname in glob.glob("/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/*.JPG")[:40]: fname = "/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/Bear-AG-29-1940-0005.JPG" img = __extract_region__(fname) id_ = fname.split("/")[-1][:-4] print(id_) # set a baseline for performance with otsu's binarization horizontal_grid,vertical_grid = __cell_boundaries__(img) thres_alg = __binary_threshold_curry__(60) mask = __create_mask__(img) pca_image,threshold,inverted = __pca__(img,thres_alg) masked_image = __mask_lines__(pca_image,mask) plt.imshow(masked_image,cmap="gray") plt.show() for h_index in range(len(horizontal_grid)-1): row = masked_image[horizontal_grid[h_index]:horizontal_grid[h_index+1],:] for v_index in range(len(vertical_grid)-1): cell = row[:,vertical_grid[v_index]:vertical_grid[v_index+1]] if len(np.where(cell<255)[0]) < 30: continue x_pts = np.where(cell<255)[1] # plt.imshow(masked_image[:,vertical_grid[v_index]:vertical_grid[v_index+1]],cmap="gray")
def __run__(table, mask): masked_image = __mask_lines__(table, mask) transcriptions = __ocr_image__(masked_image) return transcriptions
for fname in glob.glob( "/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/*.JPG" )[:40]: fname = "/home/ggdhines/Databases/old_weather/aligned_images/Bear/1940/Bear-AG-29-1940-0009.JPG" img = active_weather.__extract_region__(fname) id_ = fname.split("/")[-1][:-4] print(id_) # set a baseline for performance with otsu's binarization mask = active_weather.__create_mask__(img) horizontal_grid, vertical_grid = active_weather.__cell_boundaries__(img) pca_image, threshold, inverted = active_weather.__pca__( img, active_weather.__otsu_bin__) masked_image = active_weather.__mask_lines__(pca_image, mask) # plt.imshow(masked_image) # plt.show() im2, contours, hierarchy = cv2.findContours(masked_image.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) for cnt, h in zip(contours, hierarchy[0]): if h[0] == -1: continue leftmost = tuple(cnt[cnt[:, :, 0].argmin()][0])[0] rightmost = tuple(cnt[cnt[:, :, 0].argmax()][0])[0] topmost = tuple(cnt[cnt[:, :, 1].argmax()][0])[1] bottommost = tuple(cnt[cnt[:, :, 1].argmin()][0])[1]