Skip to content

Commit

Permalink
Merge pull request #121 from enkaoua/master
Browse files Browse the repository at this point in the history
BARD fixes
  • Loading branch information
MattClarkson authored Feb 14, 2024
2 parents 3a4ec2f + a0c1131 commit e36b392
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"models": {
"models_dir": "data/models",
"target_model_vertices": [-1],
"model_visibilities": [1],
"model_visibilities": [0],
"model_opacities": [0.5, 1.0, 1.0],
"model_representations": ["w", "s", "s"],
"reference_to_model": "data/reference_to_model.txt",
Expand Down
30 changes: 30 additions & 0 deletions config/pointer_markers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"camera": {
"source": 0,
"window size": [640, 480],
"calibration directory": "data/calibration/matts_mbp_640_x_480"
},
"tracker": {
"type" : "sksaruco",
"source" : 0,
"calibration directory": "data/calibration/matts_mbp_640_x_480",

"rigid bodies" : [
{
"name" : "modelreference",
"filename" : "data/reference.txt",
"aruco dictionary" : "DICT_ARUCO_ORIGINAL"
},
{
"name" : "pointerref",
"filename" : "data/pointer.txt",
"aruco dictionary" : "DICT_ARUCO_ORIGINAL"
}
]
},

"interaction": {
"keyboard": true
},
"out path" : "pointer_positions",
}
8 changes: 6 additions & 2 deletions config/reference_with_model.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
"camera": {
"source": 0,
"window size": [640, 480],
"calibration directory": "data/calibration/matts_mbp_640_x_480"
"calibration directory": "data/calibration/matts_mbp_640_x_480",
"roi": [0, 0, 640, 480]

},
"tracker": {
"type" : "sksaruco",
"source" : 0,
"calibration directory": "data/calibration/matts_mbp_640_x_480",
"rigid bodies" : [
{
"name" : "modelreference",
"filename" : "data/reference_for_small_liver.txt",
"filename" : "data/reference.txt",
"aruco dictionary" : "DICT_ARUCO_ORIGINAL"
}
]
Expand Down
6 changes: 6 additions & 0 deletions doc/02_0_Build_Your_Own_Systems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ You may need to add

if you don't have administrative permissions.

You may also need to install `visioneer`

::

pip install versioneer

**Another method to get BARD and all its dependant packages is the following**
::

Expand Down
2 changes: 1 addition & 1 deletion doc/02_1_Calibrate_Your_Camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Use the '-o' option to specify a directory to save to, the
For example:
::

python bardVideoCalibration.py -c config/video_calib_chessboard.json -s tests/output -p myresults
python bardVideoCalibration.py -c config/video_calib_chessboard.json -s 0 -o tests/output -p myresults
#usage: bardVideoCalibration.py [-h] -c CONFIG [-s SOURCE] [-o OUTPUT] [-p PREFIX] [-ni] [-v]

Then, each time the program recalibrates, the results will be saved to the 'tests/output' folder, with the filename prefix 'myresults'.
Expand Down
2 changes: 1 addition & 1 deletion doc/02_2_Tracking_With_AuRcoTags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OpenCV.
python sksurgerybard.py --config config/example_config.json


When you place the reference marker (data/reference.pdf) in front of the webcam you should
When you place the reference marker found in (data/resources.pdf) in front of the webcam you should
see the tag pattern overlaid with spherical markers. Check that the webcam width and height
specified in the configuration file are the same as the images you performed calibration on.

Expand Down
22 changes: 14 additions & 8 deletions doc/02_3_Make_Your_Own_Pointer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pelvis phantom.
::

ls data/PelvisPhantom
CT_Fiduicial_Markers.txt
FullPelvis.vtk
PhantomCroppedJuly08.gipl.gz
>> CT_Fiduicial_Markers.txt FullPelvis.vtk PhantomCroppedJuly08.gipl.gz

For now, have a look in the file "CT_Fiduicial_Markers.txt". This is an ordered list
of the positions of 4 fiducial markers that we
Expand All @@ -45,17 +43,25 @@ BARD is tracking the markers, so we know where they are, however we're going to
tip of the pointer to locate the fiducial markers. We find the tip of the pointer
using a "pivot calibration". The tip of the pointer is held stationary whilst the
markers are pivoted around the tip. Pressing the "d" key whilst BARD is running will write
the pointer tracking matrix to the directory pointer_positions/bard_pointer_matrices. Do this around 100
times whilst pivoting the pointer. Whilst doing this it is important that you do not
the pointer tracking matrix to the directory specified in the config file pointer_markers.json, under the parameter "out path" and then inside the directory bard_pointer_matrices, so for example if the full path is specified to be pointer_positions, the pointer positions will go under the folder pointer_positions/bard_pointer_matrices.
Obtain around 100 pointer positions by pressing the key "d" whilst pivoting the pointer. Whilst doing this, it is important that you do not
move either the pointer tip or the tracking system (webcam).

When you have a directory of pointer matrices you can run this;
::

python bardPivotCalibration.py --help
python bardPivotCalibration.py --input pointer_positions/bard_pointer_matrices

The output of this should be list of 7 numbers. The first three are the x, y and z coordinates of the

The output of this should be list of 7 numbers, something like this:

::

Pointer Offset = [[-100.19828771 7.16207486 4.48010691]]
Pivot Location = [[-47.31630508 93.11369119 293.46139526]]
Residual Error = 8.382949342574744

The first three are the x, y and z coordinates of the
pointer tip relative to the tracking markers and should be copied into a file named
pointer_tip.txt. The next three numbers are the x,y, and z coordinates of the pointer
pivot point relative to the webcam. These can be ignored for now.
Expand All @@ -67,7 +73,7 @@ less pointer poses.
Now edit config/pointer_markers.json to include the the pointer_tag_to_tip transform, within the pointerData entry:
::

"pointerData": {
"pointer": {
"pointer_tag_file": "data/pointer.txt",
"pointer_tag_to_tip": "data/pointer_tip.txt"
},
Expand Down
15 changes: 13 additions & 2 deletions doc/02_4_Register_And_Ovelay.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
Register and Overlay Model
=============================

Create a plain text-file containing the coordinates of the prostate phantom fiducials, in the same order and format as data/PelvisPhantom/CT_Fiduicial_Markers.txt. These markers have been labeled on the phantom. You must measure the points using the tracked pointer, in the same order. You should end up with a file, of the same format as CT.txt, containing the corresponding world coordinates, lets call it world.txt.
Create a plain text-file containing the coordinates of the prostate phantom fiducials, in the same order and format as data/PelvisPhantom/CT_Fiduicial_Markers.txt.

You can do this by running

::

python sksurgerybard.py --config config/pointer_markers.json

These markers have been labeled on the phantom. You must measure the points using the tracked pointer, in the same order. To do this, you can place the pointer tip at each fiducial and press "d" to record the position.

This should output the files into whatever output file you specified. These points can now be copied and pasted into the world.txt file
You should end up with a file, of the same format as CT_Fiduicial_Markers.txt, containing the corresponding world coordinates, lets call it world.txt.

Compute the registration of CT points in CT_Fiduicial_Markers.txt to your world points, run this;
::

python bardProcrustes.py -f world.txt -m data/PelvisPhantom/CT_Fiduicial_Markers.txt
python bardProcrustes.py -f data/PelvisPhantom/world.txt -m data/PelvisPhantom/CT_Fiduicial_Markers.txt

So here -f stands for "fixed" points, also called "target" points in the literature, and -m stands for "moving" points, also called "source" points in the literature.
This will output a rotation, a translation, and Fiducial Registration Error.
Expand Down

0 comments on commit e36b392

Please sign in to comment.