Thursday, September 18, 2014

Matlab marker size color


plot(xini(1),xini(2),'ko','MarkerSize',10, 'MarkerFaceColor',[0,0,0])
plot(tgt(1),tgt(2),'rd','MarkerSize',10, 'MarkerFaceColor',[1,0,0])


Tuesday, September 16, 2014

Skip items in Matlab legend


You can specify a vector of plot handles to use in the legend. For example:

h1 = plot(rand(1,10));      % Blue line
hold on;
h2 = plot(rand(1,10),'r');  % Red line
h3 = plot(rand(1,10),'g');  % Green line
legend([h1 h3],{'hello','world'});  % Only the blue and green lines appear
                                    %   in the legend

Wednesday, July 30, 2014

Ubuntu 12.04 – The System is running in low-graphics mode

How do we fix it?
There is simple fix for this issue. Once you get the error on your screen press ALT+CTRL+F1, once in new screen type/run these commands
sudo apt-get update
sudo apt-get purge flglrx
sudo reboot
The message should be gone, if not there is good chnage that you have also trouble with gdm and you can fix it in these steps:
Again press ALT+CTRL+F1 and run these commands
sudo apt-get install gdm
sudo service gdm restart

Thursday, December 26, 2013

SURF and BRISK in OpenCV

Today I spent half a day to compare the two feature detector and descriptor SURF and BRISK.

The conclusion is

  • SURF is more accurate but takes much longer
  • BRISK is 10 times faster with comparable accuracy. 
One thing to notice:
when using Brute-force matcher, mind the normType. See HERE
C++: BFMatcher::BFMatcher(int normType=NORM_L2, bool crossCheck=false )
Parameters:
* normType – One of NORM_L1, NORM_L2, NORM_HAMMING,NORM_HAMMING2. L1 and L2 norms are preferable choices for SIFT and SURF descriptors, 
* NORM_HAMMING should be used with ORB, BRISK and BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4.

The other thing to notice is the threshold used to select good matches. Maybe RANSAC should be used.
SURF feature
BRISK feature
 



Saturday, November 16, 2013

Das ist eine brilliante Idee

Teil 4 Lektion 1


  • Gibt es schon Reaktionen auf den Sprachkurse?
  • Ja, wir haben viele Hörerbriefe bekommen.
  • Und was steht in den Briefen?
  • Die kann ich doch nicht alle vorlesen. Das dauert viel zu lange.
  • Nicht alle, aber einige - bitte!
  • Ja, das interessiert mich auch.
  • Na gut. 
  • Aber bitte, machen Sie es kurz!
  • Hier habe ich einen Brief von Herrn Card aus Amerika - Moment. Mir gefallen die Abenteuer von Andreas - asl Portier im Hotel Europa.
  • Mir auch
  • s
  • Und hier ist ein Brief von Angela aus Kolumbien. Sie schreibt, ' Ich bin so glücklick, weil ich die Grammatik studiert habe. Jetzt verstehe ich den Akkusativ - der war immer ...'
  • Grammatik, Grammatik, Akkusativ - das ist ja langweilig! Schreiben die Hörer den nichts über mich?! Wie finden die Hörer mich, das will ich wissen!
  • Kein Problem, Ex.  Hier ist ein Brief aus England - da steht etwas über dich! ' The intruduction of Ex is a brilliant idea. '
  • Das verstehe ich doch nicht! Was heißt das denn auf deutsch?
  • Du bist eine brillante Idee!
  • Idee? Wieso bin ich eine Idee? Ich bin ich!
  • s
  • Das hier ist noch ganz wichtig: Manche Hörer schreiben, daß sie Ex nicht so gut verstehen. 
  • Wir können ihr ja eine andere Stimme geben.
  • Probieren wir es doch mal! Ex, sprich mal etwas!
  • Ben dem Zauberwort sollte ich das Buch verlassen und ...
  • Okay! Stop! Und noch einmal bitte!
  • Ben dem Zauberwort sollte ich das Buch verlassen und ...
  • Kann ihre Stimme nicht ganz normal bleiben?
  • Nein - Ex ist ja eine besondere Person, ein weiblicher kobold, da braucht sie auch eine besondere Stimme. 
  • Das finde ich auch!
  • Aber das ist ein technisches Problem. Das lösen wir später. 

Saturday, November 2, 2013

Finds an object pose from 3D-2D point correspondences

C++: bool solvePnP(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=ITERATIVE )


