I want to display a numpy ndarray in wxpython but somehow I can't get it to work...
My image control:
self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img))
My image code:
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)
This results in the following error:
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
It would be great if anybody could help!
Kind regards, m