Passing OpenCV contours from a JNI C++ function to Java in Android -
what best way pass opencv vector< std::vector<point > > contours
jni c++ function java in android? current approach use arrays of doubles inefficient. there way use pointers maybe?
here's efficient way access contours wrapper javacpp presets opencv:
import org.bytedeco.javacpp.indexer.*; import static org.bytedeco.javacpp.opencv_core.*; import static org.bytedeco.javacpp.opencv_imgproc.*; import static org.bytedeco.javacpp.opencv_highgui.*; public class contours { public static void main(string[] args) { mat grayscaleimage = imread("lena.png", cv_load_image_grayscale); mat binarizedimage = new mat(); matvector contours = new matvector(); threshold(grayscaleimage, binarizedimage, 128, 255, thresh_binary); findcontours(binarizedimage, contours, retr_list, chain_approx_none); int contourssize = (int)contours.size(); system.out.println("size = " + contourssize); (int contouridx = 0; contouridx < contourssize; contouridx++) { // compute center float x = 0, y = 0; mat contour = contours.get(contouridx); intindexer points = contour.createindexer(false); int pointssize = contour.rows(); (int pointidx = 0; pointidx < pointssize; pointidx++) { x += points.get(pointidx, 0); y += points.get(pointidx, 1); } system.out.println("center = (" + x / pointssize + ", " + y / pointssize + ")"); } } }
for simplicity, i'm using java se, can same thing on android.
Comments
Post a Comment