commit 472ab468deb8b3fc65c0ce871fdf775bbf954355
parent 3f7bfcb9b4b59ee0f9312b2f5ce177686e855e38
Author: Marcel <MTRNord@users.noreply.github.com>
Date: Wed, 5 Oct 2016 21:45:08 +0200
Create download-image-by-link.py
Diffstat:
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/scripts/download-image-by-link.py b/scripts/download-image-by-link.py
@@ -0,0 +1,25 @@
+import urllib.request
+import cv2
+import numpy as np
+import os
+
+def store_raw_images():
+ neg_images_link = '//image-net.org/api/text/imagenet.synset.geturls?wnid=n04096066'
+ neg_image_urls = urllib.request.urlopen(neg_images_link).read().decode()
+ pic_num = 1
+
+ if not os.path.exists('neg'):
+ os.makedirs('neg')
+
+ for i in neg_image_urls.split('\n'):
+ try:
+ print(i)
+ urllib.request.urlretrieve(i, "neg/"+str(pic_num)+".jpg")
+ img = cv2.imread("neg/"+str(pic_num)+".jpg",cv2.IMREAD_GRAYSCALE)
+ # should be larger than samples / pos pic (so we can place our image on it)
+ resized_image = cv2.resize(img, (100, 100))
+ cv2.imwrite("neg/"+str(pic_num)+".jpg",resized_image)
+ pic_num += 1
+
+ except Exception as e:
+ print(str(e))