August 3, 2016
作者:dengshuai_super
出处:http://blog.csdn.net/dengshuai_super/article/details/52069634
声明:转载请注明作者及出处。
注意⚠️:此问题还不算解决,只是暂时用了别人的库,以后解决了,会回来记录。因为我是做笔记,所以建议大家直接看文章最后。
Opencv3.1.0 , Ubuntu16.04 ,开发板Microzed和Zedboard都试过了,出现同样问题。
charVec size:101
file /home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp, line 2197 terminate called after throwing an instance of 'cv::Exception'
what():/home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp:2197:error:(-212) /mnt/PRTest/resources/model/ann.xml(1):
There should be space between attributes in function icvXMLParseTag
http://www.th7.cn/Program/cp/201605/851893.shtml
/** @brief Loads algorithm from the file
@param filename Name of the file to read.
@param objname The optional name of the node to read (if empty, the first top-level node will be used)
This is static template method of Algorithm. It's usage is following (in the case of SVM):
@code
Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml");
@endcode
In order to make this method work, the derived class must overwrite Algorithm::read(const
FileNode& fn).
*/
template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String())
{
FileStorage fs(filename, FileStorage::READ);
FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
Ptr<_Tp> obj = _Tp::create();
obj->read(fn);
return !obj->empty() ? obj : Ptr<_Tp>();
}
/** @brief Reads algorithm parameters from a file storage
*/
virtual void read(const FileNode& fn) { (void)fn; }
/** @brief Reads algorithm from the file node
This is static template method of Algorithm. It's usage is following (in the case of SVM):
@code
Ptr<SVM> svm = Algorithm::read<SVM>(fn);
@endcode
In order to make this method work, the derived class must overwrite Algorithm::read(const
FileNode& fn) and also have static create() method without parameters
(or with all the optional parameters)
*/
template<typename _Tp> static Ptr<_Tp> read(const FileNode& fn)
{
Ptr<_Tp> obj = _Tp::create();
obj->read(fn);
return !obj->empty() ? obj : Ptr<_Tp>();
}
猜测一:xml本身出现了错误
Ubuntu 里面:/home/ds/桌面/EasyPR-master/resources/model/ann.xml
<?xml version="1.0"?>
<!opencv_storage>
<opencv_ml_ann_mlp>
<format>3</format>
<layer_sizes>120 40 65</layer_sizes>
<activation_function>SIGMOID_SYM</activation_function>
<f_param1>1.</f_param1>
<f_param2>1.</f_param2>
我故意把第二行加了一个”!”,Ubuntu里运行程序:出现:
OpenCV Error: Parsing error (resources/model/ann.xml(2):
file /home/ds/opencv-3.1.0/modules/core/src/persistence.cpp,
line 2249 terminate called after throwing an instance of 'cv::Exception'
what(): /home/ds/opencv-3.1.0/modules/core/src/persistence.cpp:2249:
error: (-212) resources/model/ann.xml(2):
<opencv_storage> tag is missing in function icvXMLParse
在已经做好opencv移植的arm linux里面运行,出现:
OpenCV Error: Parsing error (resources/model/ann.xml(1):
There should be space between attributes) in icvXMLParseTag,
file /home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp, line 2197 what():
/home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp:2197: error: (-212) resources/model/ann.xml(1):
There should be space between attributes in function icvXMLParseTag
然后我只把ann.xml 的第一行改为
<?xml version !="1.0"?>
在arm linux 报错和Ubuntu 上一样:
OpenCV Error: Parsing error (resources/model/ann.xml(1): Attribute name should be followed by '=') in icvXMLParseTag,
file /home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp,
line 2149 terminate called after throwing an instance of 'cv::Exception' what():
/home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp:2149:
error: (-212) resources/model/ann.xml(1): Attribute name should be followed by '=' in function icvXMLParseTag
我把ann.xml 的第一行改为
<?xml version = "1.0" >
arm linux显示错误:
OpenCV Error: Parsing error (resources/model/ann.xml(1):
There should be space between attributes) in icvXMLParseTag,
file /home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp,
line 2197 terminate called after throwing an instance of 'cv::Exception' what(): /home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp:2197:
error: (-212) resources/model/ann.xml(1):
There should be space between attributes in function icvXMLParseTag
结果arm上没检测出最右边?的问题,Ubuntu检测出来了。
于是我用opencv官方的例子人脸识别的那个(FaceDetection),在Ubuntu上可以顺利跑起来,移植到arm 上之后,出现了同样的问题:
WARNING: Could not load classifier cascade for nested objects OpenCV Error:
There should be space between attributes) in icvXMLParseTag,
file /home/ds/build/opencv3.1.0/modules/core/src/persistence.cpp, line 2197
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ds/build/opencv-3.1.0/modules/core/src/persistence.cpp:2197: error: (-212) haarcascade_frontalface_alt.xml(1):
There should be space between attributes in function icvXMLParseTag
Aborted
说明这是通性的问题,正确的在Ubuntu上可以用的xml,移植到开发板上的arm linux里面时,就会出现
There should be space between attributes in function icvXMLParseTag
的问题。
猜测二:是arm上解析出现问题
开始时我怀疑是缺少libxml2库的问题导致了解析失败:(其实后来发现opencv是用自己的解析函数来解析xml)
于是我用ldd命令看Ubuntu程序链接了哪些库:
其中发现了xml2
ldd demo_linux_amd64
打印出:
linux-vdso.so.1 => (0x00007ffdeb3b3000)
`libopencv_world.so.3.1 => /usr/local/lib/libopencv_world.so.3.1 (0x00007f62e0ffe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f62e0c61000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f62e0957000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f62e0741000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f62e0378000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f62e015d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f62dff59000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f62dfd3c000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f62dfb33000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f62df90e000)`
libgtk-3.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007f62defdf000)
libgdk-3.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-3.so.0 (0x00007f62ded03000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f62de9ef000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f62de7cd000)
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f62de579000)
`libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f62de268000)`
libavcodec-ffmpeg.so.56 => /usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56 (0x00007f62dce3e000)
libavformat-ffmpeg.so.56 => /usr/lib/x86_64-linux-gnu/libavformat-ffmpeg.so.56 (0x00007f62dca40000)
libavutil-ffmpeg.so.54 => /usr/lib/x86_64-linux-gnu/libavutil-ffmpeg.so.54 (0x00007f62dc7d1000)
libswscale-ffmpeg.so.3 => /usr/lib/x86_64-linux-gnu/libswscale-ffmpeg.so.3 (0x00007f62dc542000)
`/lib64/ld-linux-x86-64.so.2 (0x0000561e16755000)`
libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f62dc33d000)
libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f62dc130000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.