Create a basic Python interface to save images drawn with a mouse - python

I am working on the following project and I am having really difficulties in finding the right way of doing that. I would like to build in Python (but I am open to other possibilities) a very basic interface that allows the user to draw with the mouse (or the pen if used on a surface laptop) something and then save the image. Ideally I would like this to work on a website or at least in a jupyter notebook (at least I imagine this to be utterly difficult).
Anyone can point me in the right direction? The goal would be to use the images as input to a neural network model to demonstrate its result with real life examples.
I am looking at tk but I don't seem to find much in terms of examples.
Thanks in advance, Umberto

I'd take a look at pyautogui to capture the mouse location then "draw" it in matplotlib -- should be able to do this in a loop. You'll want to watch the tkinter window size to sync the mouse coordinates with the relative location.
Why not just have your script open create a new blank img and automatically open it with paint - then read it on close? Seems easier than creating a drawing GUI.

Have a look at my Github repository which have exactly what you need.
Link : CanvasDraw Repo

Depending on the complexity you could either use tkinter which is a package for complex GUIs or something from the gaming community like pygames. You have user input and graphical output so libraries made for games will do what you want but provide way more stuff then you need. This site might help you: Drawing Libarys
Also the answere draw-on-python-tkinter-canvas-using-mouse-and-obtain-points-to-a-list might help you.

Related

VTK Render Mouse Interaction (Python)

I want to visualize one or more STL file(s) using a vtk render viewport inside my application. I was able to get it all running with this example here: https://kitware.github.io/vtk-examples/site/Python/IO/ReadSTL/
My question is as follows: I have a mouse to control it and it is just unbelievable how bad default the controls of the camera are. It is almost impossible to get the model rotated intentionally or focus on a certain part. I am confused as I could not find any topic here or elsewhere discussing this. Normally I would read through other threads to find an answer, but there doesn't seem to be any. So, maybe you can point me to an approach or even certain functions of how I can change these settings, that would be really great! Basically I want to mimic the camera behavior of say, Paraview or a common CAD tool. Like zooming with mouse wheel, rotating with RMB and holding down the wheel to pan.
Some background on my project: I have written a python program and created a quite ok UI using tkinter. However, recently I was thinking of rewriting some basic parts of it and also upgrading everything visually and in terms of handling. So, I want to move to Qt widgets and, there shall be a VTK rendering viewport inside my application to show some of the stuff that can be interacted with.
I was able to find a solution in the tutorials. By explicitly defining the vtkInteractorStyle with
style = vtk.vtkInteractorStyleTrackballCamera()
The handling is just as I wanted it to be.

Drag and drop files in Tkinter GUI

I am fairly new to Python and is stuck at a problem. I am using Python 3.7 and intend to add a "drag-and-drop" functionality to my GUI.
I have some files that needs to be read, thus i am looking for an option where i can simply drag those files to a particular area in my GUI and file name or Path is read by my program.
Being a newbie a detailed answer or a code would be highly helpful.
Thanks
Unfortunately, tkinter only supports experimental widget drag and drop, nothing else. I ran into similar problems trying to make a complex GUI.
I would look into wxPython. It's complex, Object Oriented, and daunting, but has and unbelievable amount of features that reward you for learning it. Including file drag and drop.
Look at the wxPython thumbnails at https://wxpython.org/Phoenix/docs/html/gallery.html for images of what the widgets look like. The thumbnails include images for about half of the available widgets. The images are also a bit out of date.
Look at pronounced https://pythonlibrary.org or https://zetcode.com for the best tutorials. After them, your best resource is Google and the forums.

Click automatically in specific points after recognition of text

I am using MATLAB and SIMULINK and there is something missing there that is driving me crazy, but the question is not MATLAB-related.
At a certain point I have a window like that:
I would like to have the SELECT ALL button. I don't know why, but since a lot of years I am asking this feature to MathWorks but they don't implement it.
Anyway, I decided to do a workaround by myself.
I want to make a small script in Python which detect the text 'Tunable' and after it clicks automatically on ALL the checkboxes.
Is it possible to do it in Python ?
I found a solution to my problem.
If you are interested you can look at it in this video:
VIDEO YOUTUBE
I am happy to share ideas and to know your opinion.

