Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV InputArray/OutputArray

Tags:

opencv

I had just compile the last version of OpenCV 2.3. And their decision to change all Matrix input/output into InputArray/OutputArray messes everything up. The same piece of code that was working well under OpenCV 2.2 is now worthless.

There's two solutions I would accept:

  1. Showing me where I can download OpenCV 2.2 for Linux, with all modules, it's important that stitching is not missing (I tried to find a suitable one, but stitching is always missing!).

  2. Help me solve what I'm describing below.

  3. OpenCV 2.4, even if still beta, has fixed this and I should move to this version instead!

I have this exception message:

OpenCV Error: Assertion failed (k == STD_VECTOR_MAT) in getMat, file /home/widgg/opencv/trunk/modules/core/src/matrix.cpp, line 928
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/widgg/opencv/trunk/modules/core/src/matrix.cpp:928: error: (-215) k == STD_VECTOR_MAT in function getMat

In gdb, this is the stack:

#0  0x00007ffff5df3445 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff5df6bab in __GI_abort () at abort.c:91
#2  0x00007ffff674169d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff673f846 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff673f873 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff673f96e in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff77fca51 in cv::error(cv::Exception const&) () from /usr/local/lib/libopencv_core.so.2.3
#7  0x00007ffff791306d in cv::_InputArray::getMat(int) const () from /usr/local/lib/libopencv_core.so.2.3
#8  0x00007ffff796064c in cv::perspectiveTransform(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&) () from /usr/local/lib/libopencv_core.so.2.3

finally, here's my code when I'm calling cv::perspectiveTransform:

std::vector<cv::Point2f> corners(4);

cv::Mat cur_image = imread("my_image.jpg");

std::vector<cv::Point2f> img_corners(4);

img_corners[0] = cv::Point2f(0, 0);

img_corners[1] = cv::Point2f(cur_image.cols, 0);

img_corners[2] = cv::Point2f(cur_image.cols, cur_image.rows);

img_corners[3] = cv::Point2f(0, cur_image.rows);

cur_image.release();

cv::perspectiveTransform(img_corners, corners, m_transf);

And cv::Mat m_transf = (Mat_ < double > (3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);, that's its value when it's first used, and it crashes at that place!

I have a similar problem with cv::FindHomography. The thing is that code was executing properly yesterday and now, this InputArray/OuputArray thing screw everything up.

It's very annoying, please help!

Also, I found this report here: OpenCV 2.2 Vs. 2.3 and it's not a good sign! There should be a workaround for this!

like image 461
widgg Avatar asked Apr 30 '12 01:04

widgg


1 Answers

It seems you have two versions of OpenCV installed, and the linker tries to use a different one for linking than the one used to compile your code.

The simplest way is to remove all the other OpenCV versions, and then a possible wrong library path will be more explicit (somelib.so missing)

Or, check all the settings PATH, linker flags and include folders to make sure you are using the same version through the include/complile/link steps

like image 142
Sam Avatar answered Oct 11 '22 18:10

Sam