0
votes

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;
}
1
by "at the end" you mean during cleanup after main has exited? - slawekwin
Wrong librarires! Be sure to use OpenCV compiled with vc14 (you need probably to recompile OpenCV yourself) - Miki
@Miki I need to use opencv 2.4.10, cannot use another version. The problem disappears when I comment the keypoints detect line: - stardust
detector->detect(Current, kp); - stardust
@slawekwin yes the main has exited and if I stop the execution while it's still in the for cycle the program return 0 errors - stardust

1 Answers

1
votes

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.