Monday, 23 March 2015

Angular velocity and Skew Symmetric Matrices

A matrix S is said to be skew symmetric if and only if: S^T + S = 0.
Thus S contains only three independent entries and every 3 × 3 skew symmetric matrix has the form:


If a = (a_x, a_y, a_z)' is a 3-vector, the skew symmetric matrix S(a) can be defined as:

Important properties of the matrix S(a):
  • Linearity: for any vector a and b belonging to R^3 and scalars alpha and beta:
    • S(alpha*a + beta*b) = alpha*S(a) + beta*S(b)
  • Calculation of cross project: for any vector p = (p_x, p_y, p_z)':
    • S(a)*p = a.cross(p)
  • For an orthogonal matrix (such as rotation) R in SO(3), and a,b are vector in R^3:
    • R(a.cross(b)) = (R*a).cross(R*b)
  • For R in SO(3) and a vector a belongs to R^3, we have:
    • the deviation is:





  • Computing the derivative of the rotation matrix R is equivalent to a matrix multiplication by a skew symmetric matrix S, that is:

Velocity of a point on a rotating rigid body which is moving with a linear velocity is derived in:

Monday, 16 March 2015

Paper note: Robust Jacobian Estimation for Uncalibrated Visual Servoing

This paper propose a robust Jacobian estimation for uncalibrated visual servoing. For the term "uncalibrated", authors refer to model-free and nonparametric Jacobian (i.e. non-analytic form).
To estimate the Jacobian, a Broyden rank-one secant update has been proposed which requires a good initial guess. Farahmand et al. propose local least-squares (LLS) estimation to utilize the memory of visual-motor data. This method estimated the Jacobian of any point in the workspace directly from raw visual-motor data in a close neighborhood (K-NN) of the point under consideration.
The following equation consider the Jacobian estimation as a minimization problem:



It is pointed out that the least-squares (LS) estimator is not robust to outliers as its weight function assign weight equally to all data including outliers. The L1-norm is more robust but both have the least possible breakdown point (BDP). The BDP refers to  the smallest proportion of incorrect samples that the estimator can tolerate before they arbitrarily affect the model fitting. In other words, BDP of an estimator is a measure of its resistance to outliers. The maximum BDP is 50% where outliers and inliers have equal amount. In the paper, two other M-estimators with a redescending  influence function, Tukey’s Biweight (BW) function and Geman-McClure (GM) estimator, is investigated. The tex2html_wrap_inline3570 function for GM estimator is written as:


For other type of M-estimators, refer to this link. Note that the formulation of the GM estimator in the paper is a bit different from the link, more investigation needed.



The scale parameter σ quantifies how the probability distribution is spread. For example, variance is a measure of scale for the normal distribution. To estimate a scale for a M-estimator, the paper uses Median Absolute Deviation (MAD), which has the highest possible BDP of 50% and a bounded influence function and is computationally efficient, regardless its low Gaussian efficiency (37%).
More info about MAD and other way to measure scale of data see: link

A common method to solve (6) is the Iteratively Reweighted Least Squares (IRLS) that is widely used as an efficient implementation of robust M-estimator in nonlinear optimization domains. The IRLS used in the paper for the Jacobian estimation is shown as:


The algorithm presented in the paper can be summarized as follows:

A.1 Initialize visual-motor memory
A.2 Determine neighbors: K-NN
A.3 Estimate initial scale: Use MAD to find initial measure of scale σ
A.4 Find initial weights: Initialize weight matrix W0 according to the found norm and scale.
A.5 Estimate the Jacobian: Use JACOBIANESTIRLS
A.6 Update control signal
A.7 Update memory: The new visual-motor pair is added to the memory for later use P = P +1 (All pairs are kept?)
A.8 Goto step A.2










Reference:
[1] A. Shademan, A. M. Farahmand, and M. Jägersand, “Robust Jacobian estimation for uncalibrated visual servoing,” Proc. - IEEE Int. Conf. Robot. Autom., pp. 5564–5569, 2010.

Wednesday, 17 December 2014

Crop training image patch (imageclipper)

Prepare imageclipper tool:
1. Download imageclipper (link) via git:
https://github.com/JoakimSoderberg/imageclipper
2. Install Boost and OpenCV. A prebuilt boost is available at http://boost.teeks99.com/ (use correct version for corresponding platform)
3. Build imageclipper from source (CMake is required) by following the instructions here.
4. Build/Compile Project (Visual Studio for Windows)

Modify the code for square bounding box purpose:
1. Locate line 619 in the imageclipper.cpp
2. Comment line 619 and add one line:
//         param->rect.height = abs( point0.y - y );
           param->rect.height = param->rect.width;
Therefore height is always equal to width. Rebuild project after modification

Run imageclipper.exe:
1. Follow instructions explained the command usage: link
2. Create output image format (-i for video input, -v for video input):
For example, this for a video input
%d/imageclipper/%i_%f_%04x_%04y_%04w_%04h.png
will create filename like:
video_1_0276_0134_0055_0055.png

Create a txt file for crop region:
See instructions here.


The cropping GUI should looks like this:

The region on the tool I would like to crop include:
iDot, IS_Logo, Wheel_Pin, Wheel
Please refer to Fig.4 in this paper for reference:  Appearance learning for 3D tracking of robotic surgical tools

Some examples for cropped samples:

Thursday, 20 November 2014

Hand-eye calibration for DVRK


To validate the hand-eye calibration:


Handeye problem as AX=XB:


To validate handeye by backprojecting to image


Monday, 9 June 2014

Hand-eye calibration

Install MATLAB calibration toolbox: link
Install addon for the hand-eye calibration: link

Note:
In order to use normal calibration pattern (instead of the dots pattern provided by the hand-eye program), we need to do: "active_images = 1:num_of_views;" before calling "handeye.m".

Step 1: Record stable frames number in both left and right video, save it in a txt file.
Step 2: Copy/Paste the frames to the calibration folder, rename them from XXX_0000 to XXX_0020 (for example).
Step 3: Run calib.m (MATLAB calibration toolbox). Go through the normal camera calibration procedure.
Step 4: For the hand-eye calibration, import tracking data of marker that was attached to the camera (or robot kinematic data).
Step 5: Smooth the tracking data for both position and quaternion based on the frame number recorded in the Step 1.
Step 6: Run handeye.m.

Wednesday, 14 May 2014

OpenCV save cv::Mat in double/float precision

In order to read the OpenCV matrix in double/float precision in MATLAB, we can save the matrix using:

std::ofstream myfile;
myfile.open("output.csv");
myfile << format(outMat,"csv") << std::endl << std::endl;
myfile.close();


Above code save the matrix into a csv (comma-separated values) file which can be imported by MATLAB easily using 'load' function.

Reference:
Saving matrix in double precision from OpenCV (C++) for Matlab