フィルターのクリア

After finding lines, how to find squares in an Image of a chessboard?

7 ビュー (過去 30 日間)
Iraklis S
Iraklis S 2018 年 1 月 11 日
回答済み: mohammad nemat 2021 年 7 月 13 日
Hello, I'm trying to detect the squares of a chessboard and name them accordingly (H8, A6, C4 etc.). I have already found the lines in the chessboard. Here is my code:
EDIT: Do you believe that there might be a way to use the lines, so I can find the squares of the chess?
if true
clear all; clc; close all;
I = imread('chess.jpg');
th = [0 0.417]; %threshold for canny
s = sqrt(3); %sigma for canny
Ig = rgb2gray(I);
B = edge(Ig,'Canny',th,s); %Using canny in Graythresh image
%Hough Transformation
[H, theta, rho] = hough(B, 'RhoResolution',0.9,'ThetaResolution',0.09);
peaks = houghpeaks(H,19,'threshold',ceil(0.3*max(H(:)))); %wiki
%Finding Lines
lines = houghlines(B, theta, rho, peaks, 'FillGap', 350, 'MinLength', 20);
figure(2)
imshow(I)
hold on
maxLength = 0;
%Show lines
for i = 1 : length(lines)
xy = [lines(i).point1; lines(i).point2];
% LineSHow
plot( xy(:, 1), xy(:, 2), 'LineWidth', 2, 'Color', 'green' );
% Length of line
lengthOfLines(i) = norm(lines(i).point1 - lines(i).point2);
% Find angle
angles(i) = lines(i).theta;
% Check if this is the longest line
if ( lengthOfLines > maxLength )
maxLength = lengthOfLines;
xyLongest = xy;
end
end
%Below, is a failed try to find the squares, using a suggestion by another post
%about finding squares
BW = im2bw(Ig);
S = regionprops(peaks, 'BoundingBox', 'Centroid');
imshow(I); hold on;
for cnt = 1 : numel(S)
bb = S(cnt).BoundingBox;
rectangle('position',bb,'edgecolor','r','linewidth',2);
end
end
This is the image:
This is the line detection:
  1 件のコメント
KAE
KAE 2019 年 9 月 24 日
Shouldn't it be
S = regionprops(BW, 'BoundingBox', 'Centroid');

サインインしてコメントする。

回答 (1 件)

mohammad nemat
mohammad nemat 2021 年 7 月 13 日
hi,i ran this code with this picture but i didn't get this result with detected line.
what is this problem and why i can't get this output?

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by