Dom*_*nic 5 python opencv wxpython format-conversion
这是我目前的代码(语言是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()))
Run Code Online (Sandbox Code Playgroud)
我正在尝试在wxPython窗口中显示从我的网络摄像头捕获的iplimage.问题是我不想先将图像存储在硬盘上.有没有办法将iplimage转换为内存中的另一种图像格式?还有其他方法吗?
我在其他语言中找到了一些解决这个问题的"解决方案",但我仍然遇到这个问题.
谢谢.
你要做的是:
frame = cv.QueryFrame(self.cam) # Get the frame from the camera
cv.CvtColor(frame, frame, cv.CV_BGR2RGB) # Color correction
# if you don't do this your image will be greenish
wxImage = wx.EmptyImage(frame.width, frame.height) # If your camera doesn't give
# you the stream size, you might have to use (640, 480)
wxImage.SetData(frame.tostring()) # convert from cv.iplimage to wxImage
wx.StaticBitmap(self, -1, wxImage, (0,0),
(wxImage.GetWidth(), wxImage.GetHeight()))
Run Code Online (Sandbox Code Playgroud)
我想通过查看Python OpenCV cookbook和wxPython wiki来了解如何做到这一点.
你可以用 StringIO 来做
stream = cStringIO.StringIO(data)
wxImage = wx.ImageFromStream(stream)
Run Code Online (Sandbox Code Playgroud)
您可以在 \wx\lib\embeddedimage.py 中查看更多详细信息
只是我的 2 美分。