Пример #1
0
 def init_by_checkdir(self, checkdir_path, ext='.bmp'):
     self.upg    = cv_imread(os.path.join(checkdir_path, 'UpG' + ext))
     self.upir   = cv_imread(os.path.join(checkdir_path, 'Upir' + ext))
     self.upirtr = cv_imread(os.path.join(checkdir_path, 'Upirtr' + ext))
     self.upuv   = cv_imread(os.path.join(checkdir_path, 'Upuv' + ext))
     self.upuvtr = cv_imread(os.path.join(checkdir_path, 'Upuvtr' + ext))
     self.dwg    = cv_imread(os.path.join(checkdir_path, 'DwG' + ext))
     self.dwir   = cv_imread(os.path.join(checkdir_path, 'Dwir' + ext))
     self.dwirtr = cv_imread(os.path.join(checkdir_path, 'Dwirtr' + ext))
     self.dwuv   = cv_imread(os.path.join(checkdir_path, 'Dwuv' + ext))
     self.dwuvtr = cv_imread(os.path.join(checkdir_path, 'Dwuvtr' + ext))
Пример #2
0
def tongji_width():
    # 1 实验得出纤维丝的宽度长度
    # 2 二值化得到纤维丝的有效区域
    # 3 寻找轮廓
    # 4 寻找轮廓的最大内切圆


    imdir = r'E:\DataSet\fiber\f_blue'
    imdir = r'E:\DataSet\fiber\fiber_img_1'

    imnamelist = os.listdir(imdir)

    imnames = [os.path.join(imdir, f) for f in imnamelist]
    # imnames = imnames[:500]

    rs = []

    for impath in imnames:
        im = cv_imread(impath)
        center, radiesOrNum = fiber_enclosing_circle(im, False)
        if center is None:
            # print('{0} find {1} contours'.format(impath, radiesOrNum))
            continue

        if radiesOrNum > 4.5:
            print(impath, ' R>4.5, feel exption')
        rs.append(radiesOrNum * 2)

    xs = [i for i in range(len(rs))]
    plt.plot(xs, rs, "ob")
    plt.axis([0, 800, 0, 5])
    plt.show()
