Ask Your Question
0

about MatOfPoint2f

asked Mar 20 '13

zhang13404 gravatar image

updated Mar 20 '13

opencv4android 2.4.4

befort i use Imgproc.approxPolyDP, I want to convert Mat to MatOfPoint2f;

Mat initialImg = Highgui.imread("/sdcard/card.jpg", 0);
MatOfPoint2f matOfPoint2f=new MatOfPoint2f(initialImg);

then I got the error:

03-20 10:35:57.825: E/AndroidRuntime(25073): java.lang.IllegalArgumentException: Incomatible Mat The error line is:

MatOfPoint2f matOfPoint2f=new MatOfPoint2f(initialImg);
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Mar 20 '13

berak gravatar image

updated Mar 20 '13

you can't approximate an Image with a polygon, you need to to find some contours first.

it's not a matter of converting Mat types, you're missing some processing steps.

to do it, you need to:

  1. binarize your (grayscale) image using threshold, compare or Canny
  2. findContours() in the binary image , probably filter out stuff you don't want
  3. now you can approxpoly those contours
Preview: (hide)

Comments

at first,thank you for you answer~ yes, you are right. in fact, I have done a similar deal with, such as canny, but after using canny, i have still Mat types, still need to convert Mat to MatOfPoint2f, what should i do?

zhang13404 gravatar imagezhang13404 (Mar 21 '13)edit

Oh! I get it. I overlooked after findContours() i have List<MatOfPoint>. thank you very much~!

zhang13404 gravatar imagezhang13404 (Mar 21 '13)edit

Question Tools

Stats

Asked: Mar 20 '13

Seen: 1,327 times

Last updated: Mar 20 '13