-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Equivalent of c++ std::vector<cv::Vec6f> in java with javacv? #913
Comments
Would you have some sample code in C++ that you are trying to translate to Java?
|
Hi @saudet , here is the code: cv::Subdiv2D subdiv(rect); //rect is a cv::Rect
// Insert points into subdiv (points is a vector<cv::Point2f>)
for (size_t i = 0; i < points.size(); ++i)
subdiv.insert(points[i]);
//getting the triangles from subdiv
vector<cv::Vec6f> triangleList;
subdiv.getTriangleList(triangleList); |
Something like this should work then: FloatPointer triangleList = new FloatPointer(null);
subdiv.getTriangleList(triangleList);
int n = triangleList.limit() / 6;
... Could you give it a try? |
It seems to work, here is my code: FloatBuffer buffer = null;
FloatPointer triangleList = new FloatPointer(buffer);
subdiv2D.getTriangleList(triangleList);
long n = triangleList.limit() * 6;
for (int i = 0; i < n; i++)
float f = triangleList.get(i); //points coordinate I only changed few things like: FloatPointer triangleList = new FloatPointer(null);
//to
FloatPointer triangleList = new FloatPointer(buffer);
//to avoid: Cannot resolve constructor: FloatPointer(null); ERROR
//and
int n = triangleList.limit() / 6; //number of triangles
//to
long n = triangleList.limit() * 6; //all points coordinate (that is what i need :D ) So, thanks again @saudet for your help!! |
Hum, ok, so the number of points doesn't come out right with that hack. We'll need to do something about that. Thanks for reporting! |
Thank you sir! //really strange, upper bound should not exceed triangleList.limit() * 6
long n = triangleList.limit() * 6 * 10;
//getting coordinate
for (int i = 0; i < n; i += 2) {
float x = triangleList.get(i);
float y = triangleList.get(i + 1);
} When But when Note that the right x and y are between 100 and 500. Is this normal or caused by some memory inconsistencies or some algorithmic bugs of cv::Subdiv2D? |
FloatPointer doesn't do bounds checking, that's normal.
|
…ubdiv2D` from `opencv_imgproc` (issues bytedeco/javacv#913 and bytedeco/javacv#1146)
This has now been fixed with JavaCV 1.5, which provides a nice |
Hi, I'm trying to use the Subdiv2D (from opencv_imgproc) class to perform the Delaunay triangulation.
I need to call the
getTriangleList(FloatPointer)
method, but it need a FloatPointer object as parameter.From Opencv documentation, the method getTriangleList need a
std::vector<cv::Vec6f>
as parameter.How can i achieve the same in java with javacv?
The text was updated successfully, but these errors were encountered: