Point2f to MatVector

169 views
Skip to first unread message

SFM K!4

unread,
Dec 8, 2017, 10:19:37 AM12/8/17
to javacv

How to create MatVector object to be used in drawContours function using 4 points?

       
c1 = new opencv_core.Point2f(4); c1.position(0).put(attachment.points[0]); c1.position(1).put(attachment.points[1]); c1.position(2).put(attachment.points[2]); c1.position(3).put(attachment.points[3]); opencv_core.Mat dist = new opencv_core.Mat(c1); opencv_core.MatVector co_ordinates = new opencv_core.MatVector(1); co_ordinates.put(0,dist);
opencv_core.Mat mask = new opencv_core.Mat((int)cameraFrameSize.height(), (int)cameraFrameSize.width(), CV_8UC1, new opencv_core.Scalar(0)); drawContours(mask, co_ordinates, 0, new opencv_core.Scalar(255),FILLED, LINE_8 , noArray() , 2 , new opencv_core.Point());

error result : -

12-08 14:09:36.272 3280-3896/org.bytedeco.javacv.android.example D/error sdam: /home/saudet/projects/bytedeco/javacpp-presets/opencv/cppbuild/android-arm/opencv-3.2.0/modules/imgproc/src/drawing.cpp:2481: error: (-215) npoints > 0 in function void cv::drawContours(cv::InputOutputArray, cv::InputArrayOfArrays, int, const Scalar&, int, int, cv::InputArray, int, cv::Point)

Samuel Audet

unread,
Dec 8, 2017, 6:50:05 PM12/8/17
to javacv, shene...@gmail.com
There used to be some code for that in this thread:

But it looks like Google erased it, so I'll copy/paste it below.

On 03/31/2015 12:24 AM, Tuan Nguyen wrote:
I tried it and it does not work. We need to pass a Pointer to create a
CvMat like CvMat mat = new CvMat(Pointer). On the other hand we don't
have Point2f in JavaCV we have something like cvPoint2D32f ...

Yes, there is Point2f:
http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/javacpp/opencv_core.Point2f.html

But it's more efficient and easier in Java to use Indexer anyway, so we might as well do it like that. Your code would look like this:

int size = lines.size();
Mat corners = new Mat(size, 2, CV_32FC1);
FloatIndexer idx = corners.createIndexer();
int count = 0;
for (int i = 0; i < size; i++) {
    for (int j = i+1; j < size; j++) {
        Point2f pt = computeIntersect(lines.get(i), lines.get(j));
        if (pt.x() >= 0 && pt.y() >= 0) {
            idx.put(count, 0, pt.x());
            idx.put(count, 1, pt.y());
            count++;
        }
    }
}
corners = corners.reshape(1, count);
Mat approx = new Mat();
approxPolyDP(corners, approx, arcLength(corners, true) * 0.02, true);

*My real problem is this:*


Thought I might provide some context to help you answer my question.
Basically, I'm trying to crop a receipt out from a photo ignoring the
background etc.

I've been able to determine the points but in essence, don't know how to
choose the best 4 points(4 corners of the paper) which allow me to crop
the receipt out from the photo.
See my results below.

It's alright to include a link, but please don't post large attachments on the mailing list, thank you.


One of my solution is putting all these blue dots/points into a
contour/CvMat and see if I can apply approxPolyDp and best 4 corners out
of the contour but I tried it in C++ and it does not work. So I need to
approach the problem differently.

Like I said, first, you're going to need to come up with a criterion that we can express with numbers, such as area or something...

Samuel


2017/12/09 0:19 "SFM K!4" <shene...@gmail.com>:
--

---
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages