def url_to_image ( url , flag = cv2 . IMREAD_COLOR ) : resp = urlopen ( url ) image = np . asarray ( bytearray ( resp . read ( ) ) , dtype = "uint8" ) image = cv2 . imdecode ( image , flag ) return image
opencv python read image from url
download the image convert it to a NumPy array and then read it into OpenCV format
def url_to_image(url, flag=cv2.IMREAD_COLOR):
    """ download the image, convert it to a NumPy array, and then read
    it into OpenCV format """
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, flag)
    return image