Beispiel #1
0
def cut_(origin):
    img = common.bgr2gray_(origin)
    img = common.binary_(img, thresh=config.binary_threshold)

    cut, mask = common.grabCut_(origin, newmask=img)

    return cut
Beispiel #2
0
def main_(file_path="../data/img/1_1.jpg"):
    img = read_(file_path, shrink=1)
    # img = cut_(img)
    # img = roi_(img)

    if img.shape[0] * img.shape[1] > 400 * 400:
        img = chosen(img)
    img = 255 - img
    img = common.bgr2gray_(img)
    # # img = common.canny_(img)
    # # img = common.Remove_holes(img)
    img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                cv2.THRESH_BINARY, 9, -10)
    # img = cv2.bilateralFilter(img, 5, 100, 10)
    # img = common.Removing_small_connected_domain(img, 5)
    cv2.imshow("chosen", img)

    genFontImage(ImageFont.truetype('../data/font/msyhbd.ttf', 22), '2',
                 (14, 20))
    temp = cv2.imread("temp.jpg")
    # temp = common.canny_(temp)
    # temp = common.Remove_holes(temp)
    cv2.imshow("temp", temp)

    img = common.template(img, temp, threshold=1)
    cv2.imshow("match", img)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
Beispiel #3
0
def get_data(path="./data/true_image/", image_height=32, equalize=1):
    files = os.listdir(path)
    for file in files:
        file_path = os.path.join(path, file)
        origin = cv2.imread(file_path)

        img = common.bgr2gray_(origin)
        h, w = img.shape[:2]

        img = cv2.resize(img, (int(w / h * image_height), image_height),
                         interpolation=cv2.INTER_AREA)
        if equalize == 1:
            img = cv2.equalizeHist(img)

        data = img[np.newaxis, :, :, np.newaxis]
        label = list(
            map(int,
                file.replace(" ", "").split('.')[0].split('_')[0]))

        # cv2.imshow("img", img)
        # cv2.waitKey()
        yield np.array(data), np.array(label), origin, file_path
Beispiel #4
0
        plt.subplot(1, 2, 1)
        plt.imshow(img)
        ax = plt.gca()  # 获取到当前坐标轴信息
        ax.xaxis.set_ticks_position('top')  # 将X坐标轴移到上面

        plt.subplot(1, 2, 2)
        plt.imshow(cut)
        ax = plt.gca()  # 获取到当前坐标轴信息
        ax.xaxis.set_ticks_position('top')  # 将X坐标轴移到上面
        plt.show()

    #     ret, cut = cv2.threshold(cut, 100, 255, cv2.THRESH_BINARY)

    return img, cut


if __name__ == '__main__':
    # 0黑色,255白色
    # 11,12,13
    file_name = "../data/img/2.jpg"
    img = cv2.imread(file_name)
    img = common.bgr2gray_(img)
    img = common.binary_(img)

    img, cut = rotate_(img, (1430, 895), (280, 30),
                       30,
                       draw=False,
                       display=True)

    print(cut)