Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are two-element vector represented in a OpenCV Mat in Java?

I was looking at Opencv Java documentation of Hough Transform.

The return value lines is in a Mat data type described as:

Output vector of lines. Each line is represented by a two-element vector (rho, theta). rho is the distance from the coordinate origin (0,0) (top-left corner of the image). theta is the line rotation angle in radians (0 ~ vertical line, pi/2 ~ horizontal line).

Curiously, this description matches the C++ interface's description, but the data type not: in C++ you can use a std::vector<cv::Vec2f> lines as described in this tutorial. In C++ the returned data representation, given the description, is straightforward, but in Java not.

So, in Java, how are the two-element vector represented/stored in the returned Mat?

like image 817
Antonio Avatar asked Apr 08 '15 14:04

Antonio


People also ask

What is mat in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

What does MAT mean in Java?

Mat(Size size, int type) − This constructor accepts two parameters, an object representing the size of the matrix and an integer representing the type of the array used to store the data.

What is cv_64f?

Here's example for CV_64FC1 : CV_ - this is just a prefix. 64 - number of bits per base matrix element (e.g. pixel value in grayscale image or single color element in BGR image) F - type of the base element. In this case it's F for float, but can also be S (signed) or U (unsigned)

What is Mat CPP?

Mat is basically a class with two data parts : the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for ...


1 Answers

Here's some code I used a while ago, in version 2.4.8 I think. matLines came from this:

Imgproc.HoughLinesP(matOutline, matLines, 1, Math.PI / 180, houghThreshCurrent, houghMinLength, houghMaxGap);

...

Point[] points = new Point[]{ new Point(), new Point() };
for (int x = 0; x < matLines.cols(); x++) {
   double[] vec = matLines.get(0, x);
   points[0].x = vec[0];
   points[0].y = vec[1];
   points[1].x = vec[2];
   points[1].y = vec[3];
   //...
}
like image 59
medloh Avatar answered Oct 27 '22 15:10

medloh