OpenCVとPythonと私 vol.1
#!/usr/bin/python
import cv
from opencv import highgui
import sys
import getopt
filename = None
debug = False
def main () :
global filename
global debug
try:
opts, args = getopt.getopt( sys.argv[1:], "hd",["help","debug"])
except getopt.GetoptError, err :
print str( err )
usage()
sys.exit(2)
if len( args ) != 0 :
filename = args[0]
else :
usage()
sys.exit(0)
for o, a in opts :
if o in ( "-h", "--help" ) :
usage()
sys.exit(0)
elif o in ( "-d", "--debug" ) :
debug = True
else :
assert False, "unhandled option"
def debugout ( str ) :
if debug == True :
print str
def usage () :
print "Usage: showImage.py [OPTION] FILE"
print " "
rint " -h, --help Display this message."
print " -d, --debug Output debug log."
if __name__ == "__main__" :
main()
debugout( "Input file name is " + filename )
img = cv.LoadImageM( filename )
cv.NamedWindow( "test", cv.CV_WINDOW_AUTOSIZE )
cv.MoveWindow( "test", 100, 100)
cv.ShowImage( "test", img )
print "Hit any key."
cv.WaitKey( 0 )
cv.DestroyWindow( "test" )