def url_to_img_array(url):
if not isinstance(url, basestring):
logging.warning("input is neither an ndarray nor a string, so I don't know what to do")
return None
# replace_https_with_http:
if 'http' in url and 'https' not in url:
url = url.replace("https", "http")
try:
headers = {'User-Agent': USER_AGENT}
response = requests.get(url, headers=headers)
img_array = cv2.imdecode(np.asarray(bytearray(response.content)), 1)
except requests.ConnectionError:
logging.warning("connection error - check url or connection")
return None
except:
logging.warning(" error other than connection error - check something other than connection")
return None
return img_array
评论列表
文章目录