2010-05-12 01:44:00 +08:00
|
|
|
#!/usr/bin/python
|
2011-07-12 20:56:03 +08:00
|
|
|
import cv2.cv as cv
|
2010-05-12 01:44:00 +08:00
|
|
|
import sys
|
|
|
|
import urllib2
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
cv.NamedWindow("win")
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
filename = sys.argv[1]
|
|
|
|
im = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_GRAYSCALE)
|
|
|
|
im3 = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_COLOR)
|
|
|
|
else:
|
2012-02-17 16:48:06 +08:00
|
|
|
try: # try opening local copy of image
|
|
|
|
fileName = '../cpp/left01.jpg'
|
|
|
|
im = cv.LoadImageM(fileName, False)
|
|
|
|
im3 = cv.LoadImageM(fileName, True)
|
|
|
|
except: # if local copy cannot be opened, try downloading it
|
2012-08-07 17:29:43 +08:00
|
|
|
url = 'http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/left01.jpg'
|
2012-02-17 16:48:06 +08:00
|
|
|
filedata = urllib2.urlopen(url).read()
|
|
|
|
imagefiledata = cv.CreateMatHeader(1, len(filedata), cv.CV_8UC1)
|
|
|
|
cv.SetData(imagefiledata, filedata, len(filedata))
|
|
|
|
im = cv.DecodeImageM(imagefiledata, cv.CV_LOAD_IMAGE_GRAYSCALE)
|
|
|
|
im3 = cv.DecodeImageM(imagefiledata, cv.CV_LOAD_IMAGE_COLOR)
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
chessboard_dim = ( 9, 6 )
|
2012-08-07 17:29:43 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
found_all, corners = cv.FindChessboardCorners( im, chessboard_dim )
|
|
|
|
print found_all, len(corners)
|
|
|
|
|
|
|
|
cv.DrawChessboardCorners( im3, chessboard_dim, corners, found_all )
|
2012-08-07 17:29:43 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
cv.ShowImage("win", im3);
|
|
|
|
cv.WaitKey()
|
2012-03-19 07:21:54 +08:00
|
|
|
cv.DestroyAllWindows()
|