Пример #3
0
def tongji_length():
    # 1 实验得出纤维丝的宽度长度
    # 2 二值化得到纤维丝的有效区域
    # 3 寻找轮廓
    # 4 寻找轮廓的最大内切圆, 轮廓长度

    imdir = r'E:\DataSet\fiber\f_blue'
    imdir = r'E:\DataSet\fiber\fiber_img_1'

    imnamelist = os.listdir(imdir)

    imnames = [os.path.join(imdir, f) for f in imnamelist]
    # imnames = imnames[:500]

    rs = []

    for impath in imnames:
        im = cv_imread(impath)
        length = fiber_length(im, False)
        if length == 0:
            # print('{0} find {1} contours'.format(impath, radiesOrNum))
            continue

        if length // 2 > 80:
            print('[WARNING] {0} find {1} length contours'.format(
                impath, length // 2))

        rs.append(length / 2)

    xs = [i for i in range(len(rs))]
    plt.plot(xs, rs, "ob")
    plt.axis([0, 800, 0, 100])
    plt.show()
Пример #4
0
def bloom2_debug():
    # 变造红水线数据
    # check_dir = r'E:\DataSet\redline\UpG_redline'
    # debug_dir = r'E:\DataSet\redline\debug_dark_line_midu'

    # 正常红水线数据
    check_dir = r'E:\DataSet\redline_ok\redline_normal'
    debug_dir = r'E:\DataSet\redline_ok\debug_dark_line_midu_2'

    filename_list = os.listdir(check_dir)
    for imgname in filename_list:

        print('process:', imgname)

        imagePath = os.path.join(check_dir, imgname)
        img = cv_imread(imagePath)

        iimg = img.copy()

        res_tuan = detect_bloom2(iimg)
        res_darkline = detect_darkline(iimg)

        # res = cv2.cvtColor(res, cv2.COLOR_GRAY2BGR)
        cv2.imwrite(os.path.join(debug_dir, imgname),
                    np.vstack((res_tuan, res_darkline)))
Пример #5
0
def bloom_debug():
    # 变造红水线
    # check_dir = r'E:\DataSet\redline\UpG_redline'
    # debug_dir = r'E:\DataSet\redline\debug_bloom_th5'

    # 正常红水线
    check_dir = r'E:\DataSet\redline_ok\redline_normal'
    debug_dir = r'E:\DataSet\redline_ok\debug_1'

    filename_list = os.listdir(check_dir)
    for imgname in filename_list:

        print('process:', imgname)

        imagePath = os.path.join(check_dir, imgname)
        img = cv_imread(imagePath)

        mask, res = separate_color(img, color='red')
        pair = detect_bloom(res)

        h, w = img.shape[:2]
        for x1, x2 in pair:
            if x2 - x1 > 10:
                cv2.rectangle(img, (x1, 2), (x2, h - 2), (0, 0, 255), 1)  # red
            else:
                cv2.rectangle(img, (x1, 2), (x2, h - 2), (255, 0, 0), 1)  # 窄

        cv2.imwrite(os.path.join(debug_dir, imgname), img)
Пример #6
0
def fiber_hsv_hist():
    impath = r'E:\DataSet\fiber\fiber_img_1\00354.jpg'

    imdir = r'E:\DataSet\fiber\f_red'  # 保存明显blue的img文件夹
    imnamelist = os.listdir(imdir)
    imnames = [os.path.join(imdir, f) for f in imnamelist]

    print('image num : ', len(imnames))

    HC = []
    SC = []
    VC = []

    for impath in imnames:

        im = cv_imread(impath)
        hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)

        gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        H, W = gray.shape

        # _, gray = cv2.threshold(gray, thre, 255, cv2.THRESH_BINARY)
        _, gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)

        _, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

        if len(contours) != 1:
            # print("find {0} > 1 contours".format(len(contours)))
            print("{0} find {1} > 1 contours".format(impath, len(contours)))
            continue
        else:
            # print("{0} find {1} == 1 contours".format(impath, len(contours)))
            pass

        # roi = np.zeros((H, W), dtype=np.int8)
        # cv2.drawContours(roi, contours, -1, 255, -1, lineType=cv2.LINE_AA)
        # cv2.imshow('roi', roi)
        # cv2.waitKey(0)

        for i in range(0, H):
            for j in range(0, W):
                is_in = cv2.pointPolygonTest(contours[0], (i, j), False)

                if is_in > 0.8:
                    HC.append(hsv[i][j][0])
                    SC.append(hsv[i][j][1])
                    VC.append(hsv[i][j][2])


    plt.hist(HC, 180)
    plt.show()
    plt.hist(SC, 256)
    plt.show()
    plt.hist(VC, 256)
    plt.show()
Пример #7
0
def hsv_trackbar():
    '''

    # red fiber
    # 粗略统计 [110, 80, 40] [150, 160, 140]
    # 精细统计 [146, 80, 75] [154, 120, 120] 背景好多也来了
    # hsvbar 【130/135/140,60,65】【160, 150/160,140】
    # 130 用于浅色红暗红,135用于亮红

    :return:
    '''

    imagePath = r'E:\DataSet\fiber\f_blue_light\00505.jpg'  # 浅蓝

    # red : [00038, 00039, 00278]

    # imagePath = r'E:\DataSet\fiber\f_red\00782.jpg'  # red

    img = cv_imread(imagePath)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    cv2.namedWindow('image', cv2.WINDOW_KEEPRATIO)

    # 创建RGB三个滑动条
    cv2.createTrackbar('H1', 'image', 100, 180, nothing)
    cv2.createTrackbar('H2', 'image', 150, 180, nothing)

    cv2.createTrackbar('S1', 'image', 70, 255, nothing)
    cv2.createTrackbar('S2', 'image', 190, 255, nothing)

    cv2.createTrackbar('V1', 'image', 110, 255, nothing)
    cv2.createTrackbar('V2', 'image', 255, 255, nothing)

    res = img.copy()
    while True:

        cv2.imshow('image', np.vstack((img, res)))
        if cv2.waitKey(1) == 27:
            break

        # 获取滑块的值
        # val = cv2.getTrackbarPos('R', 'image')
        H1 = cv2.getTrackbarPos('H1', 'image')
        H2 = cv2.getTrackbarPos('H2', 'image')
        S1 = cv2.getTrackbarPos('S1', 'image')
        S2 = cv2.getTrackbarPos('S2', 'image')
        V1 = cv2.getTrackbarPos('V1', 'image')
        V2 = cv2.getTrackbarPos('V2', 'image')

        lower_hsv = np.array([H1, S1, V1])  # 提取颜色的低值
        high_hsv = np.array([H2, S2, V2])  # 提取颜色的高值
        mask = cv2.inRange(hsv, lowerb=lower_hsv, upperb=high_hsv)

        res = cv2.bitwise_and(img, img, mask=mask)
