Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Whenever i use Imgproc.rectangle function following error appears

This is code i use

public Mat retContours(Mat pointMatHsv) { List<matofpoint> contours = new ArrayList<matofpoint>(); List<matofpoint> mContours = new ArrayList<matofpoint>(); Imgproc.findContours(pointMatHsv, contours, heirarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); double maxArea = 0; Iterator<matofpoint> each = contours.iterator(); while (each.hasNext()) { MatOfPoint wrapper = each.next(); double area = Imgproc.contourArea(wrapper); if (area > maxArea) maxArea = area; }

    mContours.clear();
    each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint contour = each.next();
        if (Imgproc.contourArea(contour) > mMinContourArea * maxArea) {
           // Core.multiply(contour, new Scalar(4, 4), contour);
            mContours.add(contour);

        }
    }
    Imgproc.drawContours(pointMatHsv, mContours, -1, CONTOUR_COLOR);
    MatOfPoint2f         approxCurve = new MatOfPoint2f();

    //For each contour found
    for (int i=0; i<mContours.size(); i++)
    {
        //Convert contours(i) from MatOfPoint to MatOfPoint2f
        MatOfPoint2f contour2f = new MatOfPoint2f( mContours.get(i).toArray() );
        //Processing on mMOP2f1 which is in type MatOfPoint2f
        double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
        Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

        //Convert back to MatOfPoint
        MatOfPoint points = new MatOfPoint( approxCurve.toArray() );

        // Get bounding rect of contour
        Rect rect = Imgproc.boundingRect(points);

        // draw enclosing rectangle (all same color, but you could use variable i to make them unique)
        Imgproc.rectangle(pointMatHsv, rect.tl(), rect.br(), new Scalar(255,0,0), 1, 8,0);

    }

    Imgproc.rectangle(pointMatHsv,new Point(150.0,150.0),new Point(250.0,250.0),CONTOUR_COLOR);

this is the error i get

02-01 23:38:08.459 24758-24885/org.opencv.samples.tutorial1 E/art﹕ No implementation found for void org.opencv.imgproc.Imgproc.rectangle_2(long, double, double, double, double, double, double, double, double) (tried Java_org_opencv_imgproc_Imgproc_rectangle_12 and Java_org_opencv_imgproc_Imgproc_rectangle_12__JDDDDDDDD) 02-01 23:38:08.460 24758-24885/org.opencv.samples.tutorial1 E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-3512 Process: org.opencv.samples.tutorial1, PID: 24758 java.lang.UnsatisfiedLinkError: No implementation found for void org.opencv.imgproc.Imgproc.rectangle_2(long, double, double, double, double, double, double, double, double) (tried Java_org_opencv_imgproc_Imgproc_rectangle_12 and Java_org_opencv_imgproc_Imgproc_rectangle_12__JDDDDDDDD) at org.opencv.imgproc.Imgproc.rectangle_2(Native Method) at org.opencv.imgproc.Imgproc.rectangle(Imgproc.java:2788) at org.opencv.samples.tutorial1.Tutorial1Activity.retContours(Tutorial1Activity.java:185) at org.opencv.samples.tutorial1.Tutorial1Activity.onCameraFrame(Tutorial1Activity.java:134) at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:393) at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:346) at java.lang.Thread.run(Thread.java:818)

Whenever i use Imgproc.rectangle and Imgproc.circle function following error appears

This is code i usepackage org.opencv.samples.tutorial1;

import org.opencv.android.BaseLoaderCallback; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.*; //import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc;

import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.MotionEvent; import android.view.SurfaceView; import android.view.View; import android.view.View.OnTouchListener; import android.view.WindowManager;

import com.example.imgloader.R;

import java.util.ArrayList; import java.util.Iterator; import java.util.List;

public class Tutorial1Activity extends Activity implements CvCameraViewListener2 {

private static final String TAG = "OCVSample::Activity";
private Mat mRgba;
private Mat mGray;

private CameraBridgeViewBase mOpenCvCameraView;
Scalar min = new Scalar(0, 30, 60, 0);
Scalar max = new Scalar(20, 150, 255, 0);
Mat pointMatHsv;
Mat heirarchy;
Mat overlay;

private static double mMinContourArea = 0.1;
Mat hullMat;


Scalar CONTOUR_COLOR = new Scalar(255, 0, 0, 255);


private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS: {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();

            }
            break;
            default: {
                super.onManagerConnected(status);
            }
            break;
        }
    }
};

