Hi, I have some pictures of two white dices with black dots, and I need to recognize the value on each visible face of dices.
For example, from image that includes dice with 6 dots and another dice with 5 dots, need to get [5 6].
Any ideas?

It's really urgent, I need to submit my final project and this is the last piece.
Thanks a lot!

Recommended Answers

All 3 Replies

Hi, Thanks for your answer.
I've also googled it. I cannot find an example that meet my goal.
I've managed to identify the sum of the dots, but straggeling to determine the value of each dice seperatly.
In my example - I can get 11, but I need to get [5 6].

This is my code:

rgb = snapshot(cam);
%work - [295.5 224.5 23 38]
X2 = imcrop(rgb, [83.5 189.5 453 87]);
rgbImage = X2;
% Get the dimensions of the image.  numberOfColorBands should be = 3.
[rows ,columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original color Image');
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize')); 
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);

spots = rgbImage(:, :, :) < 58; 
spots = spots(:, :, 1) == spots(:, :, 2) == spots(:, :, 3); 

subplot(2, 2, 2);
imshow(spots, []);
title('Thresholded Red Channel');
spots = imclearborder(spots,8);
subplot(2, 2, 3);
imshow(spots, []);
title('Border Cleared');
% Fill holes
spots = imfill(spots, 'holes');
subplot(2, 2, 4);
imshow(spots, []);
title('Final Spots Image');
impixelinfo;
% Count them
L = bwlabel(spots);
[labeledImage ,numberOfSpots] = bwlabel(spots);
message = sprintf('Done!\nThe number of spots (total on both dice) is %d', numberOfSpots);
msgbox(message);
[IDX] = kmeans(L,2);
 figure, imshow(rgbImage,[]);

That's going to take a lot more code. You'll have to find the outline of each dice to slice up the pictures into 2 images and then process each one. There's a paper noting a clustering system at http://www.mdpi.com/1424-8220/8/2/1212/pdf so that's 2 approaches.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.