We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How can i draw with color detection
Page Index Toggle Pages: 1
How can i draw with color detection? (Read 955 times)
How can i draw with color detection?
Mar 29th, 2007, 9:32am
 
Heey guys,

i try to make a draw program with a webcam. I want that people are standing for the webcam and that they can draw with a colored point (for example a laser pointer). I got a code with color detection, and i got a code to draw lines on the screen, but now i have to combine it. The problem is, how to do that... i have really no idea, because i'am new with this program and i'am trying to learn te basics.
if you guys can help me many thnx
grTz
Droobie


---- code for color detection ----

import JMyron.*;

JMyron m;//a camera object

void setup(){
 size(320,240);
 m = new JMyron();//make a new instance of the object
 m.start(width,height);//start a capture at 320x240
 m.trackColor(255,0,0,200);//R, G, B, and range of similarity
 m.minDensity(100); //minimum pixels in the glob required to result in a box
 println("Myron " + m.version());
 noFill();
}

void draw(){
 m.update();//update the camera view
 drawCamera();//draw the camera to the screen
 int[][] b = m.globBoxes();//get the center points
 //draw the boxes
 stroke(255,255,255);
 
 for(int i=0;i<b.length;i++){
   //line(mouseX, mouseY, pmouseX, pmouseY);
   rect( b[i][0] , b[i][1] , b[i][2] , b[i][3] );
 }

}

void drawCamera(){
 int[] img = m.image(); //get the normal image of the camera
 loadPixels();
 for(int i=0;i<width*height;i++){ //loop through all the pixels
   pixels[i] = img[i]; //draw each pixel to the screen
 }
 updatePixels();

}

void mousePressed(){
// m.settings();//click the window to get the settings
}

public void stop(){
 m.stop();//stop the object
 super.stop();
}

--- end code for color detection ---

--- code to draw on a grid ---

void setup() {
 size(200, 200);
 background(000);
}

void draw() {
 stroke(255);
 if(mousePressed) {
   line(mouseX, mouseY, pmouseX, pmouseY);
 }
}

--- end code to draw on a grid
Re: How can i draw with color detection?
Reply #1 - Mar 30th, 2007, 1:31am
 
How fast is Jmyron? I haven't used it in a while and I remembered it being pretty slow.. I just wrote my own color detection code.

assuming you're looking for red..
Create a 2-dimensional array that is relative to your video window...
Fill the array with '0's.. Where ever you find red, you will the corresponding index in the array with a '1'

So where ever there is a 1 you draw a line or circle or whatever.

hope that makes sense.
Re: How can i draw with color detection?
Reply #2 - Mar 30th, 2007, 9:25am
 
Heey thnx for your reply,

i think that will solve the problem, but (ashamed) i must say that i have really no idea how to code it Sad. iam just starting with this program.
It's a project for school, and i try to make something nice with it. The code that i already have, got i mostly from internet. Iam not able to write things like that myself. Maybe you can give me an example to place in the code. then i can figure out how it works.

Many thnx
grTz
Droobie
Re: How can i draw with color detection?
Reply #3 - Mar 30th, 2007, 8:14pm
 
What if you did this:

Each time through draw(), you search for your laser dot.  If the laser dot is found, simply draw a small filled circle at it's location.

Sounds like you're trying to make something like this:

http://graffitiresearchlab.com/?page_id=76
Page Index Toggle Pages: 1