diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..2039d35 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +EsophagusDatsetEditor \ No newline at end of file diff --git a/.idea/EsophagusDatsetEditor.iml b/.idea/EsophagusDatsetEditor.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/EsophagusDatsetEditor.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/Planck.xml b/.idea/dictionaries/Planck.xml new file mode 100644 index 0000000..716af54 --- /dev/null +++ b/.idea/dictionaries/Planck.xml @@ -0,0 +1,7 @@ + + + + endo + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..67e48d2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..57c7a88 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/EndoCalibrator.py b/EndoCalibrator.py new file mode 100644 index 0000000..02c0efd --- /dev/null +++ b/EndoCalibrator.py @@ -0,0 +1,37 @@ +import numpy as np +import cv2 +import os +from glob import glob + +class EndoCalibrator: + + def __init__(self, args): + self.args = args + + def calibrate(self, Is_example_showed=True): + criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001) + + square_size = self.args.square_size + pattern_size = (self.args.pattern_size_row, self.args.pattern_size_col) + pattern_points = np.zeros((np.prod(pattern_size), 3), dtype=np.float32) + pattern_points[:, :2] = np.indices(pattern_size).T.reshape(-1, 2) + pattern_points *= square_size + obj_points = [] + img_points = [] + + chess_img_list = glob(os.path.join(self.args.imgs_dir, '*' + self.args.chess_img_extend)) + + for fname in chess_img_list: + img = cv2.imread(fname) + gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + ret, corners = cv2.findChessboardCorners(gray, pattern_size) + + if ret: + obj_points.append(pattern_points) + corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria) + img_points.append(corners2) + + if Is_example_showed: + img = cv2.drawChessboardCorners(img, pattern_size, corners2, ret) + cv2.imshow("corners", img) + cv2.waitKey(0) diff --git a/__pycache__/EndoCalibrator.cpython-36.pyc b/__pycache__/EndoCalibrator.cpython-36.pyc new file mode 100644 index 0000000..06b161f --- /dev/null +++ b/__pycache__/EndoCalibrator.cpython-36.pyc Binary files differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..4462bfd --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +import argparse +from EndoCalibrator import EndoCalibrator + +parser = argparse.ArgumentParser() +parser.add_argument("--mode", type=str, required=True, choices=["calibrate"], help="処理モード") +parser.add_argument("--imgs_dir", type=str, required=True, help="画像が入ってるディレクトリ") +parser.add_argument("--output_dir", type=str, default="./temp", help="出力先") + +# カメラキャリブレーション用 +parser.add_argument("--square_size", type=float, default=20.0, help='正方形の一辺のサイズ[mm]') +parser.add_argument("--pattern_size_col", type=int, default=9, help="チェスの列数") +parser.add_argument("--pattern_size_row", type=int, default=6, help="チェスの行数") +parser.add_argument("--chess_img_extend", type=str, default=".JPG", help="チェス画像の拡張子") + +args = parser.parse_args() + +if __name__ == '__main__': + mode = args.mode + + if mode == 'calibrate': + editer = EndoCalibrator(args) + editer.calibrate()