Commit d8ca6f85 authored by Matt Clarkson's avatar Matt Clarkson

Issue #18: Added program to generate pattern of dots

parent 5bf676e9
Pipeline #3733 passed with stages
in 6 minutes and 48 seconds
......@@ -65,6 +65,7 @@ setup(
'sksurgeryvideolag=sksurgeryutils.ui.sksurgeryvideolag_command_line:main',
'sksurgerycharucotest=sksurgeryutils.ui.sksurgerycharucotest_command_line:main',
'sksurgeryrendermodelslikecamera=sksurgeryutils.ui.sksurgeryrendermodelslikecamera_command_line:main',
'sksurgerymakecalibrationdots.py=sksurgeryutils.ui.sksurgerymakecalibrationdots_command_line:main',
],
},
)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from sksurgeryutils.ui.sksurgerymakecalibrationdots_command_line import main
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
# -*- coding: utf-8 -*-
""" Command line processing for sksurgerymakecalibrationdots app. """
import argparse
from sksurgeryutils import __version__
from sksurgeryutils.ui.sksurgerymakecalibrationdots_demo \
import make_calibration_dots
def main(args=None):
""" Entry point for sksurgerymakecalibrationdots application"""
parser = argparse.ArgumentParser(description='sksurgerymakecalibrationdots')
parser.add_argument("-xs", "--x_size",
required=False,
default=2600,
type=int,
help="Image width in pixels.")
parser.add_argument("-ys", "--y_size",
required=False,
default=1900,
type=int,
help="Image height in pixels.")
parser.add_argument("-r", "--radius",
required=False,
default=25,
type=int,
help="Radius of dots in pixels.")
parser.add_argument("-s", "--spacing",
required=False,
default=100,
type=int,
help="Spacing of dots in pixels.")
parser.add_argument("-xd", "--x_dots",
required=False,
default=25,
type=int,
help="Number of dots in x directio.")
parser.add_argument("-yd", "--y_dots",
required=False,
default=18,
type=int,
help="Number of dots in y direction.")
parser.add_argument("-o", "--output_file",
required=True,
default=None,
type=str,
help="Output file to save image to.")
version_string = __version__
friendly_version_string = version_string if version_string else 'unknown'
parser.add_argument(
"-v", "--version",
action='version',
version='sksurgerymakecalibrationdots version ' \
+ friendly_version_string)
args = parser.parse_args(args)
make_calibration_dots(args.x_size,
args.y_size,
args.radius,
args.spacing,
args.x_dots,
args.y_dots,
args.output_file
)
# -*- coding: utf-8 -*-
""" Function to implement the drawing of a calibration pattern of dots. """
import cv2
import numpy as np
def make_calibration_dots(width,
height,
radius,
spacing,
x_dots,
y_dots,
output_file
):
"""
Function that makes a calibration pattern of dots.
:param width: horizontal size of output image in pixels
:param height: vertical size of output image in pixels
:param radius: radius of dots in pixels
:param spacing: spacing of dots in pixels
:param x_dots: number of dots in x
:param y_dots: number of dots in y
:param output_file: output file
"""
# Current calibration grid
# 26x19 5mm squares = 25x18 calibration points, 5mm apart = 125x90mm
# 19x11 3mm squares = 18x10 calibration points, 3mm apart = 54x30mm
# Dot pattern
#
centre_x = (width - 1)/2.0
centre_y = (height - 1) / 2.0
half_width = (spacing * (x_dots - 1))/2.0
half_height = (spacing * (y_dots - 1))/2.0
image = 255 * np.ones(shape=[height, width], dtype=np.uint8)
one_third_x = (x_dots // 3) - 1
one_third_y = (y_dots // 3) - 1
two_third_x = (x_dots - 1) - one_third_x
two_third_y = (y_dots - 1) - one_third_y
for y_index in range(y_dots):
for x_index in range(x_dots):
dot_x = int(centre_x + (y_index * spacing) - half_width)
dot_y = int(centre_y + (x_index * spacing) - half_height)
rad = radius
big = 2 * rad
if x_index == one_third_x and y_index == one_third_y:
rad = big
if x_index == one_third_x and y_index == two_third_y:
rad = big
if x_index == two_third_x and y_index == two_third_y:
rad = big
if x_index == two_third_x and y_index == one_third_y:
rad = big
cv2.circle(image, (dot_x, dot_y), rad, (0, 0, 0), thickness=-1)
cv2.imwrite(output_file, image)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment