Ask Your Question

gmunumel's profile - activity

2019-02-22 18:09:31 -0600 received badge  Popular Question (source)
2015-10-31 02:32:38 -0600 received badge  Self-Learner (source)
2015-05-14 05:45:28 -0600 received badge  Enthusiast
2015-05-13 02:38:11 -0600 asked a question Change size while using dilate in java opencv

I'm using opencv in java. I'm facing this weird problem, after I do dilate function my image changes its size. In the documentation explicitly said:

dst - output image of the same size and type as src.

My code is:

Log.d(TAG, "dilate size1  " + dilate.size().height + " " + dilate.size().width);
Imgproc.GaussianBlur(warpg, smooth, new Size(3, 3), 3);
Log.d(TAG, "smooth size1  " + smooth.size().height + " " + smooth.size().width);
Imgproc.adaptiveThreshold(smooth, thresh, 255, 0, 1, 5, 2);
Log.d(TAG, "thresh size1  " + thresh.size().height + " " + thresh.size().width);
kernel = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3));
Imgproc.erode(thresh, erode, kernel, new Point(-1, -1), 1);
Log.d(TAG, "erode size1  " + erode.size().height + " " + erode.size().width);
Imgproc.dilate(erode, dilate, kernel, new Point(-1, -1), 1);
Imgproc.findContours(thresh, contours, hierarchy,
        Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
Log.d(TAG, "dilate size2  " + dilate.size().height + " " + dilate.size().width);

My output is:

dilate size1  450.0 450.0
smooth size1  450.0 450.0
thresh size1  450.0 450.0
erode size1  450.0 450.0
dilate size2  1.0 313.0

If I try with Imgproc.dilate(erode, dilate, kernel); is the same result.

Any idea?

2015-05-13 02:34:52 -0600 answered a question Convert MatOfPoint2f to MatOfPoint

I got it working doing:

MatOfPoint approxf1 = new MatOfPoint();
Imgproc.approxPolyDP(newMtx, approx, 0.02 * peri, true);
// All these lines are to print the contour (optional)
approx.convertTo(approxf1, CvType.CV_32S);
List<MatOfPoint> contourTemp = new ArrayList<>();
contourTemp.add(approxf1);
Imgproc.drawContours(img, contourTemp, 0, new Scalar(0, 255, 0), 2);

Cheers.

2015-05-09 10:17:33 -0600 received badge  Supporter (source)
2015-05-09 03:23:45 -0600 asked a question Convert MatOfPoint2f to MatOfPoint

I'm working in an opencv project for android. I need to convert a variable from MatOfPoint2f to MatOfPoint. As follows is the relevant part of my code: approx is of type MatOfPoint2f and I need to convert it because drawContours use type ArrayList<matofpoint>.

Imgproc.approxPolyDP(newMtx, approx, 0.02*peri, true);
approxMatOfPoint = (MatOfPoint) approx; // to convert
ArrayList<MatOfPoint> p = new ArrayList<>();
p.add(approxMatOfPoint);
Imgproc.drawContours(img, p, 0, new Scalar(0,255,0), 2);