作者LCY1983 (陽光男)
看板C_and_CPP
標題[問題] 讀影像檔的問題
時間Mon Apr 20 19:16:15 2015
開發平台(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
→ bdvstg: 你直接imread那個路徑也不行? 為什麼要經過那個getDir? 04/20 22:01
→ LCY1983: 給定絕對路徑當然可以,我要從大量影像中,將所有 04/20 22:07
→ LCY1983: myfilename000.tiff 進行批次處理 04/20 22:08
→ suhorng: 如果路徑中都沒有中文呢 04/20 22:09
→ LCY1983: 嘗試過樓上大大的說法,依舊不行>< 04/20 22:14
→ suhorng: 突然想到 fgets 是不是會把 '\n' 一起讀進來 04/20 22:34
→ suhorng: 確認過 files 的內容了嗎? 有沒有不該出現的空白字元之類 04/20 22:35
→ LCY1983: files的內容是影像路徑沒錯 04/20 22:38
→ LCY1983: Z:\Bryant\試片受潮測試\20150414\10\2nd\子目錄\ 04/20 22:39
→ LCY1983: myfilename000.tiff 04/20 22:39
→ bdvstg: 可以的話那你有沒有把files[0]印出來看看? 04/21 12:30
→ bdvstg: 還有既然要批次的話 路徑為什麼不是用*.tiff ? 04/21 12:31
→ bdvstg: 然後你確定myfilename000.tiff是可以用opencv讀的? 04/21 12:39
推 GoIt: 問題在getDir… 你是要讀終端機的字串嗎 04/21 13:19
→ LCY1983: 沒錯,要讀終端機字串 04/21 13:22
→ GoIt: 改一下pCmd就沒問題了 04/21 13:30
→ LCY1983: 請問要如何改呢?能否具體說明? 04/21 13:32
→ GoIt: 你路徑\\改成 \就可以了…… 04/21 17:35
→ GoIt: 應該是餵回去cv的字串問題@@ 04/21 18:26
→ Fracon: lib是dubug還是release? 可能會有這問題 04/21 19:52
※ 編輯: LCY1983 (61.220.69.195), 04/22/2015 10:13:03