imageAi.py 855 B

12345678910111213141516171819
  1. from imageai.Detection import ObjectDetection
  2. import os
  3. execution_path = os.getcwd()
  4. detector = ObjectDetection()
  5. detector.setModelTypeAsYOLOv3()
  6. # detector.setModelTypeAsRetinaNet()
  7. detector.setModelPath(os.path.join(execution_path , 'yolo.h5'))
  8. detector.loadModel()
  9. detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , 'cap20190925_074847D_6.jpg'),
  10. output_image_path=os.path.join(execution_path,
  11. 'image2new.jpg'),
  12. minimum_percentage_probability=50)
  13. print(detections, end='\n')
  14. for eachObject in detections:
  15. print(eachObject['name'] , ' : ', eachObject['percentage_probability'])
  16. # print("--------------------------------")