public Tutorial1Activity() {
    Log.i(TAG, "Instantiated new " + this.getClass());
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.tutorial1_surface_view);

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);
    mOpenCvCameraView.setMaxFrameSize(720, 480);

    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

    mOpenCvCameraView.setCvCameraViewListener(this);
}

@Override
public void onPause() {
    super.onPause();
    if (mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}

@Override
public void onResume() {
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
}

public void onDestroy() {
    super.onDestroy();
    if (mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}


public void onCameraViewStarted(int width, int height) {
    mGray = new Mat();
    mRgba = new Mat();
    pointMatHsv = new Mat(1, 1, CvType.CV_8UC3);
    heirarchy = new Mat();
    overlay = new Mat(1,1, CvType.CV_8UC3);




}

public void onCameraViewStopped() {
}

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

    Scalar CONTOUR_COLOR = new Scalar(255, 0, 0, 255);
    Imgproc.cvtColor(pointMatHsv, mGray, Imgproc.COLOR_RGB2HSV);
    Core.inRange(mGray, min, max, pointMatHsv);
    Imgproc.dilate(pointMatHsv, pointMatHsv, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));
    //Imgproc.dilate(mRgba, mRgba, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));
    Imgproc.erode(pointMatHsv, pointMatHsv, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));




    mGray = retContours(pointMatHsv,mRgba);

    return mRgba;
}

public Mat retContours(Mat pointMatHsv) {
        List<matofpoint> pointMatHsv, Mat mRgba) {
    List<MatOfPoint> contours = new ArrayList<matofpoint>();
        List<matofpoint> ArrayList<MatOfPoint>();
    List<MatOfPoint> mContours = new ArrayList<matofpoint>();
    ArrayList<MatOfPoint>();
    Imgproc.findContours(pointMatHsv, contours, heirarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
      double maxArea = 0;
        Iterator<matofpoint> Iterator<MatOfPoint> each = contours.iterator();
     while (each.hasNext()) {
         MatOfPoint wrapper = each.next();
         double area = Imgproc.contourArea(wrapper);
         if (area > maxArea)
             maxArea = area;
        }

}
   // Imgproc.cvtColor(pointMatHsv,pointMatHsv,Imgproc.COLOR_HSV2RGB_FULL);

    mContours.clear();
    each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint contour = each.next();
        if (Imgproc.contourArea(contour) > mMinContourArea * maxArea) {
           // Core.multiply(contour, new Scalar(4, 4), contour);
            mContours.add(contour);

        }
    }
    Imgproc.drawContours(pointMatHsv, mContours, -1, CONTOUR_COLOR);
    MatOfPoint2f         approxCurve = new MatOfPoint2f();

    //For each contour found
Imgproc.drawContours(mRgba,mContours,-1,new Scalar(0, 255, 0));

    for(int i=0;i<mContours.size();i++) {
        MatOfPoint currentContour = mContours.get(i);
        drawConvexHull(currentContour);
        drawBoundingBox(currentContour);
        drawEnclosingCircle(currentContour);

    }





   return mRgba;

}
private void drawConvexHull(MatOfPoint currentContour) {
    MatOfInt hull = new MatOfInt();
    Imgproc.convexHull(currentContour, hull);

    List<MatOfPoint> hullContours = new ArrayList<MatOfPoint>();
    MatOfPoint hullMat = new MatOfPoint();
    hullMat.create((int) hull.size().height, 1, CvType.CV_32SC2);

    for (int i=0; i<mContours.size(); i++)
    {
        //Convert contours(i) from MatOfPoint to MatOfPoint2f
    j = 0; j < hull.size().height; j++) {
        int index = (int) hull.get(j, 0)[0];
        double[] point = new double[]{
                currentContour.get(index, 0)[0], currentContour.get(index, 0)[1]
        };
        hullMat.put(j, 0, point);
    }
    hullContours.add(hullMat);
    Imgproc.drawContours(mRgba, hullContours, 0, new Scalar(0, 0, 255), 2);
}
private void drawBoundingBox(MatOfPoint currentContour) {
    Rect rectangle =  Imgproc.boundingRect(currentContour);
    Imgproc.rectangle(mRgba, rectangle.tl(), rectangle.br(), new Scalar(255,0,0),1);

}
private void drawEnclosingCircle(MatOfPoint currentContour) {
    float[] radius = new float[1];
    Point center = new Point();
    MatOfPoint2f contour2f = new MatOfPoint2f( mContours.get(i).toArray() );
        //Processing on mMOP2f1 which is in type MatOfPoint2f
        double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
        Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

        //Convert back to MatOfPoint
        MatOfPoint points = new MatOfPoint( approxCurve.toArray() );

        // Get bounding rect of contour
        Rect rect = Imgproc.boundingRect(points);

        // draw enclosing rectangle (all same color, but you could use variable i to make them unique)
        Imgproc.rectangle(pointMatHsv, rect.tl(), rect.br(), new Scalar(255,0,0), 1, 8,0);

    }

    Imgproc.rectangle(pointMatHsv,new Point(150.0,150.0),new Point(250.0,250.0),CONTOUR_COLOR);
