【问题标题】:Carving Out exactly humans From Image从图像中精确地雕刻出人类
【发布时间】:2021-04-23 11:45:42
【问题描述】:

我想从目前能够在人类周围创建一个盒子的图像中切出精确的人类 我使用的代码如下:

import cv2
import numpy as np
import imutils

protopath = r"C:\Users\Admin\MobileNetSSD_deploy.prototxt"
modelpath = r"C:\Users\Admin\MobileNetSSD_deploy.caffemodel"
detector = cv2.dnn.readNetFromCaffe(prototxt=protopath, caffeModel=modelpath)

CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat",
           "bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
           "dog", "horse", "motorbike", "person", "pottedplant", "sheep",
           "sofa", "train", "tvmonitor"]


def main():
    image = cv2.imread(r'E:\trial2.jpg')
    image = imutils.resize(image,300)

    (H, W) = image.shape[:2]

    blob = cv2.dnn.blobFromImage(image, 0.007843, (W, H), 127.5)

    detector.setInput(blob)
    person_detections = detector.forward()

    for i in np.arange(0, person_detections.shape[2]):
        confidence = person_detections[0, 0, i, 2]
        if confidence > 0.5:
            idx = int(person_detections[0, 0, i, 1])

            if CLASSES[idx] != "person":
                continue
                

            person_box = person_detections[0, 0, i, 3:7] * np.array([W, H, W, H])
            (startX, startY, endX, endY) = person_box.astype("int")
            cv2.rectangle(image, (startX, startY), (endX, endY), (0, 0, 255), 2)

    cv2.imshow("Results", image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
main()

我想要什么 我想准确地勾勒出人类的轮廓

任何帮助或提示将不胜感激

编辑 1:由 Sunil Kumar 建议

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread(r'E:\trial3.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
# noise removal
kernel = np.ones((3,3),np.uint8)
opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel, iterations = 2)

# sure background area
sure_bg = cv2.dilate(opening,kernel,iterations=3)

# Finding sure foreground area
dist_transform = cv2.distanceTransform(opening,cv2.DIST_L2,5)
ret, sure_fg = cv2.threshold(dist_transform,0.7*dist_transform.max(),255,0)

# Finding unknown region
sure_fg = np.uint8(sure_fg)
unknown = cv2.subtract(sure_bg,sure_fg)
# Marker labelling
ret, markers = cv2.connectedComponents(sure_fg)

# Add one to all labels so that sure background is not 0, but 1
markers = markers+1

# Now, mark the region of unknown with zero
markers[unknown==255] = 0
markers = cv2.watershed(img,markers)
img[markers == -1] = [255,0,0]
cv2.imshow("Results", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

以及我得到的当前输出

【问题讨论】:

  • SSD网络是一个物体检测模型; “对象检测”通常被定义为边界框。您要求的是“掩码”,通常这个问题称为“实例分割”,您需要运行不同的模型,如 Mask R-CNN,而不是 YOLO 或 SSD 等。请参阅此处了解基本信息概述:towardsdatascience.com/…
  • @isAif 那是我目前的结果......预期的结果是在人类身上创建轮廓

标签: python-3.x image-segmentation opencv-python


【解决方案1】:

你要找的是instance segmentation,比物体检测准确多了:
而对象检测仅在每个人周围输出一个边界框(正如您已经注意到的)。实例分割尝试为每个实例输出一个精确的掩码 - 这就是您要查找的内容。

我会尝试以下实例分割框架:

  1. Mask RCNN
  2. Pixel Consensus voting

【讨论】:

    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多