url = 'http://www.xxxx.1.jpg'
fobj = urllib2.urlopen(url).read()
f = open('1.jpg','wb')
f.write(fobj)
img = cv2.imread('1.jpg')
Can I have any better way?I don't want to save file everytime!
You can use cv2.imdecode() to directly read the image data. But it needs to be transformed into a numpy.ndarray first:
jpeg_array = bytearray(fobj)
img = cv2.imdecode(np.asarray(jpeg_array), cv2.CV_LOAD_IMAGE_COLOR)