How to code a wxPython GUI program for orientating disks in a cube?

I am a geology student and am trying to come up with a program for illustrating joint networks in rock masses.
Basically I just need wxPython script, or any snippets of script that would be able to create a GUI program which displays a number of disks inside a box, with the parameters (ie relative position, orientation and radius) of the disks being input at the beginning. Does anyone know of any script like that, or if thats even possible? My problem is that this is for my thesis, and although I have dabbled in Python before, not on anything anywhere near as complex as this, and certainly not GUI. I literally don't even know where to begin trying to display geometric shapes.
I unfortunately don't have the time to learn enough wxPython to do this, I'm looking for any pre-written example code. I have downloaded wxPython and have done some tutorials on creating message windows etc but now I'm not sure where to look for help now. Any advice/tips/code at ALL would be greatly appreciated, I am desperate for help!
I'm not sure I understand exactly what you are trying to do here. Are you creating an interactive GUI or just a visualization? It sounds like you want something in 3D. In that can you should check out VPython which has some tutorials and demo code. Also much more powerful is PyOpenGL. For something and actual 2D user interface in wxPython you should really look through the demo code included with wxPython. There is quite a nice library of complete examples with source code that you can just copy and modify. I am pretty sure there are some examples for drawing polygons of arbitrary size/shape.

Python: OSX Library for fast full screen jpg/png display

Frustrated by lack of a simple ACDSee equivalent for OS X, I'm looking to hack one up for myself. I'm looking for a gui library that accommodates:
Full screen image display
High quality image fit-to-screen (for display)
Low memory usage
Fast display
Reasonable learning curve (the simpler the better)
Looks like there are several choices, so which is the best? Here are some I've run across:
PyOpenGL
PyGame
PyQT
wxpython
I don't have any particular experience with any of these, nor any strong desire to become an expert - I'm looking for the simplest solution.
What do you recommend?
[Update]
For those not familiar with ACDSee, here's what it does that I care about:
Simple list/thubmnail display of images in a directory
Sort by name/size/type
Ability to view images full screen
Single-key delete while viewing full screen
Move to next/previous image while viewing full screen
Ability to select a group of images for:
move to / copy to directory
delete
resize
ACDSee has a bunch of niceties as well, such as remembering directories you've moved images to in the past, remembering your resize settings, displaying the total size of the images you've selected, etc.
I've tried most of the options I could find (including Xee) and none of them quite get there. Please keep in mind that this is a programming/library question, not a criticism of any of the existing tools.
I will recommend using wxPython to create such a viewer, wxPython is easy to learn, free, cross platform and blends well in OSX. Even if you want to use pyopengl, wxPython would be good with pyopengl.
see such tutorials http://showmedo.com/videotutorials/video?name=1790000&fromSeriesID=179
and there is already cornice written in wxpython/PIL, may be you can modify that. It has been inspired by the famous Windows-only ACDSee :)
it's not an answer to your coding question but for (a big part of) the lack of ACDsee equivalent (requires OSX 10.5+):
Simple list/thubmnail display of images in a directory: Finder.app
Sort by name/size/type: Finder.app will do name & type, not image size (but does file size)
Ability to view images full screen: quick preview (spacebar / eye icon)
Single-key delete while viewing full screen: command-backspace while viewing in quickpreview, both windowed and fullscreen
Move to next/previous image while viewing full screen: both quickprewiew (after selecting a group of images or whole directory with cmd-a) and Preview.app
Ability to select a group of images for[...]: Finder.app will does all but resize
seems like you have everything except resize just pressing the spacebar while in finder.
Preview.app will resize both a single image or multiple ones in one batch.
Use an App like Picasa (now available on mac). Use AppleScript through Python to control it from your application.
Failing that, use PyObjC to create Cocoa image display component and dialogs, and so on.
I ended up using PyGame, has been pretty good so far.

Categories

Resources