我正在开发一个关于实时数独识别的项目,我遇到了一个问题。我想拍摄一个图像的一部分,让我们说一个已经被识别的数独游戏的一部分(如下图所示),然后把它变成一个用于未来操控的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)
我没有在互联网上找到任何解决方案,所以我问:有什么方法可以做到吗?
您可以使用轮廓边界点通过切片裁剪图像并将其存储在新数组中:
# (x1, y1) is the top-left bounding point
# (x2, y2) is the bottom-right bounding point
sudoku_box = img[y1:y2, x1:x2]