Parameters:
  • objectPoints – Array of object points in the object coordinate space, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. vector<Point3f> can be also passed here.
  • imagePoints – Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. vector<Point2f> can be also passed here.
  • cameraMatrix – Input camera matrix A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} .
  • distCoeffs – Input vector of distortion coefficients (k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]]) of 4, 5, or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.
  • rvec – Output rotation vector (see Rodrigues() ) that, together with tvec , brings points from the model coordinate system to the camera coordinate system.
  • tvec – Output translation vector.
  • useExtrinsicGuess – If true (1), the function uses the provided rvec and tvec values as initial approximations of the rotation and translation vectors, respectively, and further optimizes them.
  • flags –
    Method for solving a PnP problem:
    • CV_ITERATIVE Iterative method is based on Levenberg-Marquardt optimization. In this case the function finds such a pose that minimizes reprojection error, that is the sum of squared distances between the observed projections imagePoints and the projected (using projectPoints() ) objectPoints .
    • CV_P3P Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang “Complete Solution Classification for the Perspective-Three-Point Problem”. In this case the function requires exactly four object and image points.
    • CV_EPNP Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the paper “EPnP: Efficient Perspective-n-Point Camera Pose Estimation”.
The function estimates the object pose given a set of object points, their corresponding image projections, as well as the camera matrix and the distortion coefficients.

Friday, October 11, 2013

Tuesday, September 10, 2013

Two UAV from NWPU

西工大 灵龙  NWPU Ling Long
风火轮 滚翼机



Thursday, August 15, 2013

Image stiching in OpenCV

Reference to http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/

Main steps of the code:
  1. Load two images;
  2. Convert to gray scale;
  3. Using SURF detector to find SURF descriptor in both images;
  4. matching the SURF descriptor using FLANN Matcher;
  5. Postprocessing matches to find good matches
  6. Using RANSAC to estimate the Homography matrix using the matched SURF descriptors;
  7. Warping the images based on the homography matrix

The image shows the definition of Homography which transforms 2d Planar point to the image plane. 


 The following image is shows the initial image and the matched SURF features of the two. Homography is derived from the left image to the right image.


Stiching image result.

Source Code

Tuesday, August 6, 2013

Resource to learn optimization

http://www.quora.com/Mathematical-Optimization/What-are-some-good-resources-to-learn-about-optimization#


Theory behind MPC


MPC is based on iterative, finite horizon optimization of a plant model. At time t the current plant state is sampled and a cost minimizing control strategy is computed (via a numerical minimization algorithm) for a relatively short time horizon in the future: [t,t+T]. Specifically, an online or on-the-fly calculation is used to explore state trajectories that emanate from the current state and find (via the solution of Euler-Lagrange equations) a cost-minimizing control strategy until time t+T. Only the first step of the control strategy is implemented, then the plant state is sampled again and the calculations are repeated starting from the current state, yielding a new control and new predicted state path. The prediction horizon keeps being shifted forward and for this reason MPC is also called receding horizon control.

Sunday, May 26, 2013

Hessian Matrix and Jacobian Matrix

Hessian Matrix
In mathematics, the Hessian matrix or Hessian is a square matrix of second-order partial derivatives of a function. It describes the local curvature of a function of many variables. The Hessian matrix was developed in the 19th century by the German mathematician Ludwig Otto Hesse and later named after him. Hesse originally used the term "functional determinants".
Given the real-valued function
f(x_1, x_2, \dots, x_n),\,\!
if all second partial derivatives of f exist and are continuous over the domain of the function, then the Hessian matrix of f is
H(f)_{ij}(\mathbf x) = D_i D_j f(\mathbf x)\,\!
where x = (x1x2, ..., xn) and Di is the differentiation operator with respect to the ith argument. Thus
H(f) = \begin{bmatrix}
\dfrac{\partial^2 f}{\partial x_1^2} & \dfrac{\partial^2 f}{\partial x_1\,\partial x_2} & \cdots & \dfrac{\partial^2 f}{\partial x_1\,\partial x_n} \\[2.2ex]
\dfrac{\partial^2 f}{\partial x_2\,\partial x_1} & \dfrac{\partial^2 f}{\partial x_2^2} & \cdots & \dfrac{\partial^2 f}{\partial x_2\,\partial x_n} \\[2.2ex]
\vdots & \vdots & \ddots & \vdots \\[2.2ex]
\dfrac{\partial^2 f}{\partial x_n\,\partial x_1} & \dfrac{\partial^2 f}{\partial x_n\,\partial x_2} & \cdots & \dfrac{\partial^2 f}{\partial x_n^2}
\end{bmatrix}.
Because f is often clear from context, H(f)(\mathbf x) is frequently abbreviated to H(\mathbf x).
The Hessian matrix is related to the Jacobian matrix by H(f)(\mathbf x) = J(\nabla \! f)(\mathbf x).
The determinant of the above matrix is also sometimes referred to as the Hessian.[1]
Hessian matrices are used in large-scale optimization problems within Newton-type methods because they are the coefficient of the quadratic term of a local Taylor expansion of a function. That is,
y=f(\mathbf{x}+\Delta\mathbf{x})\approx f(\mathbf{x}) + J(\mathbf{x})\Delta \mathbf{x} +\frac{1}{2} \Delta\mathbf{x}^\mathrm{T} H(\mathbf{x}) \Delta\mathbf{x}
where J is the Jacobian matrix, which is a vector (the gradient) for scalar-valued functions. The full Hessian matrix can be difficult to compute in practice; in such situations, quasi-Newton algorithms have been developed that use approximations to the Hessian. The best-known quasi-Newton algorithm is the BFGS algorithm
Jacobian Matrix

