使用 wxPython 显示 OpenCV iplimage 数据结构
这是我当前的代码(语言是Python):
newFrameImage = cv.QueryFrame(webcam)
newFrameImageFile = cv.SaveImage("temp.jpg",newFrameImage)
wxImage = wx.Image("temp.jpg", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self, -1, wxImage, (0,0), (wxImage.GetWidth(), wxImage.GetHeight()))
我试图在wxPython窗口中显示从网络摄像头捕获的iplimage。问题是我不想先将图像存储在硬盘上。有没有办法将 iplimage 转换为内存中的另一种图像格式?还有其他解决方案吗?
我在其他语言中找到了这个问题的一些“解决方案”,但我仍然遇到这个问题。
谢谢。
Here is my current code (language is Python):
newFrameImage = cv.QueryFrame(webcam)
newFrameImageFile = cv.SaveImage("temp.jpg",newFrameImage)
wxImage = wx.Image("temp.jpg", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self, -1, wxImage, (0,0), (wxImage.GetWidth(), wxImage.GetHeight()))
I'm trying to display an iplimage captured from my webcam in a wxPython window. The problem is I don't want to store the image on hard disk first. Is there any way to convert an iplimage into another image format in memory? Any other solution?
I found a few "solutions" to this problem in other languages, but I'm still having trouble with this issue.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你要做的是:
我通过查看 Python OpenCV 食谱 以及 wxPython维基百科。
What you have to do is:
I figured oyt out how to do this by looking at the Python OpenCV cookbook and at the wxPython wiki.
是的,这个问题很老了,但我和其他人一样来到这里寻找答案。在上述解决方案之后,我想我应该分享一个使用 cv2 和 numpy 图像的快速解决方案。
这是如何将 OpenCV2 中使用的 NumPy 数组样式图像转换为位图,然后您可以将其设置为 wxPython 中的显示元素(截至今天):
10 分钟前测试:)
这使用构建的在 wx 函数 BitmapFromBuffer 中,并利用 NumPy 缓冲区接口,以便所有我们要做的就是交换颜色以使它们按预期顺序排列。
Yes, this question is old but I came here like everybody else searching for the answer. Several versions of wx, numpy, and opencv after the above solutions I figured I'd share a fast solution using cv2 and numpy images.
This is how to convert a NumPy array style image as used in OpenCV2 into a bitmap you can then set to a display element in wxPython (as of today):
Tested 10 minutes ago :)
This uses the built in wx function BitmapFromBuffer and takes advantage of the NumPy buffer interface so that all we have to do is swap the colors to get those in the expected order.
你可以用 StringIO 来做,
你可以在 \wx\lib\embeddedimage.py 中检查更多细节,
只是我的 2 美分。
You could do with StringIO
you can check more detail in \wx\lib\embeddedimage.py
just my 2 cents.