computer_science:computer_vision:opencv:object_identification_tensorflow_opencv_imageai_yolo_download_images_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
computer_science:computer_vision:opencv:object_identification_tensorflow_opencv_imageai_yolo_download_images_script [2020/08/07 16:39] – created carlossousacomputer_science:computer_vision:opencv:object_identification_tensorflow_opencv_imageai_yolo_download_images_script [2023/12/01 12:07] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Python Scripts to Download Images of Hats and People ======
 +
 This is part of the [[:computer_science:computer_vision:opencv:object_identification_tensorflow_opencv_imageai_yolo|project to identify objects with OpenCV / Tensorflow / Yolo / ImageAI]]. This is part of the [[:computer_science:computer_vision:opencv:object_identification_tensorflow_opencv_imageai_yolo|project to identify objects with OpenCV / Tensorflow / Yolo / ImageAI]].
 +
 +----
 +
 +===== Download Images of Hats =====
 +
 +download_hats_images.py
  
 <code python> <code python>
Line 15: Line 23:
 os.chdir('hardhat') os.chdir('hardhat')
 for i in hardhatImages.split('\n'): for i in hardhatImages.split('\n'):
 +    try:
 +        r = req.get(i, timeout=0.5)
 +        file = i.split("/")[-1].split('\r')[0]
 +        if 'image/jpeg' in r.headers['Content-Type']:
 +            if len(r.content)> 8192:
 +                with open(file, 'wb') as outfile:
 +                    outfile.write(r.content)
 +                    noOfImages += 1
 +                    print('Success: ' + file)
 +            else:
 +                print('Failed: ' + file + ' -- Image too small')
 +        else:
 +            print('Failed: ' + file + ' -- Not an image')
 +
 +    except Exception as e:
 +        print('Failed: ' + file + ' -- Error')
 +
 +
 +</code>
 +
 +----
 +
 +===== Download Images of People =====
 +
 +download_people_images.py
 +
 +<code python>
 +import requests as req
 +import os as os
 +
 +peopleLoc = 'http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n07942152'
 +
 +peopleImages = req.get(peopleLoc).text
 +noOfImages = 0
 +
 +if not os.path.exists('people'):
 +    os.makedirs('people')
 +
 +os.chdir('people')
 +for i in peopleImages.split('\n'):
     try:     try:
         r = req.get(i, timeout=0.5)         r = req.get(i, timeout=0.5)
Line 33: Line 81:
  
 print('*********** Download Finished **************') print('*********** Download Finished **************')
 +
  
 </code> </code>
  
  
  • computer_science/computer_vision/opencv/object_identification_tensorflow_opencv_imageai_yolo_download_images_script.1596818372.txt.gz
  • Last modified: 2023/12/01 12:07
  • (external edit)