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
|
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):
|
class PageScene(QGraphicsScene):
|
||||||
page = None
|
page = None
|
||||||
pageItem = None
|
pageItem = None
|
||||||
|
|
@ -87,7 +78,7 @@ class PageScene(QGraphicsScene):
|
||||||
self.addLine(line.left, line.baseline, line.right, line.baseline, self.linePen)
|
self.addLine(line.left, line.baseline, line.right, line.baseline, self.linePen)
|
||||||
|
|
||||||
def addPage(self, page):
|
def addPage(self, page):
|
||||||
qimage = ndimage2qimage(page.image.data)
|
qimage = page.image.toqimage()
|
||||||
graphicsitem = self.addPixmap(QPixmap.fromImage(qimage))
|
graphicsitem = self.addPixmap(QPixmap.fromImage(qimage))
|
||||||
return graphicsitem
|
return graphicsitem
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,15 @@ class Image(object):
|
||||||
array = np.fromstring(data, dtype=np.uint8).reshape(shape)
|
array = np.fromstring(data, dtype=np.uint8).reshape(shape)
|
||||||
return cls(array)
|
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):
|
def unframe(self, width=2):
|
||||||
return Image(self.data[width:-width,width:-width])
|
return Image(self.data[width:-width,width:-width])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue