Commit 390e41e0 authored by 赵威's avatar 赵威

update request f

parent b773aebf
...@@ -10,17 +10,20 @@ from PIL import Image ...@@ -10,17 +10,20 @@ from PIL import Image
def url_to_ndarray(url): def url_to_ndarray(url):
result = requests.get(url, timeout=30) try:
if result.ok: result = requests.get(url, timeout=30)
img = Image.open(io.BytesIO(result.content)) if result.ok:
img = img.convert("RGB") img = Image.open(io.BytesIO(result.content))
data = np.array(img) img = img.convert("RGB")
return data data = np.array(img)
else: return data
print("http get: {}".format(result.status_code)) else:
print("http get: {}".format(result.status_code))
return np.array([])
except Exception as e:
print(e)
return np.array([]) return np.array([])
def file_to_ndarray(path): def file_to_ndarray(path):
result = cv2.imread(path) result = cv2.imread(path)
img = Image.fromarray(result).convert("RGB") img = Image.fromarray(result).convert("RGB")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment