Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use point.x and point.y from Java bindings

I'm looking for a way to access x and y from Point class in java bindings. Below is the code I'm working with:

Mat gray = new Mat();
Imgproc.cvtColor(img, gray, Highgui.CV_LOAD_IMAGE_GRAYSCALE);

int erosion_size = 5;
Mat element = Imgproc.getStructuringElement(
        Imgproc.MORPH_CROSS, new Size(2 * erosion_size + 1, 2 * erosion_size + 1), new Point(erosion_size, erosion_size)
);
Imgproc.erode(img, gray, element);

List<Point> points = new ArrayList<Point>();
for (int i = 0; i < gray.rows(); i++) {
    for (int j = 0; j < gray.cols(); j++) {
        points.add(new Point(i,j));
    }
}

now that I've got a list of Points I would like to call x and y on them as it is done in the c++ code below:

std::vector<cv::Point> points;
cv::Mat_<uchar>::iterator it = gray.begin<uchar>();
cv::Mat_<uchar>::iterator end = gray.end<uchar>();
int left, right, top, bottom;
for (int i = 0; i < points.size(); i++)
{
    if (i == 0) // initialize corner values
    {
        left = right = points[i].x;
        top = bottom = points[i].y;
    }
}

I looked at the API documentation and don't see any way to access the X and Y from the Point class.

Is there a workaround?

How to use point.x and point.y from pass points to minAreaRect using Java bindingsBindings

I'm looking for a way to access use xminAreaRect and y from Point class in java bindings. Below is with certain points I've collected. I'm converting this C++ code to Java using the code I'm working with:OpenCV Java Bindings

Mat gray = new Mat();
Imgproc.cvtColor(img, gray, Highgui.CV_LOAD_IMAGE_GRAYSCALE);

int erosion_size = 5;
Mat element = Imgproc.getStructuringElement(
        Imgproc.MORPH_CROSS, new Size(2 * erosion_size + 1, 2 * erosion_size + 1), new Point(erosion_size, erosion_size)
);
Imgproc.erode(img, gray, element);

List<Point> points = new ArrayList<Point>();
for (int i = 0; i < gray.rows(); i++) {
    for (int j = 0; j < gray.cols(); j++) {
        points.add(new Point(i,j));
    }
}

now that I've got a list of Points I would like to call x and y on them as it is done in the c++ code below:c++

std::vector<cv::Point> points;
cv::Mat_<uchar>::iterator it box_points;
box_points.push_back(cv::Point(left, top));
box_points.push_back(cv::Point(left, bottom));
box_points.push_back(cv::Point(right, bottom));
box_points.push_back(cv::Point(right, top));

// Compute minimal bounding box for the ROI
// Note: for some unknown reason, width/height of the box are switched.
cv::RotatedRect box = gray.begin<uchar>();
cv::Mat_<uchar>::iterator end = gray.end<uchar>();
int left, right, top, bottom;
for (int i = 0; i < points.size(); i++)
{
    if (i == 0) // initialize corner values
    {
        left = right = points[i].x;
        top = bottom = points[i].y;
    }
}
cv::minAreaRect(cv::Mat(box_points));

I looked at Java:

List <Point> boxPoints = new ArrayList<Point>();
boxPoints.add(new Point(left, top));
boxPoints.add(new Point(left, bottom));
boxPoints.add(new Point(right, bottom));
boxPoints.add(new Point(right, top));

RotatedRect box = Imgproc.minAreaRect(new Mat(boxPoints));

However, the API documentation and don't see any way to access the X and Y from the Point class. last line of my java code is giving me an error.

Is there What is the best way to pass boxPoints a workaround?to minAreaRect ?