Пример #8
0
def bloom_test():
    """
    十月份测试集郭南票中的红水线测试。
    :return:
    """
    red_dir = r'E:\异常图0927\红水线晕染'
    names = os.listdir(red_dir)
    imgpaths = [os.path.join(red_dir, na) for na in names]

    for imgpath in imgpaths:
        img = cv_imread(imgpath)
        detect_bloom2(img, debug=True)
Пример #9
0
def bloom_demo():
    imagePath = r'E:\DataSet\redline\UpG_redline\UpG_161615.jpg'
    img = cv_imread(imagePath)

    pair = detect_bloom(img)

    h, w = img.shape[:2]
    for x1, x2 in pair:
        cv2.rectangle(img, (x1, 2), (x2, h - 2), (0, 0, 255), 1)

    cv2.imshow('result', img)
    cv2.waitKey(0)
Пример #10
0
def hsv_trackbar():
    # 1 正常晕染
    # imagePath = r'E:\DataSet\redline\UpG_redline\UpG_161831.jpg'
    # 2 粗线晕染
    # imagePath = r'E:\DataSet\redline\UpG_redline\UpG_161817.jpg'
    # 3 正常1
    imagePath = r'E:\DataSet\redline_ok\redline_normal\UpG_092349.jpg'
    # 3 正常2
    # imagePath = r'E:\DataSet\redline_ok\redline_normal\UpG_092610.jpg'

    # 团花H(0,90) S(0,200) V(140,255)
    imagePath = r'../hanghui/img_tuanhua/tuanhua_uv_1.jpg'
    imagePath = r'../tuanhua/img/upuv_gratch_2.jpg'

    img = cv_imread(imagePath)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    cv2.namedWindow('image', cv2.WINDOW_KEEPRATIO)

    # 创建RGB三个滑动条
    cv2.createTrackbar('H1', 'image', 0, 180, nothing)
    cv2.createTrackbar('H2', 'image', 90, 180, nothing)

    cv2.createTrackbar('S1', 'image', 0, 255, nothing)
    cv2.createTrackbar('S2', 'image', 200, 255, nothing)

    cv2.createTrackbar('V1', 'image', 140, 255, nothing)
    cv2.createTrackbar('V2', 'image', 255, 255, nothing)

    res = img.copy()
    while True:

        cv2.imshow('image', np.vstack((img, res)))
        if cv2.waitKey(1) == 27:
            break

        # 获取滑块的值
        # val = cv2.getTrackbarPos('R', 'image')
        H1 = cv2.getTrackbarPos('H1', 'image')
        H2 = cv2.getTrackbarPos('H2', 'image')
        S1 = cv2.getTrackbarPos('S1', 'image')
        S2 = cv2.getTrackbarPos('S2', 'image')
        V1 = cv2.getTrackbarPos('V1', 'image')
        V2 = cv2.getTrackbarPos('V2', 'image')

        lower_hsv = np.array([H1, S1, V1])  # 提取颜色的低值
        high_hsv = np.array([H2, S2, V2])  # 提取颜色的高值
        mask = cv2.inRange(hsv, lowerb=lower_hsv, upperb=high_hsv)

        res = cv2.bitwise_and(img, img, mask=mask)
