From 08e4382b667ef7106c8ea7662d1738815e791195 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Thu, 21 Aug 2014 23:20:30 +0200 Subject: [PATCH] Add Image.toqimage(). --- pixelocr/gui/pageview.py | 11 +---------- pixelocr/image.py | 9 +++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pixelocr/gui/pageview.py b/pixelocr/gui/pageview.py index fb8c7cd..0a4604e 100644 --- a/pixelocr/gui/pageview.py +++ b/pixelocr/gui/pageview.py @@ -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 diff --git a/pixelocr/image.py b/pixelocr/image.py index 1d6da27..427ae08 100644 --- a/pixelocr/image.py +++ b/pixelocr/image.py @@ -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])