We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone, for a school project my teachers had a cool project for me in mind. Making a cheating roullette table with the help of processing. I told them I am not very good at Processing, but they said that it was pretty easy to do. Now I am 6 weeks further and the help of my teachers is gone. I have to do it on my own now and I can't seem to improve on my work anymore. I'm stuck and it is hard as balls for me. So is there anyone here on the forums who can help me out as soon as possible?
The code makes a picture from my webcam and checks the picture for blobs. Then he colors the blobs with a size higher than 200 pixels and puts a rectangle box around it. Right now I need to check the middle of a rectangle box if it is in another box, like is it x > 400 x < 450 y > 60 y < 100 etc. This is to check if the casino tokens are on a number or not. If yes, then exclude a video from playing and if no, put the video in a random playlist. So I want if a token is on 1, i dont want the video wich rolls a 1 to be played. Also if there are tokens on 4 and 17, exclude those from the possibility to play. I don't know how to go further and I'm desperate.
Thank you in advance.
import processing.video.*;
PImage img;
ArrayList<Integer> blackPixels = new ArrayList<Integer>();
Capture cam;
void setup() {
size(1280,960);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
cam = new Capture(this, cameras[1]);
cam.start();
}
}
void draw(){
if (cam.available() == true) {
cam.read();
image(cam, 0, 0);
println("DrawFunction");
}
}
void mousePressed(){
cam.stop();
saveFrame("check.jpg");
readPixels();
//imageCheck();
}
void imageCheck(){
img = loadImage("check.jpg");
image(img,0,0);
println("imageCheck");
readPixels();
}
void readPixels()
{
println("readPixels");
loadPixels();
for (int i = 0; i < pixels.length; i++)
{
if( blue(pixels[i]) > 150 && red(pixels[i]) > 200 && green(pixels[i]) > 200)
{
pixels[i] = color(0,0,0);
blackPixels.add(1);
}
else
{
pixels[i] = color(255,255,255);
blackPixels.add(0);
}
}
updatePixels();
findFirstPixel();
}
void findFirstPixel()
{
println("findFirstPixel");
for (int i = 0; i < blackPixels.size(); i++)
{
if(blackPixels.get(i) == 1)
{
findPixels( i );
break;
}
}
}
void findPixels( int pixelNumber )
{
ArrayList<Integer> blob = new ArrayList<Integer>();
checkSurroundingPixels( pixelNumber , blob );
println(blob.size());
if( blob.size() > 200 )
{
calculateBoundingBox(blob);
calculateNumber(blob);
paintBlob(blob, color(255,0,0) );
}
else
{
paintBlob(blob, color(255,0,255) );
}
}
void checkSurroundingPixels( int pixelNumber, ArrayList<Integer> blob )
{
blob.add( pixelNumber );
int i = 0;
while( i < blob.size() )
{
pixelNumber = blob.get(i);
int topleft = pixelNumber - width - 1;
int topmiddle = pixelNumber - width;
int topright = pixelNumber - width + 1;
int left = pixelNumber - 1;
int right = pixelNumber + 1;
int bottomleft = pixelNumber + width - 1;
int bottommiddle = pixelNumber + width;
int bottomright = pixelNumber + width + 1;
if( !blob.contains( topleft ) )
{
if( topleft >= 0 && blackPixels.get(topleft) == 1)
{
blob.add( topleft );
}
}
if( !blob.contains( topmiddle ) )
{
if(topmiddle >= 0 && blackPixels.get(topmiddle) == 1)
{
blob.add( topmiddle );
}
}
if( !blob.contains( topright ) )
{
if( topright >= 0 && blackPixels.get(topright) == 1 )
{
blob.add( topright );
}
}
if( !blob.contains( left ) )
{
if( left >= 0 && blackPixels.get(left) == 1 )
{
blob.add( left );
}
}
if( !blob.contains( right ) )
{
if( right <= (width * height) - 1 && blackPixels.get(right) == 1)
{
blob.add( right );
}
}
if( !blob.contains( bottomleft ) )
{
if( bottomleft <= (width * height) - 1 && blackPixels.get(bottomleft) == 1)
{
blob.add( bottomleft );
}
}
if( !blob.contains( bottommiddle ) )
{
if( bottommiddle <= (width * height) -1 && blackPixels.get(bottommiddle) == 1)
{
blob.add( bottommiddle );
}
}
if( !blob.contains( bottomright ) )
{
if(bottomright <= (width * height) - 1 && blackPixels.get(bottomright) == 1)
{
blob.add( bottomright );
}
}
i++;
}
}
void calculateBoundingBox( ArrayList<Integer> blob )
{
println("blob found");
int maxX = 0;
int minX = width;
int maxY = 0;
int minY = height;
for (int i = 0 ; i < blob.size() ; i++){
int x = blob.get(i) % 1280;
int y = ceil(blob.get(i) / 1280);
if( x > maxX )
{
maxX = x;
}
if( x < minX )
{
minX = x;
}
if( y > maxY )
{
maxY = y;
}
if( y < minY )
{
minY = y;
}
rect(minX, minY, maxX-minX, maxY-minY);
}
}
void paintBlob( ArrayList<Integer> blob , color col)
{
loadPixels();
for (int i = 0 ; i < blob.size() ; i++)
{
pixels[blob.get(i)] = col;
}
updatePixels();
removeBlob( blob );
}
void removeBlob( ArrayList<Integer> blob )
{
for (int i = 0 ; i < blob.size() ; i++)
{
blackPixels.set( blob.get(i), 0);
}
findFirstPixel();
}