I am having problems with the cv::BFMatcher when I try to perform the feature matching. I compute the descriptors with the xfeatures2D::SIFT descriptor. When I try to perform the matching the application output shows "Exception at 0x7ff833308b9c, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) at f:\dd\vctools\crt_bld\self_64_amd64\crt\src\xthrow.cpp:13"
The code is something like:
matchesltor.clear();
matchesrtol.clear();
cv::BFMatcher matcher(cv::NORM_L2);
ProcessedImageData *imageDataLeft = mImageDataMap.value(mapKeyList.at(m));
std::vector<cv::KeyPoint> tiePointsLeft = imageDataLeft->getTiepoints();
cv::Mat descriptorsLeft= imageDataLeft->getDescriptors();
ProcessedImageData *imageDataRight = mImageDataMap.value(mapKeyList.at(n));
std::vector<cv::KeyPoint> tiePointsRight = imageDataRight->getTiepoints();
cv::Mat descriptorsRight= imageDataRight->getDescriptors();
matcher.knnMatch(descriptorsLeft,descriptorsRight,matchesltor,2)
matcher.knnMatch(descriptorsRight,descriptorsLeft,matchesrtol,2)
The output message is shown in the firts line that performs the matching "matcher.knnMatch(descriptorsLeft,descriptorsRight,matchesltor,2)".
The strange thing is that it work in a single qt project that only perform the tie point detection, tie point description and matching but when I try to join it in other project (same code, same compiler and same qt version) it shows that output message and the execution stop (the application does not break).
Thanks for your help.
Related
In my real time image tracking solution, whenever i am calling detectAndCompute i get an exception thrown.
The exception doesnt crash the program, and the tracking still works (on my machine) but due to the fact that it is constantly throwing the exception, I am seeing some major performance setbacks. Here is the exception:
Exception thrown at 0x00007FFF0FBEA839 in OpenCV2.exe: Microsoft C++ exception: ipp::IwException at memory location 0x0000004CB72FC5C8.
I tried printing the exception to get details with a try-catch clause but it didnt give me any info. Here is the line that throws this exception:
algo->detectAndCompute(frame, mask, keypoints2, descriptors2, false);
This is harmless, see for example https://github.com/opencv/opencv/issues/9718.
If you run your code outside of the debugger you will not see the exception printout.
I am currently trying to implement the Lucy Richardson algorithm in Opencv, when it comes to running the 'cv::subtract' method in my program it throws an InteropServices exception (stack trace below)
************** Exception Text **************
System.Runtime.InteropServices.SEHException (0x80004005): External has thrown an exception.
at cv.Mat.=(Mat* , MatExpr* expr) in e:\opencv\opencv\build\include\opencv2\core\mat.inl.hpp:line 3107
at LucyRichardson.LucyRich(LucyRichardson* , Mat* , basic_string<char\,std::char_traits<char>\,std::allocator<char> >* imagePath) in e:\documents\development\realtimeimageprocessing\imageprocessing\imageprocessing\lucyrichardson.cpp:line 63
Below is the block of code where the error occurs, it is thrown on the second line.
im_correction = cv::Mat (cvSize(383, 357), 8, 1);
cv::subtract(im, im_conv_kernel, im_correction);
cv::namedWindow("Sub");
cv::imshow("Sub", im_correction);
The variables im and im_conv_kernel are both of type cv::Mat and are correctly populated and the variable im_correction I have tried creating a version of before I save the result of the subtraction in.
I am using cv::subtractions fine in other parts of the program.
Does anyone know why this error occurs and how I could fix it? Or if there is a different method I could try for the subtraction?
I have worked out where the problem was I needed to make sure all of the images where of the same type. - After adding the below three lines before performing the subtract it worked fine.
im.convertTo(im, CV_8UC1);
im_conv_kernel.convertTo(im_conv_kernel, CV_8UC1);
im_correction.convertTo(im_correction, CV_8UC1);
I'm trying to get the background image from BackgroundSubtractorMOG2:
bg->getBackgroundImage(back);
but I get a Thread 1 SIGABRT (which as a c++ n00b puzzles me)
and this error:
OpenCV Error: Assertion failed (nchannels == 3) in getBackgroundImage, file /Users/hm/Downloads/OpenCV-2.4.4/modules/video/src/bgfg_gaussmix2.cpp, line 579
libc++abi.dylib: terminate called throwing an exception
(lldb)
I'm not sure what the problem is, suspecting it's something to do with the nmixtures paramater, but I've left that as the default(3). Any hints ?
It looks like you need to use 3 channel images rather than grayscale. Make sure the image type you are using is CV_8UC3 or if you are reading from a file use cv::imread('path/to/file') with no additional arguments.
I'm currently suffering from some strange exceptions that are most probably due to me doing something incorrectly while interacting with opencv:
First-chance exception at 0x7580b9bc in xxx.exe: Microsoft C++ exception: cv::Exception at memory location 0x00c1c624..
I've already enabled the Thrown field in the Debug -> Exceptions menu, however I really can't figure out where in my code the exception is thrown.
How can I debug this?
EDIT
the stack frame reads like this (my app won't even show up in the list!):
KernelBase.dll!7580b8bc()
[Frames below may be incorrect or missing ]
KernelBase.dll!7580b8bc()
opencv_core242d.dll!54eb60cc()
You could wrap your entire main in a try catch block which prints out the exception details. If the open CV API can throw exceptions, you will need to think about handling them anyway as part of your design:
try
{
// ... Contents of your main
}
catch ( cv::Exception & e )
{
cerr << e.msg << endl; // output exception message
}
OpenCV has this handy function called cv::setBreakOnError
If you put the following into your main before any opencv calls:
cv::setBreakOnError(true);
then your program will crash, because OpenCV will do an invalid operation (dereferencing a null pointer) just before it would throw cv::Exception normally. If you run your code in a debugger, it will stop at this illegal operation, and you can see the whole call stack with all of your codes and variables at the time of the error.
I´ve got this problem by using OpenCV with WebCam. The problem in my case is that the program is trying to read an image when the Cam hasn't been initialized.
my error code:
// open camera
capture.open(0);
while (1){
//store image to matrix // here is the bug
capture.read(cameraFeed);
The solution
// open camera
capture.open(0);
while (1){
//this line makes the program wait for an image
while (!capture.read(cameraFeed));
//store image to matrix
capture.read(cameraFeed);
(sorry about my english)
Thanks
My MFC app runs various API from OpenCV2. Everything else is working fine. But when my program runs
cv::Mat result;
cv::equalizeHist(m_cvImage,result);
I get following runtime exception.
Unhandled exception at 0x7727fbae in OpenCVTest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0029e944..
"C:\slave\WinInstallerMegaPack\src\opencv\modules\imgproc\src\histogram.cpp:2430: error: (-215) CV_ARE_SIZES_EQ(src, dst) && CV_ARE_TYPES_EQ(src, dst) && CV_MAT_TYPE(src->type) == CV_8UC1"
According to debugger, the exception was thrown in the middle of processing (about 40%) the image in equalizeHist. Is there anything I need to do? FYI: I am using binary OpenCV provided by its web site.
UPDATE:
I've resolved this issue by converting images to gray-level before equalizing it. I just didn't know
the function only works with gray-level image
images that look like gray-level can be non-gray.
I imagine the problem you are encountering is that m_cvImage is a 3-channel image. So, you need to convert it to a grayscale image before you can call equalizeHist.
cvtColor(m_cvImage, m_cvImage, CV_BGR2GRAY);
cv::Mat result;
cv::equalizeHist(m_cvImage, result);
Also, have a look at the EqualizeHist_Demo.cpp tutorial sample to see how it is used.