projectstreet-detection-docker

Docker for detecting streets. (WIP)
git clone git://archive.git.mtrnord.blog/Nordgedanken/projectstreet-detection-docker.git
Log | Files | Refs | README

commit 4ce55e8977c43d55f787056ee019565bcecfa44b
parent 472ab468deb8b3fc65c0ce871fdf775bbf954355
Author: Marcel <MTRNord@users.noreply.github.com>
Date:   Wed,  5 Oct 2016 21:49:25 +0200

Update download-image-by-link.py
Diffstat:
Mscripts/download-image-by-link.py | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/scripts/download-image-by-link.py b/scripts/download-image-by-link.py @@ -1,3 +1,6 @@ +########################################################################################################## +# Code is based on: https://pythonprogramming.net/haar-cascade-object-detection-python-opencv-tutorial/ # +########################################################################################################## import urllib.request import cv2 import numpy as np @@ -23,3 +26,54 @@ def store_raw_images(): except Exception as 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_images(): + neg_images_link = '//image-net.org/api/text/imagenet.synset.geturls?wnid=n07942152' + neg_image_urls = urllib.request.urlopen(neg_images_link).read().decode() + pic_num = 953 + + 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)) + +def create_pos_n_neg(): + for file_type in ['neg']: + + for img in os.listdir(file_type): + + if file_type == 'pos': + line = file_type+'/'+img+' 1 0 0 50 50\n' + with open('info.dat','a') as f: + f.write(line) + elif file_type == 'neg': + line = file_type+'/'+img+'\n' + with open('bg.txt','a') as f: + f.write(line)