从文件目录执行重复的功能,使用OpenCV 3.0
Files from directory to perform a repeated function, using OpenCV 3.0
我是c++编程的新手,我需要这样做:我有一个代码,接收两个图像的路径并输出一个数字(使用opencv的直方图相似度)。
我需要使用这个函数,而不是给它第二个图像文件,它将从一个文件夹加载图像,重复操作的次数,图像在这个文件夹中,并存储结果。
如果你能指出我可以使用的功能或在某个地方我可以学习这个,我会非常感激,我的知识非常有限。
我没有限制,但我也非常非常失落。我想我需要把函数我已经有和改变argv[1]为agv[I]。但是如何调用目录中的文件呢?我是否应该将所有文件的名称保存为txt格式?
OpenCV具有glob功能
void cv::glob ( String pattern,
std::vector< String > & result,
bool recursive = false
)
在这里你可以找到关于这个函数的详细答案
首先,您不需要将所有文件的名称保存在txt文件中。我以前遇到过很多次同样的问题,并找到了以下解决方案。正如micka建议的那样,你必须使用direct .h,它与opencv
没有连接。- 把你的图片放在一个文件夹里,并命名它。
- 谷歌direct .h下载并添加到你的c++/opencv项目。(在我的例子中,我使用的是visual studio,所以我必须使用add new item选项。只需谷歌,找到如何添加头文件为您的项目)
添加后根据需要修改后运行以下代码
#include "dirent.h" //you have to add here opencv header files also int main() { char buffer[1000]; DIR *dir; struct dirent *ent; if ((dir = opendir("file path to your folder that images are stored"))!= NULL) { while (((ent = readdir (dir)) != NULL)) { char *b=ent->d_name; if(b[0]!='.') { sprintf(buffer,"file path to your folder that images are stored\%s",ent->d_name); /* This character array named "buffer" contains the file path to each of your image in a folder. For a example if your image file paths are c://yourfolder//dew3.jpg c://yourfolder//d3dse.jpg c://yourfolder//se.jpg and during the first iteration of while loop string in "buffer" will be c://yourfolder//dew3.jpg and during the 2nd iteration of while loop string in "buffer" will be c://yourfolder//d3dse.jpg and during the 3rd iteration of while loop string in "buffer" will be c://yourfolder//se.jpg */ // do your opencv stuff here printf("%sn", ent->d_name); /* print all the files and directories within directory */ } else {} } closedir (dir); } else { /* could not open directory */ perror (""); return EXIT_FAILURE; } return 0; }
你可以看到,direction。h和sprintf在这里起了作用。我添加了一些描述作为上面的评论,并参考它们。希望这对你有所帮助。询问是否有什么需要澄清的。谢谢! !
相关文章:
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 如何使用OpenCV-C++编写*.mp4视频?
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- 在虚拟机上使用 OpenCV 重新构建C++程序
- 无法使用 OpenCv 3.4.5 从具有C++ dll 的网络摄像机 (rtsp) 中抓取帧
- 如何使用opencv和Qt拍摄部分桌面的照片
- 在C++中使用OpenCV矩阵中的特征将图像旋转90度
- 使用 OpenCV readNetFromTensorFlow 运行 Keras DNN 模型 (UNet):错误:操作
- 如何使用 opencv 绘制绿色矩形?
- 使用 Opencv 将姿势值实时写入文本文件
- 如果函数使用 OPENCV Mat 作为输入,如何编写头文件?
- 使用opencv的C++图像检测
- 在头文件中使用opencv类型来实现未定义的标识符
- 如何使用OpenCV同时显示"深度"和"颜色"视频图像
- 使用OpenCV计数硬币
- 使用opencv在GPU上调整图像大小会产生空的输出矩阵
- 如何在使用OpenCV C++应用K均值后提取分割图像
- 帧提取 使用OpenCV的视频文件开头只有几秒钟