使用 OpenCV Camera Capture 在 PyQt4 中显示网络摄像头流
我正在使用这个 Python 脚本来显示我的网络摄像头:
from opencv.cv import *
from opencv.highgui import *
import sys
cvNamedWindow("w1", CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cvCreateCameraCapture(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
frame = cvQueryFrame(capture)
cvShowImage("w1", frame)
c = cvWaitKey(10)
if c == "q":
sys.exit(0)
if __name__ == "__main__":
while True:
repeat()
它工作得很好,但我想在我的 Qt 应用程序中设置此显示。 如何将 IplImage
OpenCV 图像使用到 Qt VideoWidget
中?
I am using this Python script to display my webcam:
from opencv.cv import *
from opencv.highgui import *
import sys
cvNamedWindow("w1", CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cvCreateCameraCapture(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
frame = cvQueryFrame(capture)
cvShowImage("w1", frame)
c = cvWaitKey(10)
if c == "q":
sys.exit(0)
if __name__ == "__main__":
while True:
repeat()
It is working quite well, but I would like to set this display inside my Qt application.
How can I use the IplImage
OpenCV image into a Qt VideoWidget
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来我们需要在 Python 中绑定这个 C++ 代码:
It looks like we need to bind this C++ code in Python :
我使用下面的代码将 Iplimage 对象转换为 QImage。我花了一些时间才获得正确的格式。 Iplimage 是具有 BGR 通道顺序的 3 通道格式,而 QImage 使用 RGB 通道顺序。
I used the code bellow to covert a Iplimage objet to a QImage. It took me some time to get the right formats. Iplimage is a 3-channel format with BGR channel order while QImage uses RGB channel order.
这对我有用。我在 Linux 上使用 Python 2.6.5 工作:
This one worked for me. I work on Linux with Python 2.6.5: