Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );

vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );

I tried Converting it based on my knowledge and here is what I got:

     Mat src= new Mat();
    Utils.bitmapToMat(bitmap, src);
    Mat original = src.clone();
    Mat gray = new Mat();
    Mat mask = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.blur(gray, gray, new Size(3, 3));

    //Canny giving a warning only 4 parameters
    //are needed
    Imgproc.Canny(gray, mask, 100, 300, 3);

    //I do not know how to deal with this
    vector<Point> contours;
    vector<Point> convexHull_pts;

    Core.findNonZero(mask, contours);
    Imgproc.convexHull(contours, convexHull_pts);
    Imgproc.fillConvexPoly(mask, convexHull_pts, Scalar(255));

vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );
vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

I tried Converting it based on my knowledge and here is what I got:

     Mat src= new Mat();
    Utils.bitmapToMat(bitmap, src);
    Mat original = src.clone();
    Mat gray = new Mat();
    Mat mask = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.blur(gray, gray, new Size(3, 3));

    //Canny giving a warning only 4 parameters
    //are needed
    Imgproc.Canny(gray, mask, 100, 300, 3);

    //I do not know how to deal with this
    vector<Point> contours;
    vector<Point> convexHull_pts;

    Core.findNonZero(mask, contours);
    Imgproc.convexHull(contours, convexHull_pts);
    Imgproc.fillConvexPoly(mask, convexHull_pts, Scalar(255));

vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );
vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

I tried Converting it based on my knowledge and here is what I got:

     Mat src= new Mat();
    Utils.bitmapToMat(bitmap, src);
    Mat original = src.clone();
    Mat gray = new Mat();
    Mat mask = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.blur(gray, gray, new Size(3, 3));

    //Canny giving a warning only 4 parameters
    //are needed
    Imgproc.Canny(gray, mask, 100, 300, 3);

    //I do not know how to deal with this
    vector<Point> contours;
    vector<Point> convexHull_pts;
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    List<MatOfPoint> convexHull_pts = new ArrayList<MatOfPoint>();

    Core.findNonZero(mask, contours);
    Imgproc.convexHull(contours, convexHull_pts);
    Imgproc.fillConvexPoly(mask, convexHull_pts, Scalar(255));
Imgproc.Scalar(255));

Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );
vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

I tried Converting it based on my knowledge and here is what I got:

     Mat src= new Mat();
    Utils.bitmapToMat(bitmap, src);
    Mat original = src.clone();
    Mat gray = new Mat();
    Mat mask = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.blur(gray, gray, new Size(3, 3));

    Imgproc.Canny(gray, mask, 100, 300, 3);

    List<MatOfPoint> MatOfPoint contours = new ArrayList<MatOfPoint>();
    List<MatOfPoint> MatOfPoint(); // i am not sure ( blind suggestion )
    MatOfPoint convexHull_pts = new ArrayList<MatOfPoint>();
MatOfPoint();

    Core.findNonZero(mask, contours);
    Imgproc.convexHull(contours, convexHull_pts);
    Imgproc.fillConvexPoly(mask, convexHull_pts, Imgproc.Scalar(255));

Converting C++ code to java

I am new to both OpenCv and Java, I have been doing a bit of reading and research on how I can perform a background subtraction and thanks to sturkmen I have a piece of code that actually works, except it is in C== and my enviroment is Java, I could have converted the code but there is a few challenging thing, Like in Java Canny only has 4 parameters so its a bit of a challenge for me, here is the code:

Mat src= imread( argv[1] );
Mat original = src.clone();
Mat gray,mask;
cvtColor( src, gray, COLOR_BGR2GRAY );
blur( gray, gray, Size(3,3) );
Canny( gray, mask, 100, 300, 3 );
vector<Point> contours;
vector<Point> convexHull_pts;
findNonZero( mask, contours );

convexHull( contours, convexHull_pts);
fillConvexPoly( mask, convexHull_pts, Scalar(255) );

I tried Converting it based on my knowledge and here is what I got:

     Mat src= new Mat();
    Utils.bitmapToMat(bitmap, src);
    Mat original = src.clone();
    Mat gray = new Mat();
    Mat mask = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.blur(gray, gray, new Size(3, 3));

    Imgproc.Canny(gray, mask, 100, 300, 3);

    MatOfPoint contours = new MatOfPoint(); // i am not sure how to initialize MatOfPoint ( blind suggestion )
    MatOfPoint convexHull_pts = new MatOfPoint();

    Core.findNonZero(mask, contours);
    Imgproc.convexHull(contours, convexHull_pts);
    Imgproc.fillConvexPoly(mask, convexHull_pts, Imgproc.Scalar(255));