Assertion fails in buildScalePyramids

asked 2015-03-31 01:49:24 -0600

Neha Mittal gravatar image

updated 2015-04-08 00:44:15 -0600

I am currently using OpenCV 2.4.10 I had ORB working for feature extraction and matching. I am working on porting it to an AWS with GPU. I was finally able to build openCV and all but am now getting an assertion failure. From the call stack the only thing I figured out is that ORB_CUDA::buildScalePyramids() is calling GpuMat::GpuMat(const GpuMat& m, Rect roi) and the assertion in this function is failing.

CV_Assert(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows);

I also noticed that there is some difference in the code for building the scale pyramid in the regular orb.cpp compared to the one in gpu.

Edit 1: I am not creating any GpuMat or roi. That code is internal to the ORB implementation. I only have a Mat img; which is a valid image and I have checked that the dimensions of this image are valid. My code is Function:_getRawORBKeypoints()

gpu::GpuMat image;
Mat outImage;
gpu::ORB_GPU orb(nFeat, 1.2f, 20, 10, 0, 3, ORB::HARRIS_SCORE, 10 );
image.upload(img);
orb(image, gpu::GpuMat(), orbKeypoints, orbDescriptors);

Edit 2 The callstack :

#0  0x00007fffdbf725c9 in raise () from /lib64/libc.so.6
#1  0x00007fffdbf73cd8 in abort () from /lib64/libc.so.6
#2  0x00007fffdc876535 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6
#3  0x00007fffdc8746c6 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00007fffdc8746f3 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5  0x00007fffdc87491f in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6  0x00007ffff722f5a0 in cv::error(cv::Exception const&) () from /usr/local/lib/libopencv_core.so.2.4
#7  0x00007ffff72cf62c in cv::gpu::GpuMat::GpuMat(cv::gpu::GpuMat const&, cv::Rect_<int>) () from /usr/local/lib/libopencv_core.so.2.4
#8  0x00007fffdd28d97a in cv::gpu::ORB_GPU::buildScalePyramids(cv::gpu::GpuMat const&, cv::gpu::GpuMat const&) () from /usr/local/lib/libopencv_gpu.so.2.4
#9  0x00007fffdd28e072 in cv::gpu::ORB_GPU::operator()(cv::gpu::GpuMat const&, cv::gpu::GpuMat const&, cv::gpu::GpuMat&, cv::gpu::GpuMat&) ()  from /usr/local/lib/libopencv_gpu.so.2.4
#10 0x00007fffdd28e789 in cv::gpu::ORB_GPU::operator()(cv::gpu::GpuMat const&, cv::gpu::GpuMat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::gpu::GpuMat&) () from /usr/local/lib/libopencv_gpu.so.2.4
#11 0x000000000040650e in _getRawORBKeypoints(cv::Mat, int, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::gpu::GpuMat&, bool)    ()
edit retag flag offensive close merge delete

Comments

If that assertion fails, than please start by printing out all those parameters. It seems like one of the dimensions of your input data is invalid. How did you create the GpuMat element and the roi element? Can you post that code?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-03-31 02:26:50 -0600 )edit

I have posted the code as part of my original question.

Neha Mittal gravatar imageNeha Mittal ( 2015-03-31 03:31:07 -0600 )edit

Well looking at where you call the orb operator, you specify your second argument as gpu::GpuMat() which is actually an unitinialised GPU mat element and it can thus contain any possible value (it is simply an initialisation of a pointer to memory space). Try initiating your mask with all ones if you want to process your complete image and see if that works. I am guessing the assert is triggered on the mask GpuMat not being initialised correctly.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-03-31 04:13:09 -0600 )edit

I have tried that. Did not work. If you notice the ORB code without GPU, looks like they are creating a border around the image. Nothing like this is being done in the GPU code. Any idea why?

Neha Mittal gravatar imageNeha Mittal ( 2015-03-31 04:18:04 -0600 )edit

How did you try it, please provide that code also, there could still be errors in it!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-03-31 05:01:11 -0600 )edit

This is what I had tried.

cv::gpu::GpuMat fullmask(image.size(), CV_8U, 0xFF);
orb(image, fullmask, orbKeypoints);

Did you also check the difference in the code for buildScalePyramids()?

Neha Mittal gravatar imageNeha Mittal ( 2015-03-31 06:55:37 -0600 )edit

Could you try

Mat all_ones = Mat::ones(image.rows, image.cols, CV_8UC1);
cv::gpu::GpuMat fullmask(all_ones);
orb(image, fullmask, orbKeypoints);
StevenPuttemans gravatar imageStevenPuttemans ( 2015-03-31 06:59:16 -0600 )edit

I just tried, did not solve the issue. Here is the exact error:

OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in GpuMat, file /home/ec2-user/opencv-2.4.10/modules/core/src/gpumat.cpp, line 413
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/ec2-user/opencv-2.4.10/modules/core/src/gpumat.cpp:413: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function GpuMat
Neha Mittal gravatar imageNeha Mittal ( 2015-04-01 01:28:15 -0600 )edit

It will be your task to output all GpuMat dimensions before processing and try to find out which one is empty or not initialized, then we can help you to find the reason for that. Now it is quite difficult for me to help you any further ...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-04-01 03:21:41 -0600 )edit

I found that it is crashing in gpu/src/orb.cpp function: buildScalePyramids()

Rect inner(edgeThreshold_, edgeThreshold_, sz.width - 2 * edgeThreshold_, sz.height - 2 * edgeThreshold_);
buf_(inner).setTo(Scalar::all(255));

This because the dimension of the Rect inner has a negative height. I am unable to understand the significance of this setTo() when compared to the regular orb code. Looks like different things are happening in both the codes.

Neha Mittal gravatar imageNeha Mittal ( 2015-04-02 08:07:21 -0600 )edit