如何用Java中的OpenCV Mat表示双元素向量? [英] How are two-element vector represented in a OpenCV Mat in Java?

查看:412
本文介绍了如何用Java中的OpenCV Mat表示双元素向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看 Hough Transform的Opencv Java文档

返回值 Mat 数据类型中描述为:

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


行的输出向量。每行由两元素
向量(rho,theta)表示。 rho是坐标原点的距离
(0,0)(图像的左上角)。 theta是以弧度表示的线旋转角度
(0~垂直线,pi / 2~水平线)。

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).

好奇地,此描述符合 C ++界面的说明数据类型不是:在C ++中你可以使用 std :: vector< cv :: Vec2f>行,如本教程。在C ++中,给定描述的返回数据表示很简单,但在Java中没有。

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.

因此,在Java中,如何表示/存储双元素向量返回的Mat?

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

推荐答案

以下是我之前使用过的一些代码,我认为是版本2.4.8。 matLines 来自:

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];
   //...
}

这篇关于如何用Java中的OpenCV Mat表示双元素向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