Пример #11
0
def hsv_trackbar():

    # 团花H(0,90) S(0,200) V(140,255)
    # imagePath = r'../hanghui/img_tuanhua/tuanhua_uv_1.jpg'
    # imagePath = r'../tuanhua/img/upuv_qian_1.jpg'

    # imagePath = r'../tuanhua/img/upuv_v128.jpg'
    # imagePath = r'../tuanhua/img/upuv_qian_2.jpg'

    # imagePath = r'../tuanhua/img/all_tuanhua_2.jpg'

    imagePath = r'../tuanhua/img/th_y_l.jpg'

    img = cv_imread(imagePath)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    cv2.namedWindow('image', cv2.WINDOW_KEEPRATIO)

    # 创建RGB三个滑动条
    cv2.createTrackbar('H1', 'image', 0, 180, nothing)
    cv2.createTrackbar('H2', 'image', 100, 180, nothing)

    cv2.createTrackbar('S1', 'image', 0, 255, nothing)
    cv2.createTrackbar('S2', 'image', 255, 255, nothing)

    cv2.createTrackbar('V1', 'image', 120, 255, nothing)
    cv2.createTrackbar('V2', 'image', 255, 255, nothing)

    res = img.copy()
    while True:

        cv2.imshow('image', np.vstack((img, res)))
        if cv2.waitKey(1) == 27:
            break

        # 获取滑块的值
        # val = cv2.getTrackbarPos('R', 'image')
        H1 = cv2.getTrackbarPos('H1', 'image')
        H2 = cv2.getTrackbarPos('H2', 'image')
        S1 = cv2.getTrackbarPos('S1', 'image')
        S2 = cv2.getTrackbarPos('S2', 'image')
        V1 = cv2.getTrackbarPos('V1', 'image')
        V2 = cv2.getTrackbarPos('V2', 'image')

        lower_hsv = np.array([H1, S1, V1])  # 提取颜色的低值
        high_hsv = np.array([H2, S2, V2])  # 提取颜色的高值
        mask = cv2.inRange(hsv, lowerb=lower_hsv, upperb=high_hsv)

        res = cv2.bitwise_and(img, img, mask=mask)
Пример #12
0
def split_redline(upg_img_path, dst_dir, method=cv2.TM_CCOEFF_NORMED):

    target = cv_imread(upg_img_path)
    cropx_offset = 0

    ori_h, ori_w = target.shape[:2]
    if ori_w > check_scale[0]:
        cropx_offset = ori_w - check_scale[0]
        target = target[:, cropx_offset:]  # 裁剪坐标为[y0:y1, x0:x1]

    print(target.shape)

    # 1 取人名币大写的模板,用于定位红水线
    temp = cv2.imread(r'../img/money_chinese.jpg')
    t_height, t_width = temp.shape[:2]
    print(temp.shape[:2])

    # 2 划可能的区域
    # (1330, 630) [xmin,ymin,xmax,ymax]
    left_up = [60, 100, 400, 320]  # 左上区域
    possible_area = left_up
    xmin, ymin, xmax, ymax = possible_area
    target_crop = target[ymin:ymax, xmin:xmax]

    result = cv2.matchTemplate(target_crop, temp, method)

    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
    if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
        t_left = min_loc
    else:
        t_left = max_loc  # (x,y) 访问 result[y][x], row col

    # 3 将坐标映射回原图
    tl = (t_left[0] + xmin, t_left[1] + ymin)
    br = (tl[0] + t_width, tl[1] + t_height)

    top_right = (br[0], tl[1])

    xmin, ymin = redline_tl = (top_right[0] + 4, top_right[1] - 6)
    xmax, ymax = redline_br = (redline_tl[0] + 666, redline_tl[1] + 66)

    redline_img = target[ymin:ymax, xmin:xmax]
    filename = upg_img_path.split('\\')[-1]
    filename = filename.split('.')[0]
    cv2.imwrite(
        os.path.join(dst_dir, filename) + '.jpg', redline_img,
        [int(cv2.IMWRITE_JPEG_QUALITY), 95])
