Ask Your Question

Revision history [back]

Opencv(3.10) android- How to draw an object's trajectory

I have a project in college where I have to draw the trajectory of an object based on the color of it. Is being built based on colorBlobDetection. This is part of the code I have so far:

 public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();

if (mIsColorSelected) {
    mDetector.process(mRgba);
    List<MatOfPoint> contours = mDetector.getContours();
    Log.e(TAG, "Contours count: " + contours.size());
    Imgproc.drawContours(mRgba, contours, -1, CONTOUR_COLOR);

    List<Moments> mu = new ArrayList<Moments>(contours.size());

    for (int i = 0; i < contours.size(); i++) {
        mu.add(i, Imgproc.moments(contours.get(i), false));
        Moments p = mu.get(i);
        int xContour = (int) (p.get_m10() / p.get_m00());
        int yContour = (int) (p.get_m01() / p.get_m00());
        Point ponto = new Point(xContour, yContour);
        //Imgproc.line(mRgba, ponto, ponto, CONTOUR_COLOR, 5, Imgproc.LINE_AA, 0);
    }

At the moment I'm picking up the center of each contour.

Through the positions of the contours I want to draw their trajectories when they move

Ps. This 'Imgproc.line' was just to test if the center of each contour is correct.

Please help.