【问题标题】:OpenCV KeyPoints assertionOpenCV 关键点断言
【发布时间】:2016-12-16 21:42:36
【问题描述】:

我正在尝试使用 opencv 2.4.10 在 c++ 中实现一个代码,该代码使用 ORB 计算帧的关键点。当我在 VS 社区 2015 中运行代码时,它给了我一个断言:

程序:...l Studio 2015\Projects\lbplibrary-master\x64\Debug\prova1.exe 文件:c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0 线路:106

表达式:“(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT - 1)) == 0” && 0

有关您的程序如何导致断言的信息 失败,请参阅有关断言的 Visual C++ 文档。

这是我正在编译的代码。执行有效,它完成了工作,但最后我得到了断言!

#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;
}

【问题讨论】:

  • “最后”是指在main 退出后的清理期间?
  • 库错误!一定要使用用vc14编译的OpenCV(你可能需要自己重新编译OpenCV)
  • @Miki 我需要使用 opencv 2.4.10,不能使用其他版本。当我评论关键点检测线时问题消失了:
  • 检测器->检测(当前,kp);
  • @slawekwin 是的,主程序已经退出,如果我在它仍在 for 循环中时停止执行,程序将返回 0 个错误

标签: c++ opencv visual-studio-2015 orb


【解决方案1】:

您使用的是 Visual Studio 2015,这意味着 vc14 编译器。

OpenCV 2.4.10 没有为此预构建的二进制文件,但仅适用于 vc10 (Visual Studio 2010)、vc11 (Visual Studio 2012) 和 vc12 (Visual Studio 2013)。

所以你有几个选择:

  1. 使用 Visual Studio 2010、2011、2012 链接正确的库
  2. 使用 vc14 重新编译 OpenCV 并将它们与 Visual Studio 2015 一起使用。
  3. 如果这是一个选项,您可以切换到 OpenCV 3.1,它具有为 vc14 64 位预构建的二进制文件。

【讨论】:

  • 你的意思是从 openCV 3.1 下载 vc14 文件夹并将其复制到我的 opencv 2.10 中吗?然后重新编译opencv?谢谢你的帮助,我很感激
  • 没有。我的意思是要么用 vc14 重新编译 2.4.10,要么使用已经为 vc14 预编译二进制文件的 3.1。不要混合它们!
  • 好的,我要下载cmake并重新编译,不幸的是我需要那个版本的opencv!
  • 好的,很好。请记住在调试和发布时为您的项目(x86 与 x64)所需的相同架构进行编译。
  • 我刚刚用 vc14 编译完 opencv 2.10 但断言仍然存在
猜你喜欢
  • 1970-01-01
  • 2018-05-19
  • 2014-02-10
  • 2016-04-05
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多