【发布时间】:2014-07-31 01:03:38
【问题描述】:
我想在 wxpython 中显示一个 numpy ndarray 但不知何故我无法让它工作......
我的图片控件:
self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))
我的图片代码:
img = cv2.imread(file, 0)
flag, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY
# thresh is an ndarray with size [60, 60]
img_wx = wx.ImageFromBuffer(thresh.shape[0], thresh.shape[1], thresh)
self.imageCtrl.SetBitmap(wx.BitmapFromImage(img_wx)
这会导致以下错误:
Traceback (most recent call last):
File "cropImagesAndLabel.py", line 114, in onStart
self.countUp()
File "cropImagesAndLabel.py", line 134, in countUp
self.crop()
File "cropImagesAndLabel.py", line 104, in crop
img = wx.ImageFromBuffer(self.pattern.shape[0], self.pattern.shape[1], self.pattern)
File "\Canopy\User\lib\site-packages\wx\_core.py", line 3598, in ImageFromBuffer
image = _core_._ImageFromBuffer(width, height, dataBuffer, alphaBuffer)
TypeError: expected a single-segment buffer object
如果有人能帮忙就太好了!
亲切的问候, 米
【问题讨论】: