ucrtbase.dll: An invalid parameter was passed to a function that considers invalid parameters fatal

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-01 03:19:25

问题


I'm currently working on a personal project with OpenCV and I have a few issues during the execution of the program. After implementing an AKAZE + BOW recognizer (which didn't seem to work well enough for my problem) I wanted to try out a SIFT (and eventually SURF) implementation.

For my project I'm following this one found on github and I'm using VS2015 (community) and OpenCV 2.4.13 over Windows 10.

The issue I'm having, as stated in the title, lies with the ucrtbase.dll which gets an invalid parameter during execution (if I read other threads correctly the dll should be an OS library in Windows 10). The problem arises when the for cicle moves onto the second iteration (aka when it's supposed to get the features of another image for the BOW training), this is when the execution stops and the error in the title appears.

I tried various things (eg. using different constructors for the detector/extractor or commenting part of the code) and during the debug session it seems that the error is caused by the detect function but I'm not sure why (also, as stated in the code below, commenting the detect function and those following it fixes the problem).

The drawKeypoints function (used in another test) seems to be drawing the keypoints correctly (which should mean the detect function is working correctly).

Below you can find the snippet that's giving the error:

int main(int argc, char ** argv)
{

    const int nimages = 4;
    const int nclusters = 2;

    const char *datapath = "./database";

    SiftFeatureDetector detector(400);
    SiftDescriptorExtractor extractor;
    Ptr<BOWTrainer> bow_train = makePtr<BOWKMeansTrainer>(nclusters);

    for (int i = 0; i<nimages; i++)
    {

        Mat im, feat;
        std::vector<KeyPoint> kp;

        // read an image from the database
        im = cv::imread(format("%s/%d.png", datapath, i + 1), 1);

        // detect keypoints
        detector.detect(im, kp); // commenting from here avoids the error

        // extract features
        extractor.compute(im, kp, feat);

        // add features for bow training
        bow_train->add(feat);

    }

    /* more stuff here */
}

Tell me if there's anything else you need to know to understand the problem.

Thanks in advance for any help/advice you can give me.

EDIT 1:

I tried removing all for cicles and the program manages to reach the end executing all functions correctly but it's still giving the ucrtbase.dll error when returning from main. Another thing I've noticed during VS debug is that the debugger generates an exception when it has to deallocate memory (using that dll), either during for cicles or at the end of the program.

I guess the debugger here has the solution but I don't really get what's the problem with that dll, any help will be really appreciated if anyone has time to spare.

EDIT 2:

After a few days of testing it seems the error is coming from the deallocation of:

std::vector< cv::KeyPoint >

If KeyPoint vectors are instantiated and only destroyed when the program ends, the computation works just fine and there's the dll error at end (which is annoying but for quick tests I can cope with).

The issue is I'd like to create functions that make use of those vectors without having to pass them as arguments. Since the deallocation seems to be the problem I can't do that without having the program crash after each call to said functions. I have also tried using clear() and swap() on the vector but that didn't work either.

I'll keep trying to figure this out as I keep coding but any help/insight would really be appreciated.


回答1:


This issue with crashing on vector deallocation seems to be to do with linking against the wrong version of the OpenCV library. If you're building in Debug you need to be linked against the opencv_world320d.lib (or opencv_world310.lib or the library for whichever version of OpenCV you're using) - the "d" after the version number is significant. For Release configurations use the opencv_worldXXX.lib to link against.

If you're seeing the "invalid parameter was passed to a function that considers..." message this is a symptom of the same issue.




回答2:


After some time I guess I figured this out.

It seems the issue was with VS2015 compiler: OpenCV 2.4.13 has some issues with that version of VS and that's probably because there's only a vc12 folder instead of the vc14 that's supposed to work with VS2015 (basically the compability is not fully guaranteed).

After moving to the OpenCV3.1 build (with the extra modules) the program is running without throwing any exception.



来源:https://stackoverflow.com/questions/40074100/ucrtbase-dll-an-invalid-parameter-was-passed-to-a-function-that-considers-inval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!