提取感兴趣区域

时间:2019-07-16 16:33:59

标签: image-processing grayscale yolo

我正在使用YOLO v3检测图像中的对象,并且希望以可以对其进行一些后处理的方式裁剪该区域(边界框)。 我希望该区域为二进制图像,并且图像的所有其他部分必须为黑色。 您能否建议我如何编写此部分代码? 我的代码在这里绘制边界框

#initializing the lists detected bounding boxes, and class IDs, confidences respectively
boxes = []
classIDs = []
confidences = []


for out in raw_out_put:
    for detection in out:
        scores = detection[5:]
        classID = np.argmax(scores)
        confidence = scores[classID]



        if confidence > threshold_confidence:



            X = int(detection[0] * fWidth)
            Y = int(detection[1] * fHeight)
            width = int(detection[2] * fWidth)
            height = int(detection[3] * fHeight)


            left = int(X - width / 2)
            top = int(Y - height / 2)

            classIDs.append(classID)
            confidences.append(float(confidence))
            boxes.append([left, top, width, height])




NMS = cv.dnn.NMSBoxes(boxes, confidences, threshold_confidence, threshold_nonmaxsup)
for i in NMS:
    i = i[0]
    box = boxes[i]
    left = box[0]
    top = box[1]
    width = box[2]
    height = box[3]

    drawPred(classIDs[i], confidences[i], left, top, left + width, top + height)
def drawPred(classId, conf, left, top, right, bottom):
# Than Draw a bounding box.
cv.rectangle(frame, (left, top), (right, bottom), (20, 20, 100), 2)

1 个答案:

答案 0 :(得分:0)

在工作结束时,将原始图像的大小填充为零,然后用cv.rectangle进行thickness=-1命令(现在将厚度= 2设置为- 1),像素值=(255,255,255),如下所示:

frame=0*frame
cv.rectangle(frame, (left, top), (right, bottom), (255, 255, 255), -1)