コード例 #1
0
import cv2
import numpy as np
import matplotlib.pyplot as plt
from active_weather import __otsu_bin__, __pca__, __create_mask__
import cPickle, gzip
import math

img = cv2.imread("/home/ggdhines/eastwind-wag-279-1946_0523-0.JPG")

table = img[276:1158, 126:1476]
# plt.imshow(table)
# plt.show()

cv2.imwrite("/home/ggdhines/table.jpg", table)

pca_image, threshold, inverted = __pca__(table, __otsu_bin__)

cv2.imwrite("/home/ggdhines/pca_example.jpg", pca_image)

mask = __create_mask__(table)

cv2.imwrite("/home/ggdhines/mask_example.jpg", mask)

masked_image = np.max([mask, pca_image], axis=0)

plt.imshow(masked_image, cmap="gray")
plt.show()

# from sklearn.datasets import fetch_mldata
from sklearn import datasets, svm, metrics
コード例 #2
0
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]
コード例 #3
0
text = []



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]
コード例 #4
0
import matplotlib.pyplot as plt
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]
コード例 #5
0
text = []

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]
コード例 #6
0
#!/usr/bin/env python
from __future__ import print_function
from active_weather import __extract_region__, __create_mask__, __otsu_bin__, __pca__, __mask_lines__, __binary_threshold_curry__
import matplotlib.pyplot as plt
import numpy as np
import cv2
from tensor import mnist_tensor

table = __extract_region__("/home/ggdhines/eastwind-wag-279-1946_0523-0.JPG",
                           region=(127, 1467, 275, 1151))

pca_image, threshold, inverted = __pca__(table,
                                         __binary_threshold_curry__(175))
print(threshold)
mask = __create_mask__(table)

masked_image = __mask_lines__(pca_image, mask)

kernel = np.ones((5, 5), np.uint8)
# masked_image = 255 - masked_image
# closing = cv2.morphologyEx(masked_image, cv2.MORPH_CLOSE, kernel)
# closing = 255 - closing

im2, contours, hierarchy = cv2.findContours(masked_image.copy(), cv2.RETR_TREE,
                                            cv2.CHAIN_APPROX_SIMPLE)

for cnt in contours:
    x, y, w, h = cv2.boundingRect(cnt)
    perimeter = cv2.arcLength(cnt, True)

    if (w / h > 5) or (h / w > 5) or (perimeter < 20):
コード例 #7
0
#!/usr/bin/env python
from __future__ import print_function
from active_weather import __extract_region__,__create_mask__,__otsu_bin__,__pca__,__mask_lines__,__binary_threshold_curry__
import matplotlib.pyplot as plt
import numpy as np
import cv2
from tensor import mnist_tensor

table = __extract_region__("/home/ggdhines/eastwind-wag-279-1946_0523-0.JPG",region=(127,1467,275,1151))

pca_image, threshold, inverted = __pca__(table, __binary_threshold_curry__(175))
print(threshold)
mask = __create_mask__(table)

masked_image = __mask_lines__(pca_image,mask)

kernel = np.ones((5,5),np.uint8)
# masked_image = 255 - masked_image
# closing = cv2.morphologyEx(masked_image, cv2.MORPH_CLOSE, kernel)
# closing = 255 - closing


im2, contours, hierarchy = cv2.findContours(masked_image.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

for cnt in contours:
    x, y, w, h = cv2.boundingRect(cnt)
    perimeter = cv2.arcLength(cnt, True)

    if (w/h > 5) or (h/w > 5) or (perimeter < 20):
        cv2.drawContours(masked_image, [cnt], 0, 255, -1)
    else:
コード例 #8
0
ファイル: example.py プロジェクト: amyrebecca/aggregation
import cv2
import numpy as np
import matplotlib.pyplot as plt
from active_weather import __otsu_bin__,__pca__,__create_mask__
import cPickle, gzip
import math

img = cv2.imread("/home/ggdhines/eastwind-wag-279-1946_0523-0.JPG")

table = img[276:1158,126:1476]
# plt.imshow(table)
# plt.show()

cv2.imwrite("/home/ggdhines/table.jpg",table)

pca_image,threshold,inverted = __pca__(table,__otsu_bin__)

cv2.imwrite("/home/ggdhines/pca_example.jpg",pca_image)

mask = __create_mask__(table)

cv2.imwrite("/home/ggdhines/mask_example.jpg",mask)

masked_image = np.max([mask,pca_image],axis=0)

plt.imshow(masked_image,cmap="gray")
plt.show()

# from sklearn.datasets import fetch_mldata
from sklearn import datasets, svm, metrics