currentContour2f = new MatOfPoint2f();
    currentContour.convertTo(currentContour2f, CvType.CV_32FC2);
    Imgproc.minEnclosingCircle(currentContour2f, center, radius);
    Imgproc.circle(mRgba, center, (int) radius[0], new Scalar(255,0,0));
}

}

and this error is the error i getthrown

02-01 23:38:08.459 24758-24885/org.opencv.samples.tutorial1 02-03 19:20:05.338 29021-29113/org.opencv.samples.tutorial1 E/art﹕ No implementation found for void org.opencv.imgproc.Imgproc.rectangle_2(long, double, double, double, double, double, double, double, double) org.opencv.imgproc.Imgproc.rectangle_1(long, double, double, double, double, double, double, double, double, int) (tried Java_org_opencv_imgproc_Imgproc_rectangle_12 Java_org_opencv_imgproc_Imgproc_rectangle_11 and Java_org_opencv_imgproc_Imgproc_rectangle_12__JDDDDDDDD) 02-01 23:38:08.460 24758-24885/org.opencv.samples.tutorial1 Java_org_opencv_imgproc_Imgproc_rectangle_11__JDDDDDDDDI) 02-03 19:20:05.339 29021-29113/org.opencv.samples.tutorial1 E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-3512 Thread-8072 Process: org.opencv.samples.tutorial1, PID: 24758 29021 java.lang.UnsatisfiedLinkError: No implementation found for void org.opencv.imgproc.Imgproc.rectangle_2(long, double, double, double, double, double, double, double, double) org.opencv.imgproc.Imgproc.rectangle_1(long, double, double, double, double, double, double, double, double, int) (tried Java_org_opencv_imgproc_Imgproc_rectangle_12 Java_org_opencv_imgproc_Imgproc_rectangle_11 and Java_org_opencv_imgproc_Imgproc_rectangle_12__JDDDDDDDD) Java_org_opencv_imgproc_Imgproc_rectangle_11__JDDDDDDDDI) at org.opencv.imgproc.Imgproc.rectangle_2(Native org.opencv.imgproc.Imgproc.rectangle_1(Native Method) at org.opencv.imgproc.Imgproc.rectangle(Imgproc.java:2788) org.opencv.imgproc.Imgproc.rectangle(Imgproc.java:2779) at org.opencv.samples.tutorial1.Tutorial1Activity.retContours(Tutorial1Activity.java:185) org.opencv.samples.tutorial1.Tutorial1Activity.drawBoundingBox(Tutorial1Activity.java:204) at org.opencv.samples.tutorial1.Tutorial1Activity.onCameraFrame(Tutorial1Activity.java:134) org.opencv.samples.tutorial1.Tutorial1Activity.retContours(Tutorial1Activity.java:172) at org.opencv.samples.tutorial1.Tutorial1Activity.onCameraFrame(Tutorial1Activity.java:137) at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:393) at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:346) at java.lang.Thread.run(Thread.java:818)java.lang.Thread.run(Thread.java:818) 02-03 19:20:05.359 29021-29021/org.opencv.samples.tutorial1 D/Java