Train_hog.cpp OpenCV 3.1 示例 - 无法传递正确的路径参数

Train_hog.cpp OpenCV 3.1 Example - Cannot pass the proper path parameters

本文关键字:参数 路径 cpp hog OpenCV 示例 Train      更新时间:2023-10-16

这篇文章描述了一个与我的非常相似的问题,但我是新来的,被告知要发布一个新问题。非常感谢任何人的帮助。

@Franksye 我遇到了同样的问题。我正在通过这一行中的路径 {@pd|C:/Cars/|pos_dir}{@p|Pos.lst|pos.lst}{@nd|C:/Cars/|neg_dir} {@n|Neg.lst|neg.lst}");

在文本文件Pos.lst中,我写了例如image0000.png,image0001.png彼此下方。

但是,当我在构建后运行调试器时,它给了我以下错误 The program '[0x3CF0] opencv.exe' has exited with code -1 (0xffffffff).

创建制动点时,我意识到它在执行file.open((prefix + filename).c_str());时退出load_images函数

void load_images(const string & prefix, const string & filename, vector< Mat   > & img_lst)
{
string line;
ifstream file;
file.open((prefix + filename).c_str());
if (!file.is_open())
{
    cerr << "Unable to open the list of images from " << filename << " filename." << endl;
    exit(-1);
}
bool end_of_parsing = false;
while (!end_of_parsing)
{
    getline(file, line);
    if (line.empty()) // no more file to read
    {
        end_of_parsing = true;
        break;
    }
    Mat img = imread((prefix + line).c_str()); // load the image
    if (img.empty()) // invalid image, just skip it.
        continue;
#ifdef _DEBUG
    imshow("image", img);
    waitKey(10);
#endif
    img_lst.push_back(img.clone());
}
}

我相信我在传递目录路径时做错了什么,因为load_images函数无法打开图像文件。

有人可以指出我正确的方向或告诉我我做错了什么吗?

提前谢谢你。

解决了!多亏了Windows,这是一个愚蠢的错误。

pos.lst 和 neg.lst

实际上是 pos.lst.txt 和 neg.lst.txt因为文件扩展名被隐藏。感谢这篇文章设法解决了我的问题。

不得不切换到Windows,因为我需要使用Visual Studio,一旦这个项目结束,Visual Studio将恢复到Ubuntu!