LoginSignup
0
0

More than 3 years have passed since last update.

Pixel4のカメラで学ぶDepth map-4(pre-process最終回)

Posted at

はじめに

この記事はNoteで連載している記事で扱っているCode部分のみを切り出しています。技術背景等にご興味がある方はNoteの記事の方をご参照ください。
 今回は前処理部分の最終回となります。今までDark shading補正及び画像修正処理で下準備ができたので、これらを統合し、Pre-process部分を完成させます。

Enum定義

 Global定数として使用する値を先に定義しておきます。画像サイズやプロジェクトのフォルダー関連情報を一箇所に集めておき管理しやすくするのが目的です。

parameter.py
class ProjectFolder(Enum):
    """ Define project folders
    TOP
     project top folder
    DARK
     folder of dark shading
    PGM
     folder for pgm, the folder should include left and right raw image data
    JPG
     folder for saving JPEG images
    DISPARITY
      folder for saving disparity images as a result of depth estimation
    """
    TOP = #Projectのトップレベルの絶対パス
    DARK = 'dark/'
    PGM = 'pgm/'
    JPG = 'jpg/'
    DISPARITY = 'disparity/'


class ImageSize(Enum):
    """ Define image size
    WIDTH
     image width
    HEIGHT
     image height
    """
    HEIGHT = 1512
    WIDTH = 2016

Main関数定義

 全ての準備は揃いました。それではMain関数を定義します。

main.py
import parameters
import dark
import dualpixel
import helper
import matplotlib.pyplot as plt


if __name__ == "__main__":
    # path setting
    DARK_PATH = parameters.ProjectFolder.TOP.value + parameters.ProjectFolder.DARK.value
    PGM_PATH = parameters.ProjectFolder.TOP.value + parameters.ProjectFolder.PGM.value
    JPG_PATH = parameters.ProjectFolder.TOP.value + parameters.ProjectFolder.JPG.value

    # image size setting
    width = int(parameters.ImageSize.WIDTH.value)
    height = int(parameters.ImageSize.HEIGHT.value)

    # initialize dark image
    print('--- Start dark shading correction ---')
    dk_sh = dark.Dark(DARK_PATH, 'pgm', dsize=(width, height))

    # calculate gain map for dark shading correction
    # left_gain_map     :use this map to correct left-PD image
    # right_gain_map    :use this map to correct right-PD image
    left_gain_map, right_gain_map = dk_sh.get_gain_map(kernal_size=32, analog_gain=[0.6, 0.6, 0.6], \
        left_offset=(0, 150), right_offset=(-80, 150))

    # initialize dualpd class
    print('--- Start raw data cooking ---')
    dualpd = dualpixel.DualPixel(PGM_PATH, 'pgm', dsize=(width, height))

    # set left and right gain map
    dualpd.set_dksh_gain_map(left_gain_map, left=True)
    dualpd.set_dksh_gain_map(right_gain_map, left=False)

    # run process
    raw_data_file_list, proc_imgs = dualpd.run_process(bi_kernel_size=5, bi_disp=75, \
        unsharp_sigma=2, eq_grid_size=2, eq_sigma=32, eq_mean_value=128)

    # write images
    print('--- Outputing the processed images to folder ---')
    helper.write_img_to_path(JPG_PATH, raw_data_file_list, proc_imgs)

    print('--- Finished !! ---')

今まで定義したものを処理順に並べて流すだけです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0