Ask Your Question
0

OpenCV Assertion Failed for Perspective Transform.

asked 2013-08-05 19:18:35 -0600

swamynathan gravatar image

updated 2015-04-11 08:54:35 -0600

berak gravatar image

For this part of code from this application code

    Mat hg = Calib3d.findHomography(obj, scene, 8, 10);

    Mat obj_corners = new Mat(4,1,CvType.CV_32FC1);
    Mat scene_corners = new Mat(4,1,CvType.CV_32FC1);

    Core.perspectiveTransform(obj_corners, scene_corners, hg);

This is the error, also tried changing the type to CV_8UC1, CV_32F and CV_32FC1

08-06 05:37:35.219: E/cv::error()(17414): OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)) in void cv::perspectiveTransform(cv::InputArray, cv::OutputArray, cv::InputArray), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matmul.cpp, line 1926
08-06 05:37:35.229: W/dalvikvm(17414): threadid=11: thread exiting with uncaught exception (group=0x40ad59f0)
08-06 05:37:35.229: E/AndroidRuntime(17414): FATAL EXCEPTION: Thread-5874
08-06 05:37:35.229: E/AndroidRuntime(17414): CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matmul.cpp:1926: error: (-215) scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F) in function void cv::perspectiveTransform(cv::InputArray, cv::OutputArray, cv::InputArray)
08-06 05:37:35.229: E/AndroidRuntime(17414): ] 
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.core.Core.perspectiveTransform_0(Native Method)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.core.Core.perspectiveTransform(Core.java:5869)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at com.example.objectrecognition.MainActivity.onCameraFrame(MainActivity.java:279)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:376)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:294)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at java.lang.Thread.run(Thread.java:856)

The MainActivity.java:279 referes to the line

Core.perspectiveTransform(obj_corners, scene_corners, hg);

When I use log for the two I get

obj_corners : Mat [ 4*1*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x677d18, dataAddr=0x7de5a0 ]
scene_corners : Mat [ 4*1*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x677d58, dataAddr=0x5d9c80 ]

What am I missing here?

edit retag flag offensive close merge delete

Comments

2

The problem is that the homography matrix is a 3x3 Matrix and you are trying perspective transform on a 4x1 Matrix(4 dimensional vector) with a 3x3 matrix. Perspective transform requires a (n-1)x1 source Matrix/vector (when n is the number of columns in the transformation matrix). So it does not fail at the Matrix type, but here: (scn + 1 == m.cols). Your m.cols is 3 and snc +1 = 5.

That's also why the opencv example uses a point2f vector (point2f = point with 2 floats x and y) std::vector<Point2f> obj_corners(4);

Moster gravatar imageMoster ( 2013-08-06 05:48:55 -0600 )edit

Thanks 2 you

swamynathan gravatar imageswamynathan ( 2013-08-06 19:53:03 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-08-06 14:29:39 -0600

tenta4 gravatar image

Your
Mat obj_corners = new Mat(4,1,CvType.CV_32FC1);
Mat scene_corners = new Mat(4,1,CvType.CV_32FC1);

must be CvType.CV_32FC2

Its a points 2d, that's why they have 2 (x,y) coordinates.

edit flag offensive delete link more

Comments

Thanks it solved this problem.

swamynathan gravatar imageswamynathan ( 2013-08-06 19:52:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-08-05 19:18:35 -0600

Seen: 17,127 times

Last updated: Aug 06 '13