使用Python加载OpenCV XML文件时出错 [英] Error loading OpenCV XML file with Python

查看:229
本文介绍了使用Python加载OpenCV XML文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenCV 2.4.1和Python 2.7(在Visual Studio Python工具下运行的EPD 7.3).我正在尝试使用OpenCV Load()函数读取xml文件:

I'm using OpenCV 2.4.1 and Python 2.7 (Enthought EPD 7.3 running under Visual Studio Python Tools). I'm trying to read an xml file using OpenCV Load() function:

import cv2
import numpy as np

reprojectionError=cv2.Load("calib.xml")

但我遇到此错误:

    reprojectionError=cv2.Load("calib.xml")
AttributeError: 'module' object has no attribute 'Load'
Press any key to continue . . .

有什么想法吗?

推荐答案

我也遇到了相同的错误.搜索之后,我在OpenCV Bug Tracker中找到了有关它的讨论.从他们的讨论中,我了解的是(当然,很多事情我无法理解,例如某些编码等),OpenCV仅加载有效的xml文件.

I too had the same error. After searching, I found out some discussion on it in OpenCV bug tracker. From their discussion, what I understood is (of course there are lot of things i couldn't understand like some encoding etc), OpenCV load only valid xml file.

有效的意思是,它应该是一些OpenCV结构,例如IplImage,cvSeq等.否则会引发一些错误.

Valid means, it should be some OpenCV structures like IplImage, cvSeq etc. Otherwise it throws some errors.

当我尝试加载haarcascade xml文件时,它返回NULL.

When I tried to load a haarcascade xml file, It returned NULL.

TypeError: OpenCV returned NULL

当我尝试加载任意xml时(从某处获取,与OpenCV不相关):

When I tried to load some arbitrary xml, (got from somewhere,not related to OpenCV):

error: The node does not represent a user object (unknown type?)

最后,我加载了一个图像,使用cv.Save将其保存在xml文件中,并尝试按以下方式加载它:

Finally, I loaded an image, saved it in xml file using cv.Save, and tried to load it as follows :

import cv2
import numpy as np

img = cv2.cv.LoadImage('0.jpg',0)
cv2.cv.Save('sof.xml',img)
e=cv2.cv.Load("sof.xml")

print e

我得到以下结果,这是正确的:

And I got the following result, which is correct :

<iplimage(nChannels=1 width=300 height=300 widthStep=300 )>

因此,从这些示例和错误跟踪器的讨论中我了解到,OpenCV仅加载其中具有有效OpenCV结构的xml文件. (这是一个不错的选择.为什么OpenCV应该尝试将所有xml文件加载到那里?它只需要打开与之相关的文件即可.)

So what I understood from these examples and discussions on bug tracker is that OpenCV loads only xml files with valid OpenCV structures in it. (And it is a good option. Why should OpenCV try to load all the xml files out there? It have to open only files related to it).

这就是我所知道的.希望对您有帮助!

This is what i know about this. Hope it helps !!!

这篇关于使用Python加载OpenCV XML文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