Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds scaling option for calibrators #783

Open
wants to merge 4 commits into
base: noetic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions camera_calibration/nodes/cameracalibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def main():
group.add_option("--max-chessboard-speed", type="float", default=-1.0,
help="Do not use samples where the calibration pattern is moving faster \
than this speed in px/frame. Set to eg. 0.5 for rolling shutter cameras.")
group.add_option("--scale", type="float", default=None,
help="Scaling option for the input image relative to 640x480. \
Default scaled to 640x480, 1.0 result with no up/down scaling")

parser.add_option_group(group)

Expand Down Expand Up @@ -220,9 +223,11 @@ def main():
checkerboard_flags = cv2.CALIB_CB_FAST_CHECK

rospy.init_node('cameracalibrator')
node = OpenCVCalibrationNode(boards, options.service_check, sync, calib_flags, fisheye_calib_flags, pattern, options.camera_name,
checkerboard_flags=checkerboard_flags, max_chessboard_speed=options.max_chessboard_speed,
queue_size=options.queue_size)
node = OpenCVCalibrationNode(boards, options.service_check, sync,
calib_flags, fisheye_calib_flags, pattern, options.camera_name,
checkerboard_flags=checkerboard_flags,
max_chessboard_speed=options.max_chessboard_speed,
queue_size=options.queue_size, img_downscale=options.scale)
rospy.spin()

if __name__ == "__main__":
Expand Down
12 changes: 9 additions & 3 deletions camera_calibration/src/camera_calibration/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,11 @@ class Calibrator():
"""
Base class for calibration system
"""
def __init__(self, boards, flags=0, fisheye_flags = 0, pattern=Patterns.Chessboard, name='',
checkerboard_flags=cv2.CALIB_CB_FAST_CHECK, max_chessboard_speed = -1.0):
def __init__(self, boards, flags=0, fisheye_flags = 0,
pattern=Patterns.Chessboard, name='',
checkerboard_flags=cv2.CALIB_CB_FAST_CHECK,
max_chessboard_speed = -1.0,
scale = None):
# Ordering the dimensions for the different detectors is actually a minefield...
if pattern == Patterns.Chessboard:
# Make sure n_cols > n_rows to agree with OpenCV CB detector output
Expand Down Expand Up @@ -341,6 +344,7 @@ def __init__(self, boards, flags=0, fisheye_flags = 0, pattern=Patterns.Chessboa
self.last_frame_corners = None
self.last_frame_ids = None
self.max_chessboard_speed = max_chessboard_speed
self.scale = scale

def mkgray(self, msg):
"""
Expand Down Expand Up @@ -520,7 +524,9 @@ def downsample_and_detect(self, img):
# Scale the input image down to ~VGA size
height = img.shape[0]
width = img.shape[1]
scale = math.sqrt( (width*height) / (640.*480.) )

scale = float(self.scale) if self.scale else math.sqrt( (width*height) / (640.*480.) )

if scale > 1.0:
scrib = cv2.resize(img, (int(width / scale), int(height / scale)))
else:
Expand Down
44 changes: 29 additions & 15 deletions camera_calibration/src/camera_calibration/camera_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ def run(self):


class CalibrationNode:
def __init__(self, boards, service_check = True, synchronizer = message_filters.TimeSynchronizer, flags = 0,
fisheye_flags = 0, pattern=Patterns.Chessboard, camera_name='', checkerboard_flags = 0,
max_chessboard_speed = -1, queue_size = 1):
def __init__(self, boards, service_check = True,
synchronizer = message_filters.TimeSynchronizer, flags = 0,
fisheye_flags = 0, pattern=Patterns.Chessboard, camera_name='',
checkerboard_flags = 0, max_chessboard_speed = -1,
queue_size = 1, img_downscale = None):

if service_check:
# assume any non-default service names have been set. Wait for the service to become ready
for svcname in ["camera", "left_camera", "right_camera"]:
Expand All @@ -131,6 +134,7 @@ def __init__(self, boards, service_check = True, synchronizer = message_filters.
self._checkerboard_flags = checkerboard_flags
self._pattern = pattern
self._camera_name = camera_name
self._img_scale = img_downscale
self._max_chessboard_speed = max_chessboard_speed
lsub = message_filters.Subscriber('left', sensor_msgs.msg.Image)
rsub = message_filters.Subscriber('right', sensor_msgs.msg.Image)
Expand Down Expand Up @@ -176,13 +180,18 @@ def queue_stereo(self, lmsg, rmsg):
def handle_monocular(self, msg):
if self.c == None:
if self._camera_name:
self.c = MonoCalibrator(self._boards, self._calib_flags, self._fisheye_calib_flags, self._pattern, name=self._camera_name,
checkerboard_flags=self._checkerboard_flags,
max_chessboard_speed = self._max_chessboard_speed)
self.c = MonoCalibrator(self._boards, self._calib_flags,
self._fisheye_calib_flags, self._pattern,
name=self._camera_name,
checkerboard_flags=self._checkerboard_flags,
max_chessboard_speed=self._max_chessboard_speed,
scale = self._img_scale)
else:
self.c = MonoCalibrator(self._boards, self._calib_flags, self._fisheye_calib_flags, self._pattern,
checkerboard_flags=self.checkerboard_flags,
max_chessboard_speed = self._max_chessboard_speed)
self.c = MonoCalibrator(self._boards, self._calib_flags,
self._fisheye_calib_flags, self._pattern,
checkerboard_flags = self._checkerboard_flags,
max_chessboard_speed = self._max_chessboard_speed,
scale = self._img_scale)

# This should just call the MonoCalibrator
drawable = self.c.handle_msg(msg)
Expand All @@ -192,13 +201,18 @@ def handle_monocular(self, msg):
def handle_stereo(self, msg):
if self.c == None:
if self._camera_name:
self.c = StereoCalibrator(self._boards, self._calib_flags, self._fisheye_calib_flags, self._pattern, name=self._camera_name,
checkerboard_flags=self._checkerboard_flags,
max_chessboard_speed = self._max_chessboard_speed)
self.c = StereoCalibrator(self._boards, self._calib_flags,
self._fisheye_calib_flags, self._pattern,
name=self._camera_name,
checkerboard_flags=self._checkerboard_flags,
max_chessboard_speed=self._max_chessboard_speed,
scale=self._img_scale)
else:
self.c = StereoCalibrator(self._boards, self._calib_flags, self._fisheye_calib_flags, self._pattern,
checkerboard_flags=self._checkerboard_flags,
max_chessboard_speed = self._max_chessboard_speed)
self.c = StereoCalibrator(self._boards, self._calib_flags,
self._fisheye_calib_flags, self._pattern,
checkerboard_flags=self._checkerboard_flags,
max_chessboard_speed=self._max_chessboard_speed,
scale=self._img_scale)

drawable = self.c.handle_msg(msg)
self.displaywidth = drawable.lscrib.shape[1] + drawable.rscrib.shape[1]
Expand Down