【问题标题】:Part of an image into numpy array将图像的一部分放入 numpy 数组
【发布时间】:2019-04-20 18:37:11
【问题描述】:

我正在开展一个关于实时数独识别的项目,但遇到了问题。我想截取图像的一部分,比如说已经被识别的数独的一部分(如下图所示),并将其转换为 numpy 数组以供将来操作。

数独部分

如果你在徘徊,这些矩形是用我的程序的这一部分收集的 4 个点绘制的:

contours, hierarchy = findContours( thresh.copy(), RETR_TREE, CHAIN_APPROX_SIMPLE)

for cnt in contours:
    rect = minAreaRect(cnt)
    if rect[1][0] > 80:
        box = boxPoints(rect)
        box = np.int0(box)
        if thresh[box[0][1], box[0][0]] != 0:
            for coord in box:
                coords.append(coord)
            approx = approxPolyDP(box,0.01*arcLength(box,True),True)
            drawContours(img,[approx],0,(255,0,0),2)

我在互联网上没有找到任何解决方案,所以我问:有什么办法可以做到吗?

【问题讨论】:

标签: python numpy opencv cv2


【解决方案1】:

您可以使用轮廓边界点通过切片裁剪图像并将其存储在新数组中:

# (x1, y1) is the top-left bounding point
# (x2, y2) is the bottom-right bounding point
sudoku_box = img[y1:y2, x1:x2]

【讨论】:

  • 非常感谢您的建议,我在谷歌上搜索了裁剪。技术,这正是我需要的,再次非常感谢。
猜你喜欢
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-25
  • 2016-09-28
  • 2017-04-03
  • 2018-03-16
相关资源
最近更新 更多