Pygame使用SimpleCV库findBlob函数时出现分段错误
我一直在使用 SimpleCV 来查找与自动驾驶机器人一起使用的 blob。问题是当我在 SimpleCV 中调用 findBlobs 命令时。当我完全遮挡 Kinect 相机的镜头时,PyGame 崩溃并给出以下错误:
Fatal Python error: (pygame parachute) Segmentation Failure
有时它可以工作,有时它只是崩溃,即使镜头未被遮挡。当我运行它超过大约三十秒时,它几乎总是会崩溃。 我已经重新安装并修复了 SimpleCV 中的许多问题,并尝试重新安装 Pygame,但它似乎根本没有帮助。另外,我使用 X-Box kinect 作为我的相机源。我使用的是 Ubuntu 11.04。
这是我的确切代码:
from SimpleCV import *
from SimpleCV.Display import *
from time import sleep
k = Kinect()
dis = Display()
while 1:
depth = k.getDepth()
depth = depth.invert()
depth = depth.erode()
blobs = depth.findBlobs(threshval=127, minsize=10, maxsize=0)
if blobs:
blobs.draw()
depth.save(dis)
sleep(0)
I have been using SimpleCV for find blobs to be used with a self-driving robot. The problem is when I call the findBlobs command in SimpleCV. When I completely block the lens of the Kinect Camera, PyGame crashes giving me this error:
Fatal Python error: (pygame parachute) Segmentation Fault
Sometimes it works and other times it just crashes, even when the lens is unblocked. It will almost always crash when i run it for longer than about thirty seconds.
I have re-installed and fixed many problems in SimpleCV and tried re-installing Pygame and it doesn't seem to help at all. Also, I am using the X-Box kinect as my camera source. I'm using Ubuntu 11.04.
Here is my exact code:
from SimpleCV import *
from SimpleCV.Display import *
from time import sleep
k = Kinect()
dis = Display()
while 1:
depth = k.getDepth()
depth = depth.invert()
depth = depth.erode()
blobs = depth.findBlobs(threshval=127, minsize=10, maxsize=0)
if blobs:
blobs.draw()
depth.save(dis)
sleep(0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Kat 在这里,我编写了 SimpleCV blob 库。
在发布 1.1 版本后,我们发现 blob 库存在一些问题。两个大问题是 blob 库会达到 python 最大递归深度并退出。第二个源于实际的底层 OpenCV 包装器,当 blob 生成器未检测到 blob 时,会导致 pygame 错误。
现在的解决方案是使用 github 存储库的 master 分支中的版本。修补版本也将在本月晚些时候发布的新 SimpleCV 1.2 版本中提供。如果您想手动修复代码,我已粘贴下面的修复代码片段:
在 BlobMaker.py 中第 55 行左右
Kat here, I wrote the SimpleCV blob library.
There were a couple issues with the blob library that we found after we shipped the 1.1 release. The two big ones were that the blob library would hit the python max recursion depth and bail out. The second one stems from the actual underlying OpenCV wrapper and causes the pygame error when there are no blobs are detected by the blob maker.
The solution right now is to use the version that is in the master branch of our github repo. The patched version will also be available in the new SimpleCV 1.2 release which is slated for later this month. If you want to manually fix the code I have pasted the fixed snippet below:
In BlobMaker.py around line 55
Anthony 是 SimpleCV 的开发者之一:
您可以尝试更改最后一行:
只是为了看看是否存在某种类型的问题导致处理速度不够快。我最近升级到 Ubuntu 11.04,我认为有一些自 10.10 以来出现的 python bug 我需要解决。
另外,如果您可以将其发布到我们的问题队列中,我将不胜感激:
http://github.com/ingenuitas/SimpleCV/issues
Anthony one of the SimpleCV developers here:
Can you try changing the last line:
Just to see if there is some type of issue going on where it can't process fast enough. I recently upgraded to Ubuntu 11.04 and I think there are a couple of python bugs I need to squash that popped up since 10.10.
Also if you could post this to our issue queue I would appreciate it:
http://github.com/ingenuitas/SimpleCV/issues
这意味着某些代码崩溃了,现在你需要调试它来查找问题。我假设你正在学习一些东西;不妨学习如何调试;-)
这些是堆损坏或数据争用的典型症状。
你为什么认为会呢?您的问题根本看起来不像是安装问题。
因此,您要做的就是:Linux 上用于调试堆损坏问题的工具是 valgrind。像这样运行它:
不幸的是,默认的Python安装不是Valgrind友好的,上面的命令可能会产生很多“未初始化的内存读取”错误。您需要使用此抑制 文件。
可以集中精力处理包含非 Python 部分(尤其是 SimpleCV)的错误。您正在寻找
无效的{read,write} ...块后的N个字节...
。如果您发现这样的错误,您可以尝试使用 GDB 进一步调试它,或者将其报告给 SimpleCV 开发人员并希望得到最好的结果。
如果没有发现错误,您可以构建一个 Valgrind 友好版本的 Python (说明),然后重试。
如果上面的运行是 Valgrind 干净的,那么您可能会遇到竞争而不是堆损坏。使用 ThreadSanitizer 重复此操作。
This means that some code crashed, and now you need to debug it to find the problem. I assume you are learning something; might as well learn how to debug ;-)
These are classic symptoms of heap corruption, or a data race.
Why did you think it would? Your problem does not at all look like an installation problem.
So here is what you do: the tool for debugging heap corruption problems on Linux is valgrind. Run it like this:
Unfortunately, default Python installation is not Valgrind-friendly, and above command will likely produce a lot of "uninitialized memory read" errors. You'll want to suppress most of them using this suppression file.
It may be possible to concentrate on errors that contain non-Python parts (and SimpleCV in particular). You are looking for
invalid {read,write} ... N bytes after block ...
.If you find such an error, you can try to debug it further with GDB, or report it to SimpleCV developers and hope for the best.
If you don't find the error, you can build a Valgrind-friendly version of Python (instructions), and try again.
If above run is Valgrind-clean, then you may have a race rather than heap corruption. Repeat with ThreadSanitizer.
只需将您的斑点阈值替换为“-1”即可;我遇到了同样的问题,这解决了它。
Just replace your blob threshold with "-1"; I had the same problem and this fixed it.