I would like to recognize the boundaries of a hexagonal tiling in a photograph, like in image below:
It seems to me, that a standard approach at a square grid is to first detect corners (e.g. canny) and then extract the longest lines via a Hough transform or something similar.
This does not look as optimal solution with hex tiling, because the length of outer lines is shorter and it's hard to separate them from other lines.
Is there any algorithm to adress this problem? It would be particulary nice to have a solution in opencv, but I am also interested in general ideas.
update:
With python and opencv I was able to receive this result:
Here is my code:
import cv2
import numpy as np
imgOrig = "test1";
img = cv2.imread(imgOrig+".jpg");
lap = cv2.Laplacian(img, cv2.IPL_DEPTH_32F, ksize = 3)
imgray = cv2.cvtColor(lap,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
size = img.shape
m = np.zeros(size, dtype=np.uint8)
for i, cnt in enumerate(contours):
if cv2.contourArea(cnt) >= 1:
color = (255,255,255)
cv2.drawContours(m, cnt, -1, color, -1)
cv2.imwrite(str(imgOrig)+"contours.jpg", m);
Laplacian of image looks like:
I will try to optimate the parameters of this approach and then try to interpolate the boundaries of the four sections.