Borrar filtros
Borrar filtros

how can i detect the checkerboard pieces in an image?

2 visualizaciones (últimos 30 días)
Ahmad toufaily
Ahmad toufaily el 27 de Oct. de 2015
Respondida: Image Analyst el 28 de Oct. de 2015
hey guys! i am working on my final project which is a checkers playing robot(actually turkish checker). i was able to detect the checkerboard using hough transform and canny edge detector now i would like to find out what board cells may hold pieces and which may not. i think about xoring the "no pixels on" image with the image with the checker pieces on it to find out which squares have pieces on them, but i don't know how to do it .may someone help me please :) you may find my code and the images
if true
I = imread('FrontTop2.png');
BW = edge(rgb2gray(I),'canny');
%http://www.mathworks.com/help/images/edge-detection.html#buh9ylp-13
[H, theta, rho] = hough(BW);
figure; image(theta,rho,imadjust(mat2gray(H)),'CDataMapping','scaled');
hold on; colormap(gray(256));
%plot(theta(P(:,2)),rho(P(:,1)),'o','color','r');
%http://www.mathworks.com/help/images/ref/hough.html
%find peaks
numpeaks = 19;
thresh = ceil(0.1 * max(H(:)));
P = houghpeaks(H,numpeaks,'threshold',thresh);
% Extract image lines
lines = houghlines(BW,theta,rho,P,'FillGap',50,'MinLength',60);
figure; imshow(I);
figure; imshow(BW);
figure; imshow(I); hold on; n = size(I,2);
for k = 1:length(lines)
% Overlay kth line
x = [lines(k).point1(1) lines(k).point2(1)];
y = [lines(k).point1(2) lines(k).point2(2)];
line = @(z) ((y(2) - y(1)) / (x(2) - x(1))) * (z - x(1)) + y(1);
plot([1 n],line([1 n]),'Color','r');
end
%# shearing transformation slopes = vertcat(lines.point2) - vertcat(lines.point1); slopes = slopes(:,2) ./ slopes(:,1); TFORM = maketform('affine', [1 -slopes(1) 0 ; 0 1 0 ; 0 0 1]); II = imtransform(I, TFORM);
%# show image with lines overlayed, and the aligned/rotated image figure subplot(121), imshow(I), hold on for k = 1:length(lines) xy = [lines(k).point1; lines(k).point2]; plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2); end, hold off subplot(122), imshow(II);
end

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Oct. de 2015
Just convert both to gray level and subtract
grayImage = rgb2gray(thisImage);
refImage = rgb2gray(refImage);
diffImage = abs(double(grayImage)-double(refImage));
binaryImage = diffImage > someThreshold;
% Fill holes.
binaryImage = imfill(binaryImage, 'holes');
% Get rid of small noise specks.
binaryImage = bwareaopen(binaryImage, 1000);

Más respuestas (0)

Categorías

Más información sobre Image Processing and Computer Vision en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by