예제 #1
0
import sys
import matplotlib.pyplot as plt
import time

sys.path.append('.')
from docrec.strips.strips import Strips

# segmentation
print('=> Segmentation')
t0 = time.time()
strips = Strips(path='datasets/D2/mechanical/D002', filter_blanks=True)
strips.plot()
plt.show()
print('Strips elapsed time={:.2f} seconds'.format(time.time() - t0))
N = len(strips.strips)
fig = plt.figure(figsize=(8, 8), dpi=150)
for i in range(N):
    for j in range(N):
        if i + 1 == j:
            t0 = time.time()
            print(i, j, N)
            image = strips.pair(i, j, filled=True)
            print('Pairing time={:.2f} seconds'.format(time.time() - t0))
            plt.clf()
            plt.imshow(image)
            #plt.savefig('/home/thiagopx/temo/{}-{}.pdf'.format(i, j))
            plt.show()
#strips.plot()

예제 #2
0
    t0_global = time.time()
    print('=> Segmentation')
    t0 = time.time()
    #strips = StripsText(path=args.doc, filter_blanks=True)
    strips = Strips(path=args.doc, filter_blanks=True)
    print('Segmentation elapsed time={:.2f} seconds'.format(time.time() - t0))

    N = len(strips.strips)
    pcont = 0.2
    scores = np.zeros((N, N), dtype=np.int32)
    for i in range(N - 1):
        border = strips.strips[i].offsets_r
        j = i + 1

        print('=> Scoring [{}][{}]'.format(i, j))
        image = strips.pair(i, j, accurate=True, filled=True)
        h, w, _ = image.shape
        _, image_bin = cv2.threshold(cv2.cvtColor(image, cv2.COLOR_RGB2GRAY),
                                     0, 1, cv2.THRESH_BINARY +
                                     cv2.THRESH_OTSU)  # range [0, 1]
        temp = image_bin.astype(np.float32)
        image3 = np.stack([temp, temp, temp])

        batch = []
        total_inferences = 0
        yx = []
        labels = []
        for y in range(radius, h - radius):
            x = border[y]
            crop = image3[:, y - radius:y + radius + 1,
                          x - radius:x + radius + 1]