【发布时间】: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