computer_science:computer_vision:opencv:object_identification_tensorflow_opencv_imageai_yolo_download_images_script

This is an old revision of the document!


This is part of the project to identify objects with OpenCV / Tensorflow / Yolo / ImageAI.

import requests as req
import os as os
 
hardhatLoc = 'http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n03492922'
 
hardhatImages = req.get(hardhatLoc).text
noOfImages = 0
 
if not os.path.exists('hardhat'):
    os.makedirs('hardhat')
 
os.chdir('hardhat')
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')
 
print('*********** Download Finished **************')
  • 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)