Пример #1
0
def saveParameters(fileDir):
    # Model name 1 mean dataset`s folder 1.
    model_name = '1'
    detection_model = objectDetector.load_model(model_name)
    # File is directory
    files = utility.get_filenames(fileDir)
    fileNames = []
    domColors = []
    wallColors = []
    floorColors = []

    for f in files:
        if "." not in f:
            continue
        print("Now proceeding ", f, " [ ", files.index(f), " ]")

        coord, str_tag, number_tag, score = objectDetector.inference(
            detection_model, f)

        # Save file name make.
        save_file_name = utility.add_name(f, "_od", extension="bin")
        dirs = save_file_name.split("/")

        save_image_name = ""
        for d in dirs[0:-1]:
            save_image_name += d + "/"
        save_image_name += f.split("/")[-1].split(".")[0] + "/"

        utility.make_dir(save_image_name)

        rect_files = []
        additional_infor = []

        for i in range(len(str_tag)):
            additional_infor.append(-1)
            rect_image = image_processing.get_rect_image(
                f, int(coord[i][0]), int(coord[i][1]), int(coord[i][2]),
                int(coord[i][3]))
            rect_image_name = save_image_name + f.split("/")[-1]
            rect_image_name = utility.add_name(rect_image_name, "_" + str(i))
            rect_files.append(rect_image_name)
            utility.save_image(rect_image, rect_image_name)

        dom_color = image_processing.get_dominant_color(f)
        n_color = utility.get_remarkable_color_n(dom_color, MAX_COLOR_LENGTH)
        fileNames.append(os.path.basename(f))
        domColors.append(n_color)
        wallColors.append([])
        floorColors.append([])
        utility.save_result([
            coord, str_tag, number_tag, score, rect_files, additional_infor,
            n_color
        ], save_file_name)

    utility.save_result([files, domColors, wallColors, floorColors],
                        config.RESEARCH_BASE_FILE)
Пример #2
0
def select_user_roi(image_path):
    '''
    由于原图的分辨率较大,这里缩小后获取ROI,返回时需要重新scale对应原图
    :param image_path:
    :return:
    '''
    orig_image = image_processing.read_image(image_path)
    orig_shape = np.shape(orig_image)
    resize_image = image_processing.resize_image(orig_image,
                                                 resize_height=800,
                                                 resize_width=None)
    re_shape = np.shape(resize_image)
    g_rect = get_image_roi(resize_image)
    orgi_rect = image_processing.scale_rect(g_rect, re_shape, orig_shape)
    roi_image = image_processing.get_rect_image(orig_image, orgi_rect)
    image_processing.cv_show_image("RECT", roi_image)
    image_processing.show_image_rect("image", orig_image, orgi_rect)
    return orgi_rect
Пример #3
0
def saveParameter(fileName, detection_model):
    coord, str_tag, number_tag, score = objectDetector.inference(
        detection_model, fileName)

    # Save file name make.
    save_file_name = config.RESEARCH_BASE_DIR + "/" + os.path.basename(
        utility.get_od_bin(fileName))
    dirs = save_file_name.split("/")

    save_image_name = ""
    for d in dirs[0:-1]:
        save_image_name += d + "/"
    save_image_name += fileName.split("/")[-1].split(".")[0] + "/"

    utility.make_dir(save_image_name)

    rect_files = []
    additional_infor = []

    for i in range(len(str_tag)):
        additional_infor.append(-1)
        rect_image = image_processing.get_rect_image(fileName,
                                                     int(coord[i][0]),
                                                     int(coord[i][1]),
                                                     int(coord[i][2]),
                                                     int(coord[i][3]))
        rect_image_name = save_image_name + fileName.split("/")[-1]
        rect_image_name = utility.add_name(rect_image_name, "_" + str(i))
        rect_files.append(rect_image_name)
        utility.save_image(rect_image, rect_image_name)

    dom_color = image_processing.get_dominant_color(fileName)
    n_color = utility.get_remarkable_color_n(dom_color, MAX_COLOR_LENGTH)
    utility.save_result([
        coord, str_tag, number_tag, score, rect_files, additional_infor,
        n_color
    ], save_file_name)
    return [
        coord, str_tag, number_tag, score, rect_files, additional_infor,
        n_color
    ]
Пример #4
0
def objectDetect(inputFile, outputFile):
    '''
	입력받은 inputFile의 가구를 ObjectDetection한 결과를 outputFile에 저장한다. json 형태로 저장한다.
	현재는 bin file로만 입출력이 가능.
	폴더를 입력하면 outputFile은 무시됨.
	'''
    if "." not in inputFile:
        # File is directory
        files = utility.get_filenames(inputFile)
        for f in files:
            if "." not in f:
                continue

            coord, str_tag, number_tag, score = objectDetector.inference(
                detection_model, f)
            # Save file name make.
            save_file_name = utility.add_name(f, "_od", extension="bin")
            dirs = save_file_name.split("/")
            save_image_name = ""
            for d in dirs[0:-1]:
                save_image_name += d + "/"
            save_image_name += f.split("/")[-1].split(".")[0] + "/"
            utility.make_dir(save_image_name)
            rect_files = []

            additional_infor = []
            for i in range(len(str_tag)):
                additional_infor.append(-1)
                rect_image = image_processing.get_rect_image(
                    f, int(coord[i][0]), int(coord[i][1]), int(coord[i][2]),
                    int(coord[i][3]))
                rect_image_name = save_image_name + f.split("/")[-1]
                rect_image_name = utility.add_name(rect_image_name,
                                                   "_" + str(i))
                rect_files.append(rect_image_name)
                utility.save_image(rect_image, rect_image_name)
            utility.save_result([
                coord, str_tag, number_tag, score, rect_files, additional_infor
            ], save_file_name)

    else:
        coord, str_tag, number_tag, score = objectDetector.inference(
            detection_model, inputFile)
        # Save file name make.
        save_file_name = utility.add_name(inputFile, "_od", extension="bin")
        dirs = save_file_name.split("/")
        save_image_name = ""
        for d in dirs[0:-1]:
            save_image_name += d + "/"
        save_image_name += inputFile.split("/")[-1].split(".")[0] + "/"
        utility.make_dir(save_image_name)
        rect_files = []
        additional_infor = []
        for i in range(len(str_tag)):
            additional_infor.append(-1)
            rect_image = image_processing.get_rect_image(
                inputFile, int(coord[i][0]), int(coord[i][1]),
                int(coord[i][2]), int(coord[i][3]))
            rect_image_name = save_image_name + inputFile.split("/")[-1]
            rect_image_name = utility.add_name(rect_image_name, "_" + str(i))
            rect_files.append(rect_image_name)
            utility.save_image(rect_image, rect_image_name)
        utility.save_result(
            [coord, str_tag, number_tag, score, rect_files, additional_infor],
            outputFile)