2012-11-24 02:57:22 +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 urllib2
|
|
|
|
from sys import argv
|
|
|
|
|
|
|
|
def load_sample(name=None):
|
|
|
|
if len(argv) > 1:
|
|
|
|
img0 = cv.LoadImage(argv[1], cv.CV_LOAD_IMAGE_COLOR)
|
|
|
|
elif name is not None:
|
|
|
|
try:
|
|
|
|
img0 = cv.LoadImage(name, cv.CV_LOAD_IMAGE_COLOR)
|
|
|
|
except IOError:
|
2012-08-07 17:29:43 +08:00
|
|
|
urlbase = 'http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/c/'
|
2010-05-12 01:44:00 +08:00
|
|
|
file = name.split('/')[-1]
|
|
|
|
filedata = urllib2.urlopen(urlbase+file).read()
|
|
|
|
imagefiledata = cv.CreateMatHeader(1, len(filedata), cv.CV_8UC1)
|
|
|
|
cv.SetData(imagefiledata, filedata, len(filedata))
|
|
|
|
img0 = cv.DecodeImage(imagefiledata, cv.CV_LOAD_IMAGE_COLOR)
|
|
|
|
return img0
|