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.
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.
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).
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.
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.
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