In vector calculus, the Jacobian matrix is the matrix of all first-order partial derivatives of a vector-valued function. Specifically, suppose F : \mathbb{R}^n \rightarrow \mathbb{R}^m is a function (which takes as input real n-tuples and produces as output real m-tuples). Such a function is given by m real-valued component functions, F_1(x_1,\ldots,x_n),\ldots,F_m(x_1,\ldots,x_n). The partial derivatives of all these functions with respect to the variables x_1,\ldots,x_n (if they exist) can be organized in an m-by-n matrix, the Jacobian matrix J of F, as follows:
J=\begin{bmatrix} \dfrac{\partial F_1}{\partial x_1} & \cdots & \dfrac{\partial F_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \dfrac{\partial F_m}{\partial x_1} & \cdots & \dfrac{\partial F_m}{\partial x_n}  \end{bmatrix}.


Friday, May 3, 2013

Implementation of KalmanFilter in Opencv

Two Functions used: gemm , solve
gemm: Performs generalized matrix multiplication.
C++: void gemm(InputArray src1, InputArray src2, double alpha, InputArray src3, double gamma, OutputArray dst, intflags=0 )
The function performs generalized matrix multiplication similar to the gemm functions in BLAS level 3. For example, gemm(src1,src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T) corresponds to
\texttt{dst} =  \texttt{alpha} \cdot \texttt{src1} ^T  \cdot \texttt{src2} +  \texttt{beta} \cdot \texttt{src3} ^T

solve: Solves one or more linear systems or least-squares problems.
C++: bool solve(InputArray src1, InputArray src2, OutputArray dst, int flags=DECOMP_LU)
  • solution (matrix inversion) method.
    • DECOMP_LU Gaussian elimination with optimal pivot element chosen.
    • DECOMP_CHOLESKY Cholesky LL^T factorization; the matrix src1 must be symmetrical and positively defined.
    • DECOMP_EIG eigenvalue decomposition; the matrix src1 must be symmetrical.
    • DECOMP_SVD singular value decomposition (SVD) method; the system can be over-defined and/or the matrix src1 can be singular.
    • DECOMP_QR QR factorization; the system can be over-defined and/or the matrix src1 can be singular.
    • DECOMP_NORMAL while all the previous flags are mutually exclusive, this flag can be used together with any of the previous; it means that the normal equations\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2} are solved instead of the original system \texttt{src1}\cdot\texttt{dst}=\texttt{src2} .
The function solve solves a linear system or least-squares problem (the latter is possible with SVD or QR methods, or by specifying the flag DECOMP_NORMAL ):
\texttt{dst} =  \arg \min _X \| \texttt{src1} \cdot \texttt{X} -  \texttt{src2} \|

OpenCV: Surf Matching in Video Sequence

OpenCV: SURF Feature matching

  1. Load two images
  2. do SURF feature extraction
  3. Using Flann matching to match the keypoints
  4. Identify good matches
  5. find the object in the scene image

Wednesday, May 1, 2013

OpenCV: SURF Feature extractor

Main steps:
  1. Read Two Images
  2. Resize to half of its size
  3. Detectect Keypoints  using SURF
  4. Calculate Feature Descriptor
  5. Matching Descriptor using Brute Force Matcher
Original Image
 SURF Keypoints
SURF Matches


Sunday, April 28, 2013

Surf Detector

OpenCV Sobel edge detector

Orignal

Sobel X Gradient

Sobel Y Gradient

Sobel Gradient

OpenCV Tutorial 1: Mat - The basic Image Container


Color Space In OpenCV
There are, however, many other color systems each with their own advantages:
  • RGB is the most common as our eyes use something similar, our display systems also compose colors using these.
  • The HSV and HLS decompose colors into their hue, saturation and value/luminance components, which is a more natural way for us to describe colors. You might, for example, dismiss the last component, making your algorithm less sensible to the light conditions of the input image.
  • YCrCb is used by the popular JPEG image format.
  • CIE L*a*b* is a perceptually uniform color space, which comes handy if you need to measure the distance of a given color to another color.
Sample Code

Tuesday, April 16, 2013

Camera Calibration tool box from Caltech

http://www.vision.caltech.edu/bouguetj/calib_doc/
This is a release of a Camera Calibration Toolbox for Matlab® with a complete documentation. This document may also be used as a tutorial on camera calibration since it includes general information about calibration, references and related links.