2014-10-17 76 views
-3

嘿,我已經嘗試了很多搜索與type_id「opencv-image」讀取xml文件,我在這裏看到的所有是「opencv矩陣」和所有可用的幫助是無用的我。 請幫我從xml文件中讀取圖像矩陣。使用opencv讀取xml文件type_id opencv-image使用opencv

我在這裏粘貼我的XML文件的上半部分的一些想法。

<?xml version="1.0"?> 
<opencv_storage> 
<depthImg190 type_id="opencv-image"> 
<width>320</width> 
<height>240</height> 
<origin>top-left</origin> 
<layout>interleaved</layout> 
<dt>w</dt> 
<data> 
0 0 0 0 27120 27384 27120 27120 27384 27120 27120 27120 27120 27384 
27384 27664 27664 27944 27944 27664 27664 27944 27944 27944 28224 
27944 27944 28224 28224 28224 28224 28520 28816 29120 29120 29120 
29120 29120 29120 29120 29432 29744 30072 30072 29744 29744 30072 
30072 30072 30400 30400 30736 30736 31080 31080 31080 31440 31440 
31440 31440 31800 31800 31800 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 27120 27120 27120 27120 27384 27384 27384 27384 27384 27384 
</depthImg190> 
</opencv_storage> 

我已經使用的代碼

FileStorage f; 
Mat m; 
f.open("temp.xml", FileStorage::READ); 
f["depthImg190"] >> m; 
f.release(); 

但我面臨一個異常「opencv的Errorr:在簡歷::閱讀,文件錯誤的參數<未知的數組類型> ....... 。\ opencv \ modules \ core \ persistence.cpp,5535行「。

任何幫助將appriciated

+0

其中一個問題是,上面的xml是一個序列化的* IplImage *,而不是一個cv :: Mat。它不僅是「opencv-image」部分,寬度爲<-> cols,高度爲<->行,如果這是傳統數據,那麼除了cvLoad(yukk)之外,您將沒有其他機會。如果你真的寫了這個,你應該在第一個地方改變那個*部分。 – berak 2014-10-24 06:47:29

+0

@berak你是非常正確的,問題是我不寫這些數據。我只是將這個數據集用於我的研究工作,我不得不使用這個數據集。 I'v完成所有,但在這裏我卡住了,當我在循環中使用cvLoad獲取通過 讀取文件IplImage * depth =(IplImage *)cvLoad(getPath(filename)); 其中getPath(文件名)返回「data \\ depth \\ depthImg190.xml」 ,但cvLoad沒有正確讀取文件,但是當我使用 IplImage * depth =(IplImage *)cvLoad(「data \\ depth \\ depthImg190.xml「);它正在正確閱讀。 – Zainb 2014-10-24 08:47:01

+0

什麼可以幫助我在這裏,我沒有得到,如果它是工作時,我給文件作爲硬代碼字符,但不只與變量工作。 – Zainb 2014-10-24 08:50:01

回答

2

其實是有一些文件,你可以使用這樣的:http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html

在任何情況下,回答你的問題很簡單:

FileStorage fs("file.xml", FileStorage::READ); 
Mat image; 

fs["depthImg190"] >> image; 

(...) 

fs.release(); 

它應該工作!

+0

嘿! 我試過這個,但是我在cv :: read,file .. \ .. \ .. \ .. \ opencv \ modules \ core \ persistence中遇到了一個錯誤 「Opencv Errorr:Bad argument .cpp,5535行「 我對opencv非常陌生,請你幫我解決這個問題嗎?我必須儘快閱讀這本XML以供我的研究。謝謝 – Zainb 2014-10-20 04:07:48

+0

我需要儘快閱讀這個xml,因爲我是opencv的新手,請指導我作爲opencv的一個非常基礎的學生。謝謝 – Zainb 2014-10-20 08:24:08

+0

如果不成功,我會請求您提供更多關於您的問題的信息,以便我們可以幫助您:您使用的代碼和xml文檔的結構。 – zedv 2014-10-20 11:47:06