Re: [问题] 影像加载出错

楼主: GoIt (冻物。)   2015-04-21 19:29:32
抱歉~回一篇好了...
第一次接触到_popen()这个API 发现满好用的
原PO下的指令:/dir /b /s 可以列出档案路径~
他应该是想要把特定资料夹的.tiff档抓出
以下为修改:
void getDir(....)
{
...
string pCmd = "dir /b /s ";
pCmd += '"'+string(d) + '"';
...
...
...
}
int main(....)
{
...
string str=files[0];
str.pop_back(); // remove "\n"
...
...
}
之后就能喂进opencv了
※ 引述《LCY1983 (阳光男)》之铭言:
: 开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
: Visual Studio 2010 C++
: 额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
: OpenCV
: 问题(Question):
: imread读入影像路径后,却发现是空的
: 喂入的资料(Input):
: 预期的正确结果(Expected Output):
: 错误结果(Wrong Output):
: 程式码(Code):(请善用置底文网页, 记得排版)
: #include <cv.h>
: #include <highgui.h>
: #include <opencv2/imgproc/imgproc.hpp>
: #include <opencv2/opencv.hpp>
: #include "iostream"
: #include <vector>
: #include <fstream>
: using namespace cv;
: using namespace std;
: void getDir(const char* d, vector<string> & f)
: {
: FILE* pipe = NULL;
: string pCmd = "dir /b /s " + string(d);
: char buf[256];
: if( NULL == (pipe = _popen(pCmd.c_str(),"rt")))
: {
: cout<<"Shit"<<endl;
: return;
: }
: while (!feof(pipe))
: {
: if(fgets(buf,256,pipe) != NULL)
: {
: f.push_back(string(buf));
: }
: }
: _pclose(pipe);
: }
: int main(int argc, char* argv[])
: {
: vector<string> files;
: getDir("Z:\\Bryant\\试片受潮测试\\20150414\\10\\2nd\\myfilename000.tiff",
: files);
: string str=files[0];
: Mat original_image;
: original_image=imread(str);
: system("pause");
: return 0;
: }
: 补充说明(Supplement):
: build up是成功的
: 可是,设中断点于original_image时候
: 于区域变量看到dims竟然是0
: data那里出现 错误Ptr (无法评估运算式)
: 请问各位高手,是哪里出问题?
: 这问题困扰我3天了,寻遍各种方法皆无效
: 谢谢大家帮忙
作者: LCY1983 (阳光男)   2015-04-21 20:56:00
谢谢你呀!晚点来尝试,不过,我用其他方法解决了 XDdir这个指令,虽然古老,可是,整篇程式码,却是最少行!这是它迷人之处呀 XD再次感谢你,你的方法可以成功执行!太棒了!
作者: suhorng ( )   2015-04-21 22:41:00
所以问题是结尾的 '\n' 吗? 之前推文有说过的说@@

Links booklink

Contact Us: admin [ a t ] ucptt.com