Commit 38155e82 authored by Stephen Thompson's avatar Stephen Thompson

Issue #5 wrote up calibration

parent 3debb994
"""
this is adapted from
https://www.quickprogrammingtips.com/python/python-program-to-draw-a-square-and-chess-board-using-turtle.html
Copyright © Quick Programming Tips.
needs a bit of work to allow setting marker size etc and saving direct to a4 pdf so it prints good
"""
import turtle
def draw_box(t,x,y,size,fill_color):
t.pencolor(fill_color)
t.penup() # no drawing!
t.goto(x,y) # move the pen to a different position
t.pendown() # resume drawing
t.fillcolor(fill_color)
t.begin_fill() # Shape drawn after this will be filled with this color!
for i in range(0,4):
board.forward(size) # move forward
board.right(90) # turn pen right 90 degrees
t.end_fill() # Go ahead and fill the rectangle!
def draw_chess_board():
square_color = "black" # first chess board square is black
start_x = 0 # starting x position of the chess board
start_y = 0 # starting y position of the chess board
box_size = 30 # pixel size of each square in the chess board
for i in range(0,3): # 8x8 chess board
for j in range(0,2):
draw_box(board,start_x+j*box_size,start_y+i*box_size,box_size,square_color)
square_color = 'black' if square_color == 'white' else 'white' # toggle after a column
square_color = 'black' if square_color == 'white' else 'white' # toggle after a row!
board = turtle.Turtle()
board.shape("turtle")
board.speed(100)
draw_chess_board()
board.hideturtle()
ts = board.getscreen()
ts.getcanvas().postscript(file="chessboard.eps")
turtle.done()
......@@ -18,12 +18,14 @@ Outcomes:
After completing the workshop the student should be able to:
- Calibrate a video camera using a standard chessboard pattern.
- Calibrate a tracked pointer using an invariant point method.
- Explain the relationship between calibration errors and
calibration residual errors for the above two cases.
- Register a CT model of a pelvic phantom to physical space using
fiducial markers.
fiducial marker based registration.
- Explain the difference between fiducial registration
error, target registration error, and fiducial localisation error.
- Explain how rigid body transforms between different coordinate systems are
combined to create a basic augmented reality system.
- Explain the difference between calibration residual error, fiducial registration
error, and target registration error.
- Combine the above to create a augmented reality demonstration using the supplied phantom.
.. _`Medical Imaging Summer School`: https://medicss.cs.ucl.ac.uk/
......
.. highlight:: shell
.. _Introduction:
===============================================
Camera Calibration
===============================================
B.A.R.D. requires a calibrated camera. The calibration is necessary for two reasons.
- Augmented reality, overlaying virtual models over live video requires it, discuss why.
- BARD used the video camera to track objects in the real world, converting detected
pixel coordinates to model coordinates in 3D space requires a model of the camera.
The following instructions will guide you through calibrating your webcam.
Camera calibration
with BARD can be described briefly as:
- Capture a number (>3) images of a physical object of known geometry.
- Extract salient features from these images using computer vision (OpenCV)
- Fit a model to your camera that best fits the relationship between the
features on your model and the feature detected in the images.
See `Camera calibration with OpenCV`_ for a more complete explanation of
camera calibration and the physics of a pin hole camera.
Get hold of a suitably sized calibration chessboard. The should be one in the data
directory, or write a script to make one
(a) Take 5-20 pictures of chessboard using
::
python bardGrabVideoImages.py -o <output_dir>
hitting the ‘c’ key to dump a video image to the output folder. Press 'q' to quit
the application.
BARD provides a camera calibration program. Try it out.
::
python bardCameraCalibration -help
python bardCameraCalibration --xcorners 14 --ycorners 10 --size 24 -i <output_dir> --verbose
(filling in appropriate parameters: so -x gives the number of chessboard squares in the x direction, -y the number of chessboard squares in the y direction and -s gives the size of each chessboard square in millimetres)
This will find all file named .png in <output_dir>, attempt to detect chessboard corners from them,
and if successful use the corners to calibrate the camera.
Repeat calibration 2,3,4 times.
- which parameters vary the most?
- Is there a link between the reprojection error returned and the calibration
accuracy?
- Does the number and range of views affect the result?
- What happens if the chessboard is upside down?
.. _`Camera calibration with OpenCV`: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html
.. _`Medical Imaging Summer School`: https://medicss.cs.ucl.ac.uk/
.. _`OpenCV` : https://opencv.org/
.. _`VTK` : https://vtk.org/
.. _`SNAPPY`: https://weisslab.cs.ucl.ac.uk/WEISS/PlatformManagement/SNAPPY/wikis/home
.. _`EPSRC`: https://www.epsrc.ac.uk/
.. _`Wellcome EPSRC Centre for Interventional and Surgical Sciences`: http://www.ucl.ac.uk/weiss
......@@ -13,9 +13,13 @@ Build Your Own Image Guided Surgery System
:align: center
2. Select a USB camera. There are 2 spare in the TIG lab, or in Matt's office 8.24.
2. Find a USB camera, there are a few in the lab, or we can use a tablet with a rear facing camera.
3. Get B.A.R.D.
::
pip install scikit-surgerybard
3. Compile BARD in DEBUG mode using CMake and your compiler of choice. Basic build instructions are in the README.md in the repository containing this document.
4. Calibrate USB camera.
......
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