示例#1
0
                cnt += 1

                A_file_name = os.path.join(config.base_dir,
                                           config.TRAIN.A_data_dir, cur_dir,
                                           train_file_list[ind] + '.jpg')
                B_file_name = os.path.join(config.base_dir,
                                           config.TRAIN.A_data_dir, cur_dir,
                                           true_crop + '.jpg')

                # last parameter in file_name, normalized to [0,1]
                overlap = float(train_file_list[ind].split("_")[-1]) / 100

                if not os.path.isfile(A_file_name) or not os.path.isfile(
                        B_file_name):
                    continue
                A_image = helper.read_image(A_file_name)  # training image A
                B_image = helper.read_image(B_file_name)  # training image B

                feed_dict = {
                    input_A: A_image,
                    input_B: B_image,
                    overlap_input: overlap,
                    lr: 1e-8
                }

                # session run
                eval = fetcher.fetch(feed_dict, [G_loss])
                # evalCX = fetcher.fetch(feed_dict, [CX_content_loss])
                if cnt % 100 == 0:
                    g_loss[ind] = eval[G_loss]
                    # cx_loss[ind] = evalCX[CX_content_loss]
示例#2
0

# ---------------------------------------------------
#                      train
# ---------------------------------------------------
if config.TRAIN.is_train:
    file_list = os.listdir(os.path.join(config.base_dir,config.TRAIN.A_data_dir))
    val_file_list = os.listdir(os.path.join(config.base_dir,config.VAL.A_data_dir))
    file_list = np.random.permutation(file_list)
    assert len(file_list) > 0
    train_file_list = file_list[0::config.TRAIN.every_nth_frame]
    val_file_list = val_file_list[0::config.VAL.every_nth_frame]
    g_loss = np.zeros(len(train_file_list), dtype=float)
    fetcher = FetchManager(sess, [G_opt, G_loss])
    B_file_name = config.single_image_B_file_name
    B_image = helper.read_image(B_file_name)  # training image B

    ## ------------ epoch loop -------------------------
    for epoch in range(1, config.TRAIN.num_epochs + 1):
        epoch_dir = config.TRAIN.out_dir + "/%04d" % epoch
        if os.path.isdir(epoch_dir):
            continue
        cnt = 0

        ## ------------ batch loop -------------------------
        for ind in np.random.permutation(len(train_file_list)):#
            st = time.time()
            cnt += 1

            A_file_name = config.base_dir + config.TRAIN.A_data_dir + '/' + train_file_list[ind]
            if not os.path.isfile(A_file_name) or not os.path.isfile(A_file_name):
示例#3
0

def _prewitt(self):
    return ([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]],
            [[-1, -1, -1], [0, 0, 0], [1, 1, 1]])


def bounding_box(img, range_w=None, range_h=None):
    img = histogram_equalization.adaptive_mean(img)
    cv2.imshow('binary', img)

    contours, hierarchy = cv2.findContours(img, cv2.RETR_LIST, cv2.CHAIN_APPROX_TC89_KCOS)
    boundings = []
    for cnt in contours:
        x, y, w, h = cv2.boundingRect(cnt)
        if (not range_w or (w >= range_w[0] and w <= range_w[1])) and \
                (not range_h or (h >= range_h[0] and h <= range_h[1])):
            boundings.append((x, y, w, h))
            cv2.rectangle(img, (x, y), (x + w, y + h), (255), 2)

    return img, boundings


if __name__ == '__main__':
    pix = helper.read_image('../resources/fp01.jpg')
    pix = helper.convert_gray(pix)
    helper.save_image('../resources/gray.png', True)
    pix = basic(pix)
    # noise_removal = NoiseRemoval()
    # pix = noise_removal.opening(pix)
    helper.save_image(pix, '../resources/edge.png')