Ask Your Question

mrfazolka's profile - activity

2014-11-06 10:24:57 -0500 received badge  Necromancer (source)
2014-11-06 08:04:21 -0500 received badge  Editor (source)
2014-11-06 08:00:10 -0500 answered a question C++ code equivalent in java

I dealt with the same problem. After some attempts I solved it by this code in java:

ArrayList <org.opencv.core.Point> pointsInterestList = new ArrayList();

//iterate over Mat
for (int j = 0; j < mask.rows(); j++)
{
   for (int k = 0; k < mask.cols(); k++)
   {
    double[] pixel = mask.get(j, k);
    if(pixel[0] == 255)
    {
       //add Point of Mat to list of points
       org.opencv.core.Point point = new org.opencv.core.Point(k, j);
       pointsInterestList.add(point);
    }
   }
}

MatOfPoint2f m2fFromList = new MatOfPoint2f();
m2fFromList.fromList(pointsInterestList); //create MatOfPoint2f from list of points
MatOfPoint2f m2f = new MatOfPoint2f();
m2fFromList.convertTo(m2f, CvType.CV_32FC2); //convert to type of MatOfPoint2f created from list of points

RotatedRect minRect = Imgproc.minAreaRect(m2fFromList);

It should works same like c++ code. I hope it helps you.

2014-11-06 07:59:03 -0500 answered a question Convert C++ Code to java (Iterator)

I dealt with the same problem. After some attempts I solved it by this code in java:

ArrayList <org.opencv.core.Point> pointsInterestList = new ArrayList();

//iterate over Mat
for (int j = 0; j < mask.rows(); j++)
{
   for (int k = 0; k < mask.cols(); k++)
   {
    double[] pixel = mask.get(j, k);
    if(pixel[0] == 255)
    {
       //add Point of Mat to list of points
       org.opencv.core.Point point = new org.opencv.core.Point(k, j);
       pointsInterestList.add(point);
    }
   }
}

MatOfPoint2f m2fFromList = new MatOfPoint2f();
m2fFromList.fromList(pointsInterestList); //create MatOfPoint2f from list of points
MatOfPoint2f m2f = new MatOfPoint2f();
m2fFromList.convertTo(m2f, CvType.CV_32FC2); //convert to type of MatOfPoint2f created from list of points

RotatedRect minRect = Imgproc.minAreaRect(m2fFromList);

It should works same like c++ code. I hope it helps you.

2014-11-05 05:51:42 -0500 received badge  Supporter (source)