首页 > 解决方案 > FasterRcnn 模型未显示边界框

问题描述

我试图在出现在屏幕上的人周围绘制边界框。但似乎,代码已经检测到框架中的人,但无法为其绘制边界框。
请帮我解决这个问题。
我正在使用这个模型,faster_rcnn_inception_resnet_v2_atrous_coco_2018_01_28

源代码

def draw_boxes(result,imgToDisplay,w,h):

    #Draw bounding boxes onto the frame.
    for box in result[0][0]: # Output shape is 1x1x100x7
            conf = box[2]  #box[2] = result[0][0][2] is a probability value
            print("probability value : ",conf)
            print("box[0] : ",box[0]) #Object found or not
            print("box[1] : ",box[1]) #Object class
            print("xmin : ", box[3])
            print("ymin : ", box[4])
            print("xmax : ", box[5])
            print("ymax : ", box[6])

            #In below code, w and h are height and width of image respectively
            if conf >= 0.1:
                xmin = int(box[3] * w)  
                ymin = int(box[4] * h) 
                xmax = int(box[5] * w) 
                ymax = int(box[6] * h) 
                cv2.rectangle(imgToDisplay, (xmin, ymin), (xmax, ymax), (0, 0, 255), 1)

             cv2.imshow('Object_detection',imgToDisplay)

标签: pythonopencvkerasdeep-learning

解决方案


推荐阅读