尝试使用 OpenCV 保存网络摄像头图片时出错
import cv
capture = cv.CaptureFromCAM(0)
img = cv.QueryFrame(capture)
cv.SaveImage("test.JPG", img)
你好, 我只想在 Ubuntu 10 上使用 OpenCv 和 Python 保存网络摄像头的图片。 OpenCv 可以连接网络摄像头。
但我收到这个错误:
OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /build/buildd/opencv-2.1.0/src/cxcore/cxarray.cpp, line 2376
Traceback (most recent call last):
File "video.py", line 5, in <module>
cv.SaveImage("test.JPG", img)
cv.error: NULL array pointer is passed
import cv
capture = cv.CaptureFromCAM(0)
img = cv.QueryFrame(capture)
cv.SaveImage("test.JPG", img)
Hi,
I just want to save a picture from my webcam with OpenCv and Python on my Ubuntu 10.
OpenCv can connect with the webcam.
But I get this error:
OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /build/buildd/opencv-2.1.0/src/cxcore/cxarray.cpp, line 2376
Traceback (most recent call last):
File "video.py", line 5, in <module>
cv.SaveImage("test.JPG", img)
cv.error: NULL array pointer is passed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 SimpleCV,省去急诊室的麻烦。它是 OpenCV 的 Python 绑定和其他一些工具的 Pythonic 包装器(它使用 Numpy、Scipy 和 PIL):
Save yourself a trip to the emergency room and use SimpleCV. It's a Pythonic wrapper for OpenCV's Python bindings and a few more tools (it uses Numpy, Scipy and PIL):
我一遍又一遍地看到这个错误:
CaptureFromCAM()
调用失败,这意味着QueryFrame()
失败并返回 NULL图像,导致 SaveImage() 也失败。这里需要考虑两件事:
1)您的网络摄像头可能不是索引 0(尝试 -1 或 1)
2)学习安全编码!始终检查正在调用的函数的返回。这种做法将来会为您节省大量时间:
I see this mistake over and over and over and over again: the
CaptureFromCAM()
call is failing, which means thatQueryFrame()
is failing as a consequence and returning NULL as image, causingSaveImage()
to fail as well.Two things that you need to take into consideration here:
1) your webcam might not be index 0 (try -1, or 1)
2) learn to code safely! Always check the return of the functions that are being called. This practice will save you a lot of time in the future: