先来看看完整的代码,使用YOLOv3算法对13张照片进行目标识别。 from imageai.Detection import ObjectDetection import os detector = ObjectDetection() detector.setModelTypeAsYOLOv3() detector.setModelPath("./model/yolo.h5") detector.loadModel() path = os.getcwd() input_image_list = os.listdir(path+"...
from imageai.DetectionimportObjectDetectionimportos execution_path=os.getcwd()detector=ObjectDetection()detector.setModelTypeAsRetinaNet()detector.setModelPath(os.path.join(execution_path,"resnet50_coco_best_v2.0.1.h5"))detector.loadModel()detections=detector.detectObjectsFromImage(input_image=os.path....
创建一个Python文件并命名(如FirstDetection.py),然后将下面的代码写入该文件。将RetinaNet模型文件和要检测的图像复制到包含Python文件的文件夹中。 FirstDetection.py: 1 2 3 4 5 6 7 8 9 10 11 12 13 fromimageai.DetectionimportObjectDetection importos execution_path=os.getcwd() detector=ObjectDetection(...
下边就是全部代码,用这个代码可以进行Object Detection,数一下有木有10行呢~~ import cv2import matplotlib.pyplot as pltimport cvlib as cvfrom cvlib.object_detection import draw_bboxim = cv2.imread('apple-256261_640.jpg')bbox, label, conf = cv.detect_common_objects(im)output_image = draw_bbox...
from imageai.Detection import ObjectDetection importosdetector = ObjectDetection() detector.setModelTypeAsYOLOv3() detector.setModelPath("./model/yolo.h5") detector.loadModel()path=os.getcwd() input_image_list =os.listdir(path+"\pic\input") ...
cv2.imshow("Object detection", image) cv2.waitKey() 1. 2. 如果一切顺利,此代码块将生成我们在对象检测简介部分开头看到的相同图像。 我们对 YOLO 的讨论到此结束。在下一节中,我们将介绍一个名为 Faster R-CNN 的两阶段目标检测器(R-CNN 代表带有 CNN 的区域)。
准备工作到此结束,你可以写自己的第一个目标检测代码了。新建一个Python文件并命名(如FirstDetection.py),然后将下述代码写入此文件。接着将RetinaNet模型文件、FirstDetection.py和你想检测的图片放在同一路径下,并将图片命名为“image.jpg”。 下面是FirstDetection.py中的10行代码: ...
在上面两行代码中,我们迭代了第一行中detector.detectObjectFromImage函数返回的所有结果,然后打印出第二行中模型对图像上每个物体的检测结果(名称和概率)。 ImageAI支持很多强大的目标检测自定义功能,其中一项就是能够提取在图像上检测到的每个物体的图像。只需将附加参数extract_detected_objects=True解析为detectObjects...
detector = ObjectDetection() detector.setModelTypeAsRetinaNet() detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5")) detector.loadModel() detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=...
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg")) for eachObject in detections: print(eachObject["name"] , " : " , eachObject["percentage_probability"] ) 然后运行代码,等待...