Пример #13
0
def split(check_dir, des_dir, prefix, copy=True):
    # check_dir : 100张支票图片\092339\UpG.jpg
    # des_dir : 复制的目标目录
    # prefix : 分离的前缀名list,例如: ['UpG' ,'Upir']
    # 注意后缀可能变化
    all_dir = os.listdir(check_dir)
    for one_dir in all_dir:
        dir_path = os.path.join(check_dir, one_dir)
        if os.path.isdir(dir_path):  # 保存图像的支票目录,每个目录保存一张支票的10个图像
            all_files = os.listdir(dir_path)

            for file in all_files:
                sp = file.split('.')

                if len(sp) > 1 and (sp[1] in ['bmp', 'jpg']) and (sp[0]
                                                                  in prefix):
                    # shutil.copy(os.path.join(dir_path, file), os.path.join(des_dir, file.split('.')[0]))

                    if copy == True:
                        new_filename = os.path.join(
                            des_dir,
                            sp[0]) + '\\' + sp[0] + '_' + one_dir + '.' + sp[1]

                        print('move ' + file + ' to ' +
                              os.path.join(des_dir, sp[0]))

                        shutil.copyfile(os.path.join(dir_path, file),
                                        new_filename)
                    else:
                        new_filename = os.path.join(
                            des_dir,
                            sp[0]) + '\\' + sp[0] + '_' + one_dir + '.jpg'

                        im = cv_imread(os.path.join(dir_path, file))
                        # cv2.imshow('upuv',im)
                        # cv2.waitKey(0)
                        print('save ', os.path.join(dir_path, file),
                              ' img to jpg:', new_filename)
                        cv2.imwrite(new_filename, im,
                                    [int(cv2.IMWRITE_JPEG_QUALITY), 95])

                else:
                    print(file + ' is disgard')
Пример #14
0
    def __init__(self, check_dir):
        self.debug = False

        self.th_w = 374
        self.th_h = 145
        self.off_x_by_right = 25
        self.off_y_by_top = 10

        TEMP_DIR = check_dir

        upuv = TEMP_DIR + '/' + 'Upuv.bmp'
        upg = TEMP_DIR + '/' + 'UpG.bmp'
        upir = TEMP_DIR + '/' + 'Upir.bmp'
        upirtr = TEMP_DIR + '/' + 'Upirtr.bmp'

        upuv_img = cv_imread(upuv)
        upg_img = cv_imread(upg)
        upir_img = cv_imread(upir)
        upirtr_img = cv_imread(upirtr)

        self.th_template = TuanHuaROI(upg_img,upir_img, upirtr_img, upuv_img)

        self.im = self.th_template.upuv_box.copy()

        # template region  团花左侧区域 中心74
        self.tr_1 = TmpRegionInfo(5, 58 - 20, 30 + 30, 90 + 20, self.im)

        # 团花右侧区域
        # self.tr_1 = TmpRegionInfo(325, 74-50, 325+50, 74+50, self.im)

        # 团花上部区域 y[6, 30]超过三十可能带有文字区域了 中心x187
        # self.tr_1 = TmpRegionInfo(187 - 50, 6, 187 + 50, 30, self.im)

        cv2.imshow('tmp_1', self.tr_1.tmp_img)


        # 1)颜色提取
        self.hsv_mask, self.hsv = separate_color(self.im, color='tuanhua_green')
        # 2)二值化
        # _, self.hsv_mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)



        # hsv -> gray -> denoise -> bin,转化为灰度图,然后降噪,在转变为二值图去做最后的匹配
        # 这一步去除一些极小的噪点
        hsv_gray = cv2.cvtColor(self.hsv, cv2.COLOR_BGR2GRAY)
        hsv_gray_denoise = cv2.fastNlMeansDenoising(hsv_gray, h=5.0)
        th, hsv_gray = cv2.threshold(hsv_gray_denoise, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)

        # 固定阈值效果不好
        # _, hsv_gray = cv2.threshold(hsv_gray_denoise, 150, 255, cv2.THRESH_BINARY)
        # 局部二值化 效果不好
        # hsv_gray = cv2.adaptiveThreshold(hsv_gray_denoise, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, C= 0)

        # print("去噪后OSTU二值化的阈值:", th)

        self.hsv_mask = hsv_gray.copy()


        gray = cv2.cvtColor(self.im, cv2.COLOR_BGR2GRAY)
        # _, gray = cv2.threshold(gray, thre, 255, cv2.THRESH_BINARY)
        _, gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        # 只寻找最外轮廓 RETR_EXTERNAL RETR_CCOMP
        _, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
        H, W = gray.shape

        self.roi_mask = np.zeros((H, W), dtype=np.uint8)

        # 绘制ROI mask
        # cv2.drawContours(im, contours, -1, (0, 0, 255), 2, lineType=cv2.LINE_AA)
        count = 0
        for cnt in contours:
            if cv2.contourArea(cnt) > H * W // 2:
                count += 1
                cv2.drawContours(self.roi_mask, [cnt], 0, 255, -1, lineType=cv2.LINE_AA)

        # assert count == 1, 'Non-standard group flower image template'

        # 以右上角为原点,左x,下y,这个区域是文字区域
        self.ignore_x_range = (110, 310)
        self.ignore_y_range = (80, 160)

        # 以团花为参考系,文字区域和收款行区域
        # self.num_box = [90, 70, 290, 120]  # xmin 90 100
        self.num_box = [80, 70, 290, 120]
        self.recvbank_box = (0, 90)  # (xmin, ymin) ymin 90 100

        self.blank_thresh = 1
        self.white_thresh = 3
