Tips for Python beginners to use Scikit-image examples for themselves 4 Use GUI

Tips for Python beginners to use the Scikit-image example for themselves Tips for Python beginners to use the Scikit-image example for themselves 2 Process multiple files Tips 3 for Python beginners to use Scikit-image examples for themselves Next, I will write the content for Python beginners to play with the example of Scikit-image with a slight modification.

In order for a third party to use a tool created using OpenCV-Python and Scikit-image, it is necessary to be able to start the tool using a command line interface or GUI.

** To use the command line interface **

See OpenCV for Python beginners. From the set of OpenCV downloaded while referring to it (folder of opencv_2.4) \ sources \ samples \ python2 (folder of opencv_3.1) \ sources \ samples \ python See the sample Python script at.

An example using sys.argv is a good example for using the command line interface.

filename = sys.argv[1]

Is a typical usage. If you are using cygwin etc., you can find it by typing> grep sys.argv * .py.

** To use GUI (for Tk) **

If you make it so that you can operate it only with the GUI when you double-click the icon, it will be easier for people who do not know the Python language to use it. The Python language has a GUI library called Tkinter in the standard distribution. Using this, you can easily describe the realization of a common GUI for Windows and Linux. A common situation where you want to use the GUI is when specifying input and output filenames. In the case of a script that someone will use, you will want to enter the filename in the GUI. One of the usages I often use is to create a tool created in C / C ++ language so that it works on the command line, and give the file name to the tool with tkFileDialog. filename=tkFileDialog.askopenfilename(filetypes=fTyp,initialdir=iDir) It is to get it like this. Also message tkMessageBox.showinfo ('Title','Message to display') Display with or ask YesNO questions tkMessageBox.askquestion ('Title','Question Content') I often use it. The following is an example of my typical usage (Note).

20160116a.png

20160116.png

20160116b.png Tkinter has the ability to create more sophisticated GUIs. But I'm spending time without creating such a fancy GUI.

.py:gui_example.py


# -*- coding: cp932 -*-
import sys, os, string, glob
import Tkinter
import tkMessageBox
import tkFileDialog
if __name__=='__main__':
    root=Tkinter.Tk()
    root.withdraw()

    doc=u"""Tool to display avi file
Video file to display(avi, mp4)Please specify.
"""
    tkMessageBox.showinfo('aviviewer.py',doc)
    fTyp=[('movie file','*.avi;*.mp4'),]

    filename=tkFileDialog.askopenfilename(filetypes=fTyp,
                                          initialdir='.')
    
    assert(os.path.isfile(filename))
    cmd='''aviViewer.exe "%s"''' % filename
    os.system(cmd)
    doc=u"""aviViewer.Exit py.
"""
    tkMessageBox.showinfo('aviViewer.py',doc)
    

An example of an article in Japanese tkFileDialog [Python] Try using the dialog to open a file using Tkinter (tkFileDialog).

tkMessageBox Article Displaying a MessageBox using Tkinter in Python.

Task:

Tips for Python beginners to use the Scikit-image example for themselves 2 Process multiple files Based on the example shown in, let's rewrite it to give a file by using tkFileDialog.askopenfilename () instead of for name in glob.glob ("* .jpg ") :.

Note: This is just an example for adding a GUI in Python. Since OpenCV-Python itself can read and display AVI files, there is no need to execute exe format commands. By not including the GUI in the part developed in the C / C ++ language in this way, it is possible to reduce OS dependency and dependence on commercial libraries.

** Addendum: If you want to add options to the command line **

If you want to add functionality equivalent to command line options where Unix commands start with-or- You can also use the following standard library. (However, I don't use it much in my case.)

Python standard library getopt — C-style command line option parser

Python standard library argparse — parser for command line options, arguments and subcommands

Hint 5 Incorporate into network application

Recommended Posts

Tips for Python beginners to use Scikit-image examples for themselves 4 Use GUI
Tips for Python beginners to use Scikit-image examples for themselves 3 Write to a file
Tips for Python beginners to use the Scikit-image example for themselves
Tips for Python beginners to use Scikit-image examples for themselves 5 Incorporate into network apps
Tips for Python beginners to use the Scikit-image example for themselves 9 Use from C
Tips for Python beginners to use the Scikit-image example for themselves 6 Improve Python code
Tips for Python beginners to use the Scikit-image example for themselves 2 Handle multiple files
Tips for Python beginners to use the Scikit-image example for themselves 7 How to make a module
~ Tips for beginners to Python ③ ~
Tips for Python beginners to use the Scikit-image example for themselves 8 Processing time measurement and profiler
[For beginners] How to use say command in python!
Beginners use Python for web scraping (1)
Beginners use Python for web scraping (4) ―― 1
[Python] Organizing how to use for statements
How to use "deque" for Python data
Memo # 4 for Python beginners to read "Detailed Python Grammar"
The fastest way for beginners to master Python
Python for super beginners Python for super beginners # Easy to get angry
Memo # 3 for Python beginners to read "Detailed Python Grammar"
Memo # 1 for Python beginners to read "Detailed Python Grammar"
~ Tips for Python beginners from Pythonista with love ① ~
How to use data analysis tools for beginners
Try to calculate RPN in Python (for beginners)
Memo # 2 for Python beginners to read "Detailed Python Grammar"
Memo # 7 for Python beginners to read "Detailed Python Grammar"
Introduction to Programming (Python) TA Tendency for beginners
Memo # 6 for Python beginners to read "Detailed Python Grammar"
How to make Python faster for beginners [numpy]
~ Tips for Python beginners from Pythonista with love ② ~
Memo # 5 for Python beginners to read "Detailed Python Grammar"
Tips for those who are wondering how to use is and == in Python
python textbook for beginners
OpenCV for Python beginners
[BigQuery] How to use BigQuery API for Python -Table creation-
How to convert Python # type for Python super beginners: str
[For beginners] How to study Python3 data analysis exam
Python # How to check type and type for super beginners
Beginners use Python for web scraping (4) --2 Scraping on Cloud Shell
python3: How to use bottle (2)
Learning flow for Python beginners
[python] How to use the library Matplotlib for drawing graphs
[Python] How to use list 1
[For beginners] How to use for statements on Linux (variables, etc.)
How to use Python argparse
How to learn TensorFlow for liberal arts and Python beginners
Tips for coding short and easy to read in Python
How to use machine learning for work? 03_Python coding procedure
Python3 environment construction (for beginners)
3 Reasons Beginners to Start Python
Python: How to use pydub
[Python] How to use checkio
Python #function 2 for super beginners
How to convert Python # type for Python super beginners: int, float
[For beginners] Script within 10 lines (4. Connection from python to sqlite3)
I didn't know how to use the [python] for statement
Basic Python grammar for beginners
100 Pandas knocks for Python beginners
Python for super beginners Python #functions 1
[Python] Introduction to graph creation using coronavirus data [For beginners]
[Python + Selenium] Tips for scraping
Python #list for super beginners