Assertion fails in buildScalePyramids
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) ()
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?
I have posted the code as part of my original question.
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.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?
How did you try it, please provide that code also, there could still be errors in it!
This is what I had tried.
Did you also check the difference in the code for buildScalePyramids()?
Could you try
I just tried, did not solve the issue. Here is the exact error:
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 ...
I found that it is crashing in gpu/src/orb.cpp function: buildScalePyramids()
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.