Пример #15
0
def gary_trackbar():
    # 1 正常晕染 UpG_161405 UpG_161410 UpG_161734
    # imagePath = r'E:\DataSet\redline\UpG_redline\UpG_161903.jpg'
    # 2 粗线晕染
    # imagePath = r'E:\DataSet\redline\UpG_redline\UpG_161817.jpg'
    # 3 正常1
    # imagePath = r'E:\DataSet\redline_ok\redline_normal\UpG_092349.jpg'
    # 3 正常2
    imagePath = r'E:\DataSet\redline_ok\redline_normal\UpG_092629.jpg'

    img = cv_imread(imagePath)
    mask_red, redhsv = separate_color(img, color='red')
    # cv2.imshow('ori', img)
    # cv2.imshow('tiqutu', redhsv)

    h, w, _ = img.shape
    for i in range(0, h):
        for j in range(0, w):
            a, b, c = redhsv[i][j]
            if a == 0 and b == 0 and c == 0:
                redhsv[i][j] = [255, 255, 255]

    cv2.imshow('bai', redhsv)

    res_ori = cv2.cvtColor(redhsv, cv2.COLOR_BGR2GRAY)
    print(res_ori.shape)
    vals = []
    for i in range(0, h):
        for j in range(0, w):
            if res_ori[i][j] != 255:
                vals.append(res_ori[i][j])
    vals = np.array(vals)

    # plt.hist(vals,255)
    # plt.show()

    line_gray_mean = np.mean(vals)
    print('红水线灰度化均值:', line_gray_mean)

    cv2.namedWindow('image', cv2.WINDOW_KEEPRATIO)
    cv2.createTrackbar('G', 'image', 88, 255, nothing)
    cv2.createTrackbar('TH', 'image', 10, 40, nothing)

    while True:
        if cv2.waitKey(1) == 27:
            break

        G = cv2.getTrackbarPos('G', 'image')
        TH = cv2.getTrackbarPos('TH', 'image')

        _, res = cv2.threshold(res_ori, G, 255, cv2.THRESH_BINARY)

        ser = cv2.bitwise_not(res)

        # 以(30,2)长度的滑动窗口,滑动,如果有校像素超过3/4 28? ,认为是深色红水线
        # 中值滤波呢,不太行
        # midblur = cv2.medianBlur(ser, 3)

        valid = []
        blank = np.zeros((h, w), dtype=np.uint8)  # 黑板

        kh = 2
        kw = 20
        for i in range(0, h - kh):
            for j in range(0, w - kw):
                temp = ser[i:i + kh, j:j + kw]
                white = np.sum(temp == 255)
                if white >= TH:
                    blank[i:i + kh, j:j + kw] = 255

        cv2.imshow('moban', blank)
        cv2.imshow('image', np.vstack((res_ori, ser)))
