├── .gitignore ├── 1city.jpg ├── 2cars_people.jpeg ├── 3silicon_valley.jpg ├── main.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.pyc 3 | /venvObjDet/ -------------------------------------------------------------------------------- /1city.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythontoday/object_detection_in_an_image/d340a2f0663309cec689ecb234b7d37eb55773cc/1city.jpg -------------------------------------------------------------------------------- /2cars_people.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythontoday/object_detection_in_an_image/d340a2f0663309cec689ecb234b7d37eb55773cc/2cars_people.jpeg -------------------------------------------------------------------------------- /3silicon_valley.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythontoday/object_detection_in_an_image/d340a2f0663309cec689ecb234b7d37eb55773cc/3silicon_valley.jpg -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" 3 | from pixellib.instance import instance_segmentation 4 | 5 | 6 | def object_detection_on_an_image(): 7 | segment_image = instance_segmentation() 8 | segment_image.load_model("path_to_model") 9 | 10 | target_class = segment_image.select_target_classes(person=True) 11 | 12 | result = segment_image.segmentImage( 13 | # image_path="1city.jpg", 14 | # image_path="2cars_people.jpeg", 15 | image_path="3silicon_valley.jpg", 16 | # show_bboxes=True, 17 | segment_target_classes=target_class, 18 | # extract_segmented_objects=True, 19 | # save_extracted_objects=True, 20 | # output_image_name="output.jpg" 21 | ) 22 | 23 | # print(result[0]["scores"]) 24 | objects_count = len(result[0]["scores"]) 25 | print(f"Найдено объектов: {objects_count}") 26 | 27 | 28 | def main(): 29 | object_detection_on_an_image() 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | absl-py==0.12.0 2 | astunparse==1.6.3 3 | attrs==20.3.0 4 | cachetools==4.2.1 5 | certifi==2020.12.5 6 | chardet==4.0.0 7 | cycler==0.10.0 8 | decorator==4.4.2 9 | flatbuffers==1.12 10 | gast==0.3.3 11 | google-auth==1.28.1 12 | google-auth-oauthlib==0.4.4 13 | google-pasta==0.2.0 14 | grpcio==1.32.0 15 | h5py==2.10.0 16 | idna==2.10 17 | imageio==2.9.0 18 | imantics==0.1.12 19 | imgaug==0.4.0 20 | jsonschema==3.2.0 21 | Keras-Preprocessing==1.1.2 22 | kiwisolver==1.3.1 23 | labelme2coco==0.1.2 24 | lxml==4.6.3 25 | Markdown==3.3.4 26 | matplotlib==3.4.1 27 | networkx==2.5.1 28 | numpy==1.19.5 29 | oauthlib==3.1.0 30 | opencv-python==4.5.1.48 31 | opt-einsum==3.3.0 32 | Pillow==8.2.0 33 | pixellib==0.6.1 34 | pkg-resources==0.0.0 35 | protobuf==3.15.8 36 | pyasn1==0.4.8 37 | pyasn1-modules==0.2.8 38 | pyparsing==2.4.7 39 | pyrsistent==0.17.3 40 | python-dateutil==2.8.1 41 | PyWavelets==1.1.1 42 | requests==2.25.1 43 | requests-oauthlib==1.3.0 44 | rsa==4.7.2 45 | scikit-image==0.18.1 46 | scipy==1.6.2 47 | Shapely==1.7.1 48 | six==1.15.0 49 | tensorboard==2.4.1 50 | tensorboard-plugin-wit==1.8.0 51 | tensorflow==2.4.1 52 | tensorflow-estimator==2.4.0 53 | termcolor==1.1.0 54 | tifffile==2021.4.8 55 | typing-extensions==3.7.4.3 56 | urllib3==1.26.4 57 | Werkzeug==1.0.1 58 | wrapt==1.12.1 59 | xmljson==0.2.1 60 | --------------------------------------------------------------------------------