简体   繁体   中英

OpenCV KeyPoints assertion

I am trying to implement a code in c++ using opencv 2.4.10 that calculates frame's keypoints with ORB. When I run the code in VS community 2015 it gives me the assertion:

Program: ...l Studio 2015\\Projects\\lbplibrary-master\\x64\\Debug\\prova1.exe File: c:\\program files (x86)\\microsoft visual studio 14.0\\vc\\include\\xmemory0 Line: 106

Expression: "(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT - 1)) == 0" && 0

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

This is the code I am compiling. The execution works and it does the job but at the end I get the assertion!

#include <iostream>
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <string>
#include <fstream>
#include <opencv2/opencv.hpp>

#include "stdafx.h"


using namespace cv;
using namespace std;
using namespace lbplibrary;

static bool isFileExist(const String& filename)

{
    /// Open the file
    FILE* f = fopen(filename.c_str(), "rb");

    /// in the event of a failure, return false
    if (!f)
        return false;

    fclose(f);

    return true;
}


string intToStr(int i, string path) {

    string bla = "";
    stringstream ss;
    ss << i;
    string ret = "";
    ss >> ret;
    string name = bla.substr(0, bla.size() - ret.size());

    name = path + name + ret;
    return name;
}


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


    //keyframe
    string current_window = "Current frame ";
    Mat Current;


    //keypoints
    vector<KeyPoint> kp;
    Ptr<ORB> detector = FeatureDetector::create("ORB");

    fstream outputFile;

    //elaborate keyframes

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

        //read and show keyframe 

        string Curr_name = intToStr(i, "dataset/backyard-seq/map/frame");
        Current = imread(Curr_name + ".jpg", 1);
        namedWindow(current_window, WINDOW_AUTOSIZE);
        imshow(current_window, Current);

        //calculate frame keypoints

        detector->detect(Current, kp);

        //save keypoints of each keyframe in txt

        if (!isFileExist(Curr_name + ".txt"))
        {
            outputFile.open(Curr_name + ".txt", ios::out);
            for (size_t ii = 0; ii < kp.size(); ++ii)
                outputFile << kp[ii].pt.x << " " << kp[ii].pt.y << std::endl;
            outputFile.close();
        }

        //draw and show keypoints

        Mat out;
        drawKeypoints(Current, kp, out, Scalar::all(255));
        imshow("Keypoints", out);


    }


    return 0;
}

You're using Visual Studio 2015, which means vc14 compiler.

OpenCV 2.4.10 doesn't have prebuilt binaries for that, but only for vc10 (Visual Studio 2010), vc11 (Visual Studio 2012) and vc12 (Visual Studio 2013).

So you have a few options:

  1. Use either Visual Studio 2010, 2011, 2012 linking the correct libraries
  2. Recompile OpenCV using vc14 and use them with Visual Studio 2015.
  3. If that's an option, you can switch to OpenCV 3.1, which has prebuilt binaries for vc14 64bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM