I'm just a 100% Freshfish in Processing, i've met some problems to realize my works.
I want make a Mimosa that when you detect the movement of Mimosa then launch SOMETHING(not defini yet). (when the finger touche the leaf of Mimosa, it close and fall down, and when the day light coming the leafs open, night fall the leafs close)....
here is a demostration of this plant and how it fonction.
There is two person helped me in different times and but in the end i think i need fusion this two code together.
Here is the first one that use color detection to detect the movement , it could choose the color and follow the movement, but in this code , there is just one point , my professor helped me and he said that need detect more points on the leaf.
Here is two code From one program that detect the color point,
----------------------------------------------Detect from Video----------------------------------------------------
import processing.video.*;
Capture video;
int numPixels; // number of pixels in the video
int rectDivide = 4; // the stage width/height divided by this number is the video width/height
int vidW; // video width
int vidH; // video height
int[][] colouredPixels; // the different colour references for each pixel
int[][] colourCompareData; // captured r, g and b colours
int currR; //
int currG; //
int currB; //
int[][] squareCoords; // x, y, w + h of the coloured areas
color[] colours; // captured colours
int colourRange = 25; // colour threshold
int[][] centrePoints; // centres of the coloured squares
color[] pixelColours;
boolean isShowPixels = false; // determines whether the square and coloured pixels are displayed
int colourMax = 2; // max amount of colours - also adjust the amount of colours added to pixelColours in setup()
int coloursAssigned = 0; // amount of cours currently assigned
CoordsCalc coordsCalc;
void setup()
{
size(640, 480);
vidW = width / rectDivide;
vidH = height / rectDivide;
video = new Capture(this, vidW, vidH, 30);
noStroke();
numPixels = vidW * vidH;
colouredPixels = new int[vidH][vidW];
colourCompareData = new int[colourMax][3];
squareCoords = new int[colourMax][4];
colours = new color[colourMax];
centrePoints = new int[colourMax][2];
color c1 = color(0, 255, 0);
color c2 = color(255, 0, 0);
pixelColours = new color[colourMax];
pixelColours[0] = color(0, 255, 0);
pixelColours[1] = color(255, 0, 0);
coordsCalc = new CoordsCalc();
}
void captureEvent(Capture video)
{
video.read();
}
void draw()
{
noStroke();
fill(255, 255, 255);
rect(0, 0, width, height);
drawVideo();
coordsCalc.update();
}
void drawVideo() {
image(video, 0, 0);
}
void mousePressed() {
// if outside video, forget the rest
if (mouseX >= video.width || mouseY >= video.height) return;
Here is another person helped me to detect the pixels on the image,but my intention is replace those image to Video, that could catch the movement of the leaf.
=============================Detect from images===========================================