我想在图像中检测和隔离所有Rummikub瓷砖的(get sub-images).这是Rummikub瓷砖的图像:
我试图在锋利的图像中找到瓦片的轮廓.但是,我无法找到所有瓦片的所有轮廓.
这是我到目前为止所得到的:
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
import cv2
import imutils
from imutils import contours
# Load image
img = cv2.imread('RK1.jpg',3)
# Converting the image to grayscale.
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Smoothing without removing edges.
gray_filtered = cv2.bilateralFilter(gray, 6, 400, 400)
# Applying the canny filter
edges_filtered = cv2.Canny(gray_filtered, 50, 30)
# find contours in the edged image
contours= cv2.findContours(edges_filtered, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
# loop over our contours
for contour in contours:
# approximate the contour
peri = cv2.arcLength(contour, True)
approx = cv2.approxPolyDP(contour, 0.015 * peri, True)
# if our approximated contour has four points, then draw contour
if len(approx) == 4:
cv2.drawContours(img, [approx], -1, (0, 255, 0), 3)
这是结果:
我非常感谢关于如何可靠地找到所有瓷砖的所有轮廓的建议.