Friday, 17 November 2017
Robot Jacobian in different coordinate for visual servoing
Reference link:
QUT online course: link
vpServo Class of ViSP library: link
vpVelocityTwistMatrix: link
Tuesday, 24 January 2017
VTK volume dimension
These settings specifies the dimension and position of your vtkImageData object.
SetExtent sets the dimensions in each axis. e.g. a dataset of 50 images and width/height of 512/512
myVtkImageData->SetExtent(0,511,0,511,0,49);
SetSpacing sets the size of a voxel (size in each direction x,y,z) in your dataset.
(default)
myVtkImageData->SetSpacing(1,1,1);
SetOrigin sets the position in 3D space of point 0 0 0 (first pixel)
(default)
myVtkImageData->SetOrigin(0,0,0)
The absolute size of a volume is determined by the 'Extent' x 'Spacing' (i.e. number of voxel multiply by size of the voxel). To downsample the volume (increase spacing), we should:
// Specify the size of the image data
imageData->SetExtent(-100/scale, 100/scale, -100/scale, 100/scale, -50/scale, 50/scale);
imageData->SetSpacing(scale, scale, scale);
void vtkImageData::GetDimensions(int *dOut)
{
const int* extent = this->Extent;
dOut[0] = extent[1] - extent[0] + 1;
dOut[1] = extent[3] - extent[2] + 1;
dOut[2] = extent[5] - extent[4] + 1;
}
Friday, 7 October 2016
Compile & Install OpenCVBlobsLib on Windows
Win7 64bit, Visual Studio 2012, OpenCV 3.0
1. Install pthread-win32 which is required by OpenCVBlobsLib
Instruction: InstallingpthreadsforVisualStudio.pdf
2. Download OpenCVBlobsLib: http://opencvblobslib.github.io/opencvblobslib/
3. Configure with CMake. Make sure BUILD_SHARED_LIBS is off. CMAKE_CXX_FLAGS_(DEBUG/RELEASE)/CMAKE_C_FLAGS_(DEBUG/RELEASE) has value /MTd (Debug) and /MT (Release) for static link.
4. Configure/Generate/Build
1. Install pthread-win32 which is required by OpenCVBlobsLib
Instruction: InstallingpthreadsforVisualStudio.pdf
2. Download OpenCVBlobsLib: http://opencvblobslib.github.io/opencvblobslib/
3. Configure with CMake. Make sure BUILD_SHARED_LIBS is off. CMAKE_CXX_FLAGS_(DEBUG/RELEASE)/CMAKE_C_FLAGS_(DEBUG/RELEASE) has value /MTd (Debug) and /MT (Release) for static link.
4. Configure/Generate/Build
Wednesday, 24 February 2016
Add additional slice to model in Solidworks
- Open part of model if it's in assembly
Sketchtap ->Sketchbutton (3D Sketch) -> Select Line (ShortcutL)- Draw three lines (points) and define a plane using the points (NOT two lines)
- To define a plane,
Featuretab ->Reference Geometry->Plane - Right click the created
planeunderFeatureManager Design Tree, selectsketch - Select the new
sketch, pressConvert Entities, then select the plane we want to extrude from original model. - With the
sketchselected, pressExtruded Boss/Basebutton.- After all slices extruded, we can hide the 3D sketches for better visualization.
- Hide other part, only leave extruded part shown. Save the extruded part as separate file with proper name (Note: use
copy and continuein save dialog). - Leave the part edit mode without saving or changing anything in assembly.
- Import the saved extruded part in assembly.
- Mate three planes (front/top/right) between extruded part and original part.
Export to mesh for colouring
- Save as IGS (choose specified coordinate)
- Open the IGS file, save as VRML (*.wrl) with VRML97 version which is supported by meshlab
- Close IGS file without saving it.
Tuesday, 2 February 2016
Setup ROS for multiple machines
1. Pre-request
- Setup ssh for all computers, usually ssh-client is installed but not ssh-server.
sudo apt-get install openssh-server
sudo service ssh status
sudo ufw allow ssh
- Set host IP for each computer:
- Get the IP:
hostname -I
- set IP for
ROS_IP export ROS_IP=$IP_ADDR$
- Setup ssh for all computers, usually ssh-client is installed but not ssh-server.
sudo apt-get install openssh-server sudo service ssh status sudo ufw allow ssh - Set host IP for each computer:
- Get the IP:
hostname -I - set IP for
ROS_IPexport ROS_IP=$IP_ADDR$
- Get the IP:
2. Master
There will be a computer run as master machine where roscore will be run.
- Set
ROS_MASTER_URI export ROS_MASTER_URI=http://localhost:11311
- Start
roscore
- Start test program
rosrun rospy_tutorials listener.py
There will be a computer run as master machine where
roscore will be run.- Set
ROS_MASTER_URIexport ROS_MASTER_URI=http://localhost:11311 - Start
roscore - Start test program
rosrun rospy_tutorials listener.py
3. Slaves (other machines)
- ssh to remote PC
- Set
ROS_MASTER_URI export ROS_MASTER_URI=http://$MASTER_IP_HERE$:11311
- Start test program
rosrun rospy_tutorials talker.py
We should see in the master the message sent by slave is received.
http://nootrix.com/software/ros-networking/
- ssh to remote PC
- Set
ROS_MASTER_URIexport ROS_MASTER_URI=http://$MASTER_IP_HERE$:11311 - Start test program
rosrun rospy_tutorials talker.py
We should see in the master the message sent by slave is received.
http://nootrix.com/software/ros-networking/Thursday, 30 July 2015
Qt 4 and 5 in same machine (Ubuntu)
"qtchooser -list-versions": get available version of qt.
modify following file
/usr/lib/x86_64-linux-gnu/qtchooser/5.conf
so that it specify directory of qmake and lib of qt. Example for qt5:
/opt/Qt5.5.0/5.5/gcc_64/bin
/opt/Qt5.5.0/5.5/gcc_64
To choose different qt version:
"export QT_SELECT=5"
To check current using qt:
"qmake -v"
"export PKG_CONFIG_LIBDIR=/opt/qt-4.8.7/lib:$PKG_CONFIG_LIBDIR"
"export PATH=/opt/qt-4.8.7/bin:$PATH"
"export PKG_CONFIG_PATH=/opt/qt-4.8.7/lib/pkgconfig/:$PKG_CONFIG_PATH"
"export PATH=/opt/qt-4.8.7/bin:$PATH"
"export PKG_CONFIG_PATH=/opt/qt-4.8.7/lib/pkgconfig/:$PKG_CONFIG_PATH"
Monday, 27 July 2015
Configure AJA device
0. Dependency:
g++, libasound2, libsound2-dev, and libncurses5-dev
For Qt-based demo, qt4-dev-tools is required. qt4-dev-tools doesn't include QtMultimedia which is required by the demo program.
In Ubuntu:
sudo apt-get install libasound2
sudo apt-get install autoconf
1. In terminal, under directory ntv2projects in the SDK. Use make command.
2. Load the device driver: sudo SDK_Dir/bin/loadOEM2K
3. Verify XENA2 is installed using 'lsmod'
------------------------------
Load .ko (driver) from boot (DO NOT WORKED FOR AJA DEVICE):
1. copy the XENA2.ko to /lib/modules/3.16.0-41-generic/kernel/drivers/ntv2
2. edit /etc/modules and add a line "XENA2"
3. "sudo depmod -a"
4. reboot
Make sure the kernel version is the one currently used.
------------------------------
------------------------------
Base on discussion in this link. To avoid linking error of pthread, following lines need to be added to the CMakeLists.txt due to a cmake bug.
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
Thursday, 2 July 2015
OpenCV findCirclesGrid with color filter
1. Convert RGB image to HSV for better colour identification.
As a side note, in OpenCV H has values from 0 to 180, S and V from 0 to 255. The red color, in OpenCV, has the hue values approximately in the range of 0 to 10 and 160 to 180.
In HSV space:
red primary at 0°
green primary at 120° (60 - opencv)
blue primary at 240° (120 - opencv)
yellow (30 - opencv)
// Convert input image to HSV
2. Use cv::inRange function to filter out colour
// Threshold the HSV image, keep only the red pixels
As a side note, in OpenCV H has values from 0 to 180, S and V from 0 to 255. The red color, in OpenCV, has the hue values approximately in the range of 0 to 10 and 160 to 180.
In HSV space:
red primary at 0°
green primary at 120° (60 - opencv)
blue primary at 240° (120 - opencv)
yellow (30 - opencv)
// Convert input image to HSV
cv::Mat hsv_image; cv::cvtColor(bgr_image, hsv_image, cv::COLOR_BGR2HSV);
2. Use cv::inRange function to filter out colour
// Threshold the HSV image, keep only the red pixels
cv::Mat lower_red_hue_range; cv::Mat upper_red_hue_range;
cv::inRange(hsv_image, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), lower_red_hue_range); cv::inRange(hsv_image, cv::Scalar(160, 100, 100), cv::Scalar(179, 255, 255), upper_red_hue_range);
3. Use cv::addWeighted function to filter out colour
cv::Mat red_hue_image; cv::addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, red_hue_image);
Reference:
[1] Detect red circles in an image using OpenCV
Thursday, 4 June 2015
Argon Plasma Coagulation (APC) laparoscopy application
1. Use of Neutral Argon Plasma in the Laparoscopic Treatment of Endometriosis: link
Neutral argon plasma can be utilized as a multi-functional device that has vaporization, coagulation, and superficial cutting capacities with minimal thermal spread and acceptable outcomes. The use of neutral argon plasma appears to be efficacious and safe for the complete treatment of endometriotic implants.
Vaporization: the probe was directed at the lesions from a distance of close to 5mm, spraying the tissue surface at an angle of approximately 45 degrees until the tissue surface demonstrated a characteristic silver, shiny appearance and there was visual confirmation of complete eradication of the lesions
Cutting: closer to the tissue surface at approximately a 90-degree angle
Within the limitations of a pilot study, plasma energy appears to be efficacious and safe for the complete vaporization of endometriotic implants and can be used for the laparoscopic management of endometriosis.
2. Barrett's Oesophagus: Long-term Follow-up After Complete Ablation With Argon Plasma Coagulation: link
laparoscopic fundoplication
3. Argon plasma coagulation for successful treatment of early gastric cancer with intramucosal invasion: link
3. Argon plasma coagulation for successful treatment of early gastric cancer with intramucosal invasion: link
hematischesis:
Saturday, 30 May 2015
Different ways to estimate relative pose during visual servoing
In order to obtain relative pose (pdHp) between current and desired pattern pose (cHp and cHpd) in camera frame, we can:
Method 1: Find rigid transformation between two set of pattern points (X_p and X_pd) in camera frame directly using a findRigidTransform() function described here.
Method 2: Calculate cHp and cHpd using the findRigidTransform() as the pattern points in local coordinate is known. The relative pose pdHp is calculated as:
Method 3: Calculate cHp and cHpd using the cv::solvePnP() function which finds an object pose from 3D-2D point correspondence. The relative pose is then calculated same as method 2.
According to the results, Method 1 is least stable and accurate as the estimated relative pose varies a lot and very different from the other two methods.
Method 2 and 3 have similar results in which Method 3 seems better since the rotation part is closer to Identity when the relative pose should be the same.
Summary: Method 3 is the best for the time being.
Method 1: Find rigid transformation between two set of pattern points (X_p and X_pd) in camera frame directly using a findRigidTransform() function described here.
Method 2: Calculate cHp and cHpd using the findRigidTransform() as the pattern points in local coordinate is known. The relative pose pdHp is calculated as:
pdHp = inv(cHpd) * cHp
Method 3: Calculate cHp and cHpd using the cv::solvePnP() function which finds an object pose from 3D-2D point correspondence. The relative pose is then calculated same as method 2.
According to the results, Method 1 is least stable and accurate as the estimated relative pose varies a lot and very different from the other two methods.
Method 2 and 3 have similar results in which Method 3 seems better since the rotation part is closer to Identity when the relative pose should be the same.
Summary: Method 3 is the best for the time being.
Labels:
Robotics
Thursday, 28 May 2015
Relative trajectory playback from different starting pose
1. Given a trajectory in the global frame, a relative trajectory (H_rela) can be generated as:
H_rela = inv(H_1) * H_i
Since the relative transformation is regard to local frame (first pose in the trajectory). H_rela(1) is Identity
2. For a new starting pose in the global frame H_start, a new trajectory begins at the starting pose is generated as:
H_new = H_start * H_rela
where H_new is in the global frame.
Labels:
Robotics
Tuesday, 5 May 2015
Git - update submodule
Update and merge/rebase local submodule with upstream:
Under main project directory, see difference of submodule:
3 cases:
It means that
If the latter is right, change the version that the submodule is at with:
Reference:
[1] http://git-scm.com/book/en/v2/Git-Tools-Submodules
[2] http://stackoverflow.com/questions/6006494/git-submodule-modified-files-status
git submodule update --remote --merge
git submodule update --remote --rebase
Under main project directory, see difference of submodule:
git diff --submodule
3 cases:
- Same commit but submodule has dirty suffix
-Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7
+Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7-dirty
It means that
git status in the submodule isn't clean. cd into the submodule and see what's going on.- Different commit, former one is correct (the one in main project)
-Subproject commit c4478af032e604bed605e82d04a248d75fa513f7
+Subproject commit c79d9c83c2864665ca3fd0b11e20a53716d0cbb0
If the former is right, add and commit the new version of the submodule in main project
- Different commit, latter one is correct (the one in submodule)
git submodule update $submodule_name$
Reference:
[1] http://git-scm.com/book/en/v2/Git-Tools-Submodules
[2] http://stackoverflow.com/questions/6006494/git-submodule-modified-files-status
Sunday, 29 March 2015
Set 'd' postfix for debug dll/lib using CMake
if(WIN32)
# Postfix of .lib and .dll
set(CMAKE_DEBUG_POSTFIX "d")
endif()
http://stackoverflow.com/questions/17865072/linking-against-a-debug-version-of-a-library-with-cmake
# Postfix of .lib and .dll
set(CMAKE_DEBUG_POSTFIX "d")
endif()
http://stackoverflow.com/questions/17865072/linking-against-a-debug-version-of-a-library-with-cmake
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:
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:
- 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:
Reference:
Skew symmetric matrix
Skew symmetric matrix
Labels:
Robotics
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
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.
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
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:
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:
Subscribe to:
Posts (Atom)







