【问题标题】:Rotated contour pixels旋转轮廓像素
【发布时间】:2020-12-06 23:47:49
【问题描述】:
    def find_border(self):
        print("Start capturing the border")
        ret, thresh = cv2.threshold(self.__grayScaledImage, 250, 255, 0)
        contours = cv2.findContours(thresh.astype(np.uint8), cv2.RETR_TREE,
                                    cv2.CHAIN_APPROX_NONE)[-2]

        # There might be multiple are with 255. then you need to find the index of the largest contour
        areas = [cv2.contourArea(c) for c in contours]
        max_index = np.argmax(areas)
        border = contours[max_index]
        border = border.reshape(-1, border.shape[2])
        for i, j in border:
            if i >=0 and i < self.__image.shape[0] and j >= 0 and j < self.__image.shape[1]:
                self.__image[i, j] = [255, 0, 0]
        print("Finish capturing the border")

        # cv2.drawContours(self.__image, border, -1, (255, 0, 0), 1)
        plt.imshow(self.__image)
        plt.show()

        border = border.reshape(-1, border.shape[2])
        return border

我有上面的代码 sn-ps 来获取图像的边框像素,但是当我尝试两种方法来可视化边框时:使用cv2.drawContours 或在像素上标记红点作为边框像素。 drawContours 给了我一个合理的输出,但是点标记方法生成了一个旋转的轮廓。 后来我检查了边框像素,发现它们实际上是旋转后反映的点。 我这里有

self.__grayScaledImage = cv2.cvtColor(self.__image, cv2.COLOR_RGB2GRAY)

我不知道为什么。

【问题讨论】:

    标签: image-processing graphics computer-vision


    【解决方案1】:

    你在某处混合了 x 和 y。轮廓没有旋转,而是沿对角线翻转。

    numpy 索引是矩阵样式。 [行,列]或[y,x],如果你喜欢

    OpenCV 给你 (x,y) 点,或 (column, row)

    哦,感谢您使用图片来说明问题。让事情变得比其他方式容易得多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      相关资源
      最近更新 更多