Save image without rectangle borders

I am using the “MobileNetSSD_deploy.caffemodel” model to detect objects.

When it detects a person what I do is save it with “cv2.imwrite()”.

for (objectId, bbox) in objects.items():
            x1, y1, x2, y2 = bbox
            x1 = int(x1)
            y1 = int(y1)
            x2 = int(x2)
            y2 = int(y2)

            cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2)
            text = f"ID: {objectId}"
            cv2.putText(frame, text, (x1, y1-5), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)

auxFrame = frame.copy()
persona = auxFrame[y1:y2,x1:x2]

My problem is that it saves the edges:

It’s honestly not a serious problem, but, I think it would be cleaner if the edges don’t come out. I can remove the rectangle, but for testing it is necessary. What solution do you suggest?

simply save it before drawing rects into it

your code is also only saving the last object, not all of them
(so you want to move the saving code inside th loop, before the drawing)

1 Like

I hadn’t thought of it that way. You’re right. It worked.

Sorry for the silly question.