commit 940aa2374b43723c44699751bc8b4f84bedf72ff
parent 83be67cc65b966ce7866d79d4756e355f51bb9e4
Author: Marcel <MTRNord@users.noreply.github.com>
Date: Fri, 7 Oct 2016 06:46:05 +0200
Update download-image-by-link.py
Diffstat:
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/scripts/download-image-by-link.py b/scripts/download-image-by-link.py
@@ -7,7 +7,7 @@ import numpy as np
import os
def store_raw_images():
- neg_images_link = 'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n07942152'
+ neg_images_link = 'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n00523513'
neg_image_urls = urllib.urlopen(neg_images_link).read().decode()
pic_num = 1
@@ -25,23 +25,28 @@ def store_raw_images():
pic_num += 1
except Exception as e:
- print(str(e))
+ print str(e)
-def find_uglies():
- match = False
- for file_type in ['neg']:
- for img in os.listdir(file_type):
- for ugly in os.listdir('uglies'):
- try:
- current_image_path = str(file_type)+'/'+str(img)
- ugly = cv2.imread('uglies/'+str(ugly))
- question = cv2.imread(current_image_path)
- if ugly.shape == question.shape and not(np.bitwise_xor(ugly,question).any()):
- print('That is one ugly pic! Deleting!')
- print(current_image_path)
- os.remove(current_image_path)
- except Exception as e:
- print(str(e))
+def store_raw_images2():
+ neg_images_link = 'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n07942152'
+ neg_image_urls = urllib.urlopen(neg_images_link).read().decode()
+ pic_num = len([name for name in os.listdir('neg') if os.path.isfile(name)])+1
+
+ if not os.path.exists('neg'):
+ os.makedirs('neg')
+
+ for i in neg_image_urls.split('\n'):
+ try:
+ i
+ urllib.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)
def create_pos_n_neg():
for file_type in ['neg']:
@@ -58,5 +63,5 @@ def create_pos_n_neg():
f.write(line)
store_raw_images()
-find_uglies()
+store_raw_images2()
create_pos_n_neg()