[問題] 影像載入出錯 [已解決]

看板C_and_CPP (C/C++)作者 (陽光男)時間11年前 (2015/04/20 19:16), 11年前編輯推噓1(1019)
留言20則, 5人參與, 最新討論串1/1
開發平台(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天了,尋遍各種方法皆無效 謝謝大家幫忙 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.69.195 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1429528577.A.F59.html ※ 編輯: LCY1983 (175.182.140.93), 04/20/2015 21:40:08

04/20 22:01, , 1F
你直接imread那個路徑也不行? 為什麼要經過那個getDir?
04/20 22:01, 1F

04/20 22:07, , 2F
給定絕對路徑當然可以,我要從大量影像中,將所有
04/20 22:07, 2F

04/20 22:08, , 3F
myfilename000.tiff 進行批次處理
04/20 22:08, 3F

04/20 22:09, , 4F
如果路徑中都沒有中文呢
04/20 22:09, 4F

04/20 22:14, , 5F
嘗試過樓上大大的說法,依舊不行><
04/20 22:14, 5F

04/20 22:34, , 6F
突然想到 fgets 是不是會把 '\n' 一起讀進來
04/20 22:34, 6F

04/20 22:35, , 7F
確認過 files 的內容了嗎? 有沒有不該出現的空白字元之類
04/20 22:35, 7F

04/20 22:38, , 8F
files的內容是影像路徑沒錯
04/20 22:38, 8F

04/20 22:39, , 9F
Z:\Bryant\試片受潮測試\20150414\10\2nd\子目錄\
04/20 22:39, 9F

04/20 22:39, , 10F
myfilename000.tiff
04/20 22:39, 10F

04/21 12:30, , 11F
可以的話那你有沒有把files[0]印出來看看?
04/21 12:30, 11F

04/21 12:31, , 12F
還有既然要批次的話 路徑為什麼不是用*.tiff ?
04/21 12:31, 12F

04/21 12:39, , 13F
然後你確定myfilename000.tiff是可以用opencv讀的?
04/21 12:39, 13F

04/21 13:19, , 14F
問題在getDir… 你是要讀終端機的字串嗎
04/21 13:19, 14F

04/21 13:22, , 15F
沒錯,要讀終端機字串
04/21 13:22, 15F

04/21 13:30, , 16F
改一下pCmd就沒問題了
04/21 13:30, 16F

04/21 13:32, , 17F
請問要如何改呢?能否具體說明?
04/21 13:32, 17F

04/21 17:35, , 18F
你路徑\\改成 \就可以了……
04/21 17:35, 18F

04/21 18:26, , 19F
應該是餵回去cv的字串問題@@
04/21 18:26, 19F

04/21 19:52, , 20F
lib是dubug還是release? 可能會有這問題
04/21 19:52, 20F
※ 編輯: LCY1983 (61.220.69.195), 04/22/2015 10:13:03
文章代碼(AID): #1LDE01zP (C_and_CPP)
文章代碼(AID): #1LDE01zP (C_and_CPP)