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 & HelpVideo Capture,  Movie Playback,  Vision Libraries › How to create a color analyzer with JMyron
Page Index Toggle Pages: 1
How to create a color analyzer with JMyron? (Read 950 times)
How to create a color analyzer with JMyron?
Mar 16th, 2007, 8:49pm
 
Here is what I am trying to do:

At my work I analyze samples of lubricants, oils, etc.  One thing we look at is the colour of the sample.  I am trying to eliminate any subjectivity on the analysis of the colour of the sample.  One idea I had was to create a "color analyzer" utilizing my webcam.  My goal was to ultimately reduce the colour of the sample to the R,G,B values (the samples are in clear bottles and I was planning on placing them beside the webcame while iluminating them with some sort of light source).  I noticed that JMyron has the following command:

"average(int left,int top,int right,int bottom) will average a given rect of pixels in the differenceImage and return the overall color. The return is a color. In Lingo, this is a color object. In Processing, this is an single integer color, whose color channel values can be retrieved using the functions red(), green(), and blue()."

I have JMyron installed, and I can view the video feed through Processing fine.  However, when it comes to editing the code to do what I want to do, I am at a loss  - I do not know where to even begin.  Any suggestions?

Ideally I would want to somehow change the video feed from the webcam to display a single colour - the average of all the pixels.  Further, if there was a way to somehow display the R,G,B values also, that would be swell.  If the later is too difficult, I can use a colour picker program that I have (where it displays the colour that the mouse cursor is touching).

Thanks...
Re: How to create a color analyzer with JMyron?
Reply #1 - Oct 25th, 2008, 3:32am
 
I'm working on a matrix-averaging sketch right now. Part of making a mosaic of an image is the same color averaging you asked about. I think the following code is what you asked for. Though it's been a long time since you asked, hope this can help you out, or maybe the next person searching for help.

Quote:
//Michael Shaub
//Oct, 24, 2008
//www.cageybirds.com/blog
//-------------
//Based very much on "Myron_tracking" by JTNIMOY

/*
this is an example of averaging all the video pixels.
pixels are rendered as 1 full image rectangle.

last tested to work in Processing 0154

Mike Shaub

*/

import JMyron.*;  //calls the jMyron library

JMyron m;  //a camera object
int avgColor = 0;  //single integer color for camera average

void setup(){
 size(320,240); //display size
 m = new JMyron();//make a new instance of the object
 m.start(width,height);//start a capture at 320x240
 println("Myron " + m.version());
 noStroke();
}

void draw(){
 background(255);
 m.update();//update the camera view
 int[] img = m.image(); //get the normal image of the camera

 //measures average color "Variable = m.average(left, top, right, bottom)"
 avgColor = m.average(0, 0, width, height); //measures average color value of entire image

 //Set fill color to average values
 fill(red(avgColor),green(avgColor),blue(avgColor)); //red() calls red channel value from single integer color
 rect(0,0,width,height); //draw rectangle on entire screen filled with average color

 //Output Text of RGB values
 println("Red = " + red(avgColor)
   + ", Green = " + green(avgColor)
   + ", Blue = " + blue(avgColor));

}

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

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



Page Index Toggle Pages: 1