Пример #16
0

    names = os.listdir(tuanhuayc)
    # names = [n for n in names if '团花' in n]  # 116对不齐

    # tuanhuayc = r'E:\异常图0927\敦南\敦南正常'
    # names = ['20200828_15-06-02 太淡']

    # print(names)

    for na in names:
        print('===============processing ', na, '=======================')
        imgdir = os.path.join(tuanhuayc, na)
        upuv = imgdir + '/' + 'Upuv.bmp'

        upuv_img = cv_imread(upuv)
        h, w, c = upuv_img.shape

        xmin = w - TH_W - TH_XOFF_RIGHT
        ymin = TH_YOFF_TOP
        xmax = xmin + TH_W
        ymax = ymin + TH_H

        upg = imgdir + '/' + 'UpG.bmp'
        upir = imgdir +'/' + 'Upir.bmp'
        upirtr = imgdir + '/' + 'Upirtr.bmp'



        upg_img = cv_imread(upg)
        upir_img = cv_imread(upir)
Пример #17
0
def gratch_demo():
    imagePath = r'E:\DataSet\redline\UpG_redline\UpG_161328.jpg'
    img = cv_imread(imagePath)

    detect_scratch(img, debug=True)
Пример #18
0
    return RECTS_2 + RES_3  # (xmin, ymin, xmax, ymax)


def bloom_test():
    """
    十月份测试集郭南票中的红水线测试。
    :return:
    """
    red_dir = r'E:\异常图0927\红水线晕染'
    names = os.listdir(red_dir)
    imgpaths = [os.path.join(red_dir, na) for na in names]

    for imgpath in imgpaths:
        img = cv_imread(imgpath)
        detect_bloom2(img, debug=True)


if __name__ == '__main__':

    imagePath = r'E:\异常图0927\红水线晕染\88.jpg'
    img = cv_imread(imagePath)

    # 1.检测晕染,以及刮擦产生的晕染,ok的
    pairs = detect_bloom2(img, debug=True)

    # bloom_test()

    cv2.imshow('imread', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
Пример #19
0
    # bank_measure.add_template_of_upuv(nonghang_3)
    # bank_measure.add_template_of_upuv(nonghang_4)

    # test_check_dir = r'E:\异常图0927\敦南\敦南异常'
    test_check_dir = r'E:\异常图0927\敦南\敦南正常'
    # test_check_dir = r'E:\异常图0927\华菱\正常票'
    # test_check_dir = r'E:\异常图0927\华菱\异常票'

    check_ids = os.listdir(test_check_dir)
    # check_ids = [id for id in check_ids if '行徽' in id]
    check_ids = [id for id in check_ids if '14-45-18' in id]

    bank_measure.debug = True

    for na in check_ids:
        print('===========', na, '=================================')
        imgdir = os.path.join(test_check_dir, na)
        upuv = imgdir + '/' + 'Upuv.bmp'
        upg = imgdir + '/' + 'UpG.bmp'
        upir = imgdir + '/' + 'Upir.bmp'
        upirtr = imgdir + '/' + 'Upirtr.bmp'

        upuv_img = cv_imread(upuv)

        na = na.split('.')[0]  # 变造图像文件夹名字有中文

        bank_measure.set_cur_filename(na)
        score = bank_measure.measure(upuv_img)
        if score < 0.5:
            print(na, '得分:', score)
            print('---reason--->', bank_measure.reasons)
Пример #20
0
 def add_template_of_upuv(self, upuv_icon_path):
     img = cv_imread(upuv_icon_path)
     assert img is not None
     self.template_list_upuv.append(BankUpuv(img))
Пример #21
0
    if debug:
        cv2.imshow('way3 second', img)

    # 检测到的晕染坐标
    corrs = detect_bloom2(image, debug=True)

    for xmin,ymin,xmax,ymax in corrs:
        img[ymin:ymax, xmin:xmax] = 255

    damage = confidence_percentage(first, img)

    return damage

def debug():
    check_dir = r'E:\DataSet\redline\UpG_redline'
    debug_dir = r'E:\DataSet\redline\debug'

    filename_list = os.listdir(check_dir)
    for imgname in filename_list:
        img_path = os.path.join(check_dir, imgname)
        debug = way_3(img_path)
        cv2.imwrite(os.path.join(debug_dir, imgname), debug)

if __name__ == '__main__':


    img_path = r'E:\DataSet\redline\UpG_redline\UpG_161436.jpg'
    img = cv_imread(img_path)
    way_3(img,debug=True)
    cv2.waitKey(0)
    cv2.destroyAllWindows()