Ask Your Question
0

[Java OpenCV] Fatal error in Imgproc.arcLength

asked 2013-07-10 09:14:52 -0600

Sodat gravatar image

updated 2013-07-10 09:15:33 -0600

I've been trying to recode the squares.cpp C++ example in Java, using OpenCV 2.4.6, and I'm stuck with an error I don't understand:

OpenCV Error: Assertion failed (curve.checkVector(2) >= 0 && (curve.depth() == CV_32F || curve.depth() == CV_32S)) in arcLength, file /local/XXXX/libs/opencv-2.4.6/modules/imgproc/src/contours.cpp, line 1886

But when I check my curve, I get:

  • curve.checkVector(2) = 4

  • curve toString output: Mat [ 4 * 1 * CV_32SC2, isCont=true, isSubmat=false, nativeObj=0x7ffca453be90, dataAddr=0x7ffca4588720 ]

So I should be able to pass the assertion, but I fail.

Is CV_32SC2 different from CV_32S?

edit retag flag offensive close merge delete

Comments

"Is CV_32SC2 different from CV_32S?"

yes, CV_32SC2 has 2 channels, CV_32S has only 1

but your mat there has the type CV_32SC2 and the depth CV_32S

so, what did you feed in ?

  MatOfPoint2f m = new MatOfPoint2f(new Point(1,1),new Point(2,3),new Point(2,3));
  double d = Imgproc.arcLength(m, false);
      System.out.println("al " + d);
      // al 2.2360680103302
berak gravatar imageberak ( 2013-07-10 11:52:18 -0600 )edit

Thanks for the answer berak ! My mat is a MatOfPoint2f, in which I copy a MatOfPoint:

MatOfPoint contours = (previous code)

MatOfPoint2f contours2f = new MatOfPoint2f();

contours.copyTo(contours2f);

How can I copy the data in a MatOfPoint in a MatOfPoint2f and still keep type and depth coeherent?

Sodat gravatar imageSodat ( 2013-07-15 04:17:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-07-15 09:48:05 -0600

Sodat gravatar image

Well, I seem to have solved the problem, though I'm not sure why...

By using:

contours2f.fromArray(contours.toArray());

instead of:

contours.copyTo(contours2f);

to copy the content of my MatOfPoint into my MatOfPoint2f, I don't fail the assertion anymore and my program is running fine (except it finds waaaay too many squares, but I'm trying to tweak it).

edit flag offensive delete link more

Comments

ah, good. got a bit helpless, there ;)

berak gravatar imageberak ( 2013-07-15 09:59:51 -0600 )edit

Question Tools

Stats

Asked: 2013-07-10 09:14:52 -0600

Seen: 2,062 times

Last updated: Jul 15 '13