问题
I'm new to OpenCV and Android. I'm tring to covert a C++ code to java
line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
this is the last part of it. Here, I replaced line with Core.line()
But now problem is adding these 2 points in the above code.
scene_corners[0] + Point2f( img_object.cols, 0)
I replaced (scene_corners[0],Point2f( img_object.cols, 0)) with
scene_corners.get(0),new Point(img_object.cols(),0)
Since both are org.opencv.core.Point type objects, these types of operations are not supported. Any way to convert this. Please help me. Thank you in advance.
回答1:
The first thing to note is that the second and third parameters to Core.line must be points.
In your replacement, you removed the addition symbol (+). Hmm. I don't think you can do that if you are converting the code line for line.
The get method appears to return a Point, but you'll need to print the object out to make sure or just look at the variable definition for scene_corners. Use this to try printing it out:
System.out.println(scene_corners.get(0));
If it's a Point object, then you can add it to your point by taking each component of the Point and adding it to the corresponding component in the added to Point. Assume Point A and B with components 0 and 1.
P(A) + P(B) = P(A0+B0, A1+B1)
Here, I am assuming that scene_corners.get(0) has x and y properties:
line(
img_matches,
new Point(
img_object.cols() + scene_corners.get(0).x,
0 + scene_corners.get(0).y),
new Point(
img_object.cols() + scene_corners.get(1).x,
0 + scene_corners.get(1).y),
Scalar(0, 255, 0),
4
);
来源:https://stackoverflow.com/questions/18975813/how-to-add-2-org-opencv-core-point-objects-in-android