Add Image.toqimage().
This commit is contained in:
parent
48b179e2e0
commit
08e4382b66
2 changed files with 10 additions and 10 deletions
|
|
@ -37,15 +37,6 @@ import numpy as np
|
|||
from scipy.ndimage import imread
|
||||
|
||||
|
||||
def ndimage2qimage(image):
|
||||
return QImage(
|
||||
np.ascontiguousarray(image.astype(np.uint8).copy()).data,
|
||||
image.shape[1], image.shape[0],
|
||||
image.shape[1] * 3,
|
||||
QImage.Format_RGB888,
|
||||
)
|
||||
|
||||
|
||||
class PageScene(QGraphicsScene):
|
||||
page = None
|
||||
pageItem = None
|
||||
|
|
@ -87,7 +78,7 @@ class PageScene(QGraphicsScene):
|
|||
self.addLine(line.left, line.baseline, line.right, line.baseline, self.linePen)
|
||||
|
||||
def addPage(self, page):
|
||||
qimage = ndimage2qimage(page.image.data)
|
||||
qimage = page.image.toqimage()
|
||||
graphicsitem = self.addPixmap(QPixmap.fromImage(qimage))
|
||||
return graphicsitem
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,15 @@ class Image(object):
|
|||
array = np.fromstring(data, dtype=np.uint8).reshape(shape)
|
||||
return cls(array)
|
||||
|
||||
def toqimage(self):
|
||||
from PyQt4.QtGui import QImage
|
||||
return QImage(
|
||||
np.ascontiguousarray(self.data.astype(np.uint8)).data,
|
||||
self.data.shape[1], self.data.shape[0],
|
||||
self.data.shape[1] * 3,
|
||||
QImage.Format_RGB888,
|
||||
)
|
||||
|
||||
def unframe(self, width=2):
|
||||
return Image(self.data[width:-width,width:-width])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue