Python: "Draw" with the mouse into a Numpy array -
for purpose of demonstrating handwritten digit recognition system, want able draw digits mouse in python 3 application. drawings must end gray scale raster images in 28-by-28 numpy array.
since digits must resemble digits mnist dataset , therefore can't aliased, it's best if can draw thick strokes on large canvas, read image numpy array , downsample it.
how can accomplish this?
edit: initially, considered using tkinter canvas drawing, there seems no way rasterized version of tkinter canvas drawing.
ok, wasn't able solve tkinter.
however, found this question. turns out possible qt using python bindings provided pyside (pyqt have worked). class qimage
contains method called constbits
returns memory view of pixel data. can turned numpy array using numpy.asarray
.
while qimage instance isn't widget object , hence never rendered qt, can drawn ordinary qwidget
object. if qwidget
subclassed, methods mousepressevent
, mousemoveevent
, mousereleaseevent
can overridden in subclass , made draw example qpainterpath in qimage
object, done here.
Comments
Post a Comment