for Robot Artificial Inteligence

Vector Normalization(Covariance Matrix, mass points)

|

정규화란 무언가를 표준화 시키거나 다른 것과 비교하기 쉽도록 바꾸는 것을 의미합니다

Vector Normalization는 벡터에 대한 크기를 구하는 것이다.

벡터에 대한 크기를 가지고 우리는 특정 데이터를 표준화 할 수 있기 때문에 좀더 정확한 데이터 처리에 대한 결과를 얻을 수 있다.

데이터에 대한 표준화를 하지 않는다면 연산량과 데이터에 대한 튀는 값이 발생할 수 있기 떄문에 표준화 작업이 필요하다.

즉, normalization을 한다는 것은 크기를 구하여서 표준화 작업을 하겠다라고 이해하면 좋겠다.

예제로 Covariance Matrix를 구할때 Normalization Covariance(Mass points -> vector between masspoints and point -> distance += norm(normal vector) -> avg_distance = distance/number of points - > ratio = sqrt(2)/avg_distance -> each point *= ratio -> build covarinace matrix -> SVD(PCA) -> eigen vector and eigen value -> scale = norm(eigen vector -> eigen vactor = eigen_vector/norm)

Normalization intuition

covariance normalization 관련 코드

// Apply Least-Squares plane fitting
void FitPlaneLSQ(MatrixReaderWriter& mrw,
	vector<int>& inliers,
	Mat& plane)
{
	vector<Point3d> normalizedPoints;
	normalizedPoints.reserve(inliers.size());

	// Calculating the mass point of the points
	Point3d masspoint(0, 0, 0);

	for (const auto& inlierIdx : inliers)
	{
		Point3d p;
		p.x = mrw.data[mrw.columnNum * inlierIdx];
		p.y = mrw.data[mrw.columnNum * inlierIdx + 1];
		p.z = mrw.data[mrw.columnNum * inlierIdx + 2];
		masspoint += p;
		normalizedPoints.emplace_back(p);
	}
	masspoint = masspoint * (1.0 / inliers.size());

	// Move the point cloud to have the origin in their mass point
	for (auto& point : normalizedPoints)
		point -= masspoint;

	// Calculating the average distance from the origin
	double averageDistance = 0.0;
	for (auto& point : normalizedPoints)
	{
		averageDistance += cv::norm(point);
		// norm(point) = sqrt(point.x * point.x + point.y * point.y + point.z * point.z)
	}

	averageDistance /= normalizedPoints.size();
	const double ratio = sqrt(2) / averageDistance;

	// Making the average distance to be sqrt(2)
	for (auto& point : normalizedPoints)
		point *= ratio;

	// Now, we should solve the equation.
	cv::Mat A(normalizedPoints.size(), 3, CV_64F);

	// Building the coefficient matrix
	for (size_t pointIdx = 0; pointIdx < normalizedPoints.size(); ++pointIdx)
	{
		const size_t& rowIdx = pointIdx;

		A.at<double>(rowIdx, 0) = normalizedPoints[pointIdx].x;
		A.at<double>(rowIdx, 1) = normalizedPoints[pointIdx].y;
		A.at<double>(rowIdx, 2) = normalizedPoints[pointIdx].z;
	}

	cv::Mat evals, evecs;
	cv::eigen(A.t() * A, evals, evecs);
	const cv::Mat& normal = evecs.row(2); // the normal of the line is the eigenvector corresponding to the smallest eigenvalue
	const double& a = normal.at<double>(0),
		& b = normal.at<double>(1),
		& c = normal.at<double>(2);
	Point3d normalP(a, b, c);
	const double d = -normalP.ddot(masspoint);

	plane.at<double>(0) = a;
	plane.at<double>(1) = b;
	plane.at<double>(2) = c;
	plane.at<double>(3) = d;
}

Comment  Read more

Sequential quadratic programming(Gradient Newton, LM, etc)

|

Sequential quadratic programming (SQP : 비선형 최적화 알고리즘) is an iterative method for constrained nonlinear optimization. SQP methods are used on mathematical problems for which the objective function and the constraints are twice continuously differentiable.

SQP methods solve a sequence of optimization subproblems, each of which optimizes a quadratic model of the objective subject to a linearization of the constraints. If the problem is unconstrained, then the method reduces to Newton’s method for finding a point where the gradient of the objective vanishes. If the problem has only equality constraints, then the method is equivalent to applying Newton’s method to the first-order optimality conditions, or Karush–Kuhn–Tucker conditions, of the problem.

Sequential quadratic programming 문제를 푸는 것은 GM, LM과 같은 여러 방법들이 있다.

**블로그에 Non Linear Least Square 검색하여서 GM과 LM에 더 구체적으로 이해할 수 있다.

Comment  Read more

PCA and SDV Difference

|

Principal Component Analysis, or PCA, is a well-known and widely used technique applicable to a wide variety of applications such as dimensionality reduction, data compression, feature extraction, and visualization. The basic idea is to project a dataset from many correlated coordinates onto fewer uncorrelated coordinates called principal components while still retaining most of the variability present in the data.

Singular Value Decomposition, or SVD, is a computational method often employed to calculate principal components for a dataset. Using SVD to perform PCA is efficient and numerically robust. Moreover, the intimate relationship between them can guide our intuition about what PCA actually does and help us gain additional insights into this technique.

한국어 설명

Well Known about between PCA and SDV Difference

위에 말을 따르면 SVD는 PCA의 Application일종이다.

즉, 목적은 covariance Matrix에 대해 Matrix Decomposition을하여 EigenVector와 EigenValue를 구하는 것이고 PCA는 말 그대로 egienvalue가 높은 eigenvector들을 가지고 주성분(기저)로 normal surface, plane or line parameter, rotation matrix 등 다양한 분야에서 사용할수 있다.

Comment  Read more

NDT(Normal Distribution tranform)

|

NDT step

(1)用第一帧laser scan,按照上述过程计算初始NDT分布

(2)初始化位姿变换参数T,全零或者用odometry初始化

(3)根据位姿变换参数T,将第二帧的laser scan点云转换到第一帧坐标系下

(4)为第二帧的每个2D点分配网格,计算点云对应的四种概率分布

(5)累计点云的概率分布,计算总体得分

https://blog.csdn.net/jinshengtao/article/details/103828230

Comment  Read more

EightPoints Algorithm(To find Essential Matrix and fundamental Matrix)

|

the EightPoint Algorithm is an algorithm used in computer vision to estimate the Essential matrix or the fundamental matrix related to a stereo camera from a set of corresponding image point.

use Sequence Quadratic Program(Gradient Newton, LM …) to solve unknown variable(Essential Matrix’s element) iterately.

eightpoints is selected by RANSAC

STEP

  1. image feature extraction
  2. image feature matching(KNN)
  3. use ransac outlier image feature matching’s result
  4. use ransac to find essential matrix and fundamental matrix with eight point algorithm.
  5. now with eesstianl matrix and intrinsic parameter to make fundamental matrix.
  6. and with fundamental matrix, using SVD to get Relative rotation Matrix and Traslation.(initialize pose)
  7. now we can generate 3d triangulation point by them
  8. and do PnP solve(3d - 2d) next camera pose estimation and literately generate 3d triangulation point(creating map) until camera frame no longer exist

Reference

https://www.quora.com/Computer-Vision-What-is-the-difference-between-the-essential-matrix-and-the-fundamental-matrix

https://www.baidu.com/from=844b/s?word=essential+matrix+c%2B%2B&sa=tb&ts=9943862&t_kt=0&ie=utf-8&rsv_t=c6b9XlTmpQPfwQGN%252BwmWZENzj0Tikfj9D2s6z%252BCpYp13qJVswX7UAlr6NA&ms=1&rsv_pq=12478331738706715542&ss=&rqlang=zh&oq=essential%2Bmatrix%E6%B1%82%E8%A7%A3

Comment  Read more