示例#1
0
def get_pixels_from_path(path: QPainterPath) -> list:
    polygons = path.toFillPolygons()
    result = []
    for polygon in polygons:
        for i in range(polygon.size()):
            result.append(polygon.at(i))
    return result
示例#2
0
def count_area(outline_path: QPainterPath, ratio: int = 1) -> float:
    """
    :param outline_path: 轮廓的像素的矩阵
    :param ratio: 图像的分辨率 以米为单位
    :return: float类型的面积
    """
    fills = outline_path.toFillPolygons()
    j = 0
    counter = []
    for j in range(len(fills)):
        fill = fills[j]
        print(fill)
        i = 0
        counter.append([])
        counter[j] = []
        for i in range(fill.__len__()):
            x = int(fill.value(i).x())
            y = int(fill.value(i).y())
            counter[j].append([x, y])
            i = i + 1
        counter[j] = np.array(counter[j], dtype='int32')
        j = j + 1
    totalarea = 0.0
    i = 0
    for j in counter:
        area = cv2.contourArea(counter[i])
        totalarea = area * ratio + totalarea
        i = i + 1
    return totalarea