Bit Shifting Colour/Color Tracking with Threshold, "for" help needed
in
Core Library Questions
•
2 years ago
Hi there,
Im making a bit shift colour tracker with a toggle that'll switch around a colour threshold.
At the moment ive got to the point where i can track the colours, but i cant get the toggle to work,
Im trying to test the tracked pixel to see if it is green enough using:
- for (color activetest = video.pixels[colorY*width+colorX]; ((activetest >> 8) & 0xFF)<200;){
- active = false;
- activetoggle = 0;
- }
Heres the rest of the code which works:
- int colorX = 0; // X-coordinate of the closest in color video pixel
- int colorY = 0; // Y-coordinate of the closest in color video pixel
- float activetoggle = 0;
- import oscP5.*;
- import netP5.*;
- boolean active = false;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- import processing.video.*;
- Capture video;
- int g;
- int ay;
- int ax;
- void setup(){
- size(600,600);
- video = new Capture(this, width, height, 30);
- smooth();
- /* Frame rate is 30 */
- /* The fill color is set to black (0) for the boundaries (drawn as a quad) */
- oscP5 = new OscP5(this,7474);
- myRemoteLocation = new NetAddress("127.0.0.1",7474);
- frameRate(30);
- }
- void draw(){
- if (video.available()) {
- video.read();
- image(video, 0, 0, width, height);
- video.loadPixels();
- int index = 0;
- for (int ay = 0; ay < video.height; ay++) {
- for (int ax = 0; ax < video.width; ax++) {
- // Get the color stored in the pixel
- color argb = video.pixels[index];
- int a = (argb >> 24) & 0xFF;
- int r = (argb >> 16) & 0xFF;
- int g = (argb >> 8) & 0xFF;
- int b = argb & 0xFF;
- if (g>200){
- active = true;
- colorY = ay;
- colorX = ax;
- activetoggle = 1;
- }
- index++;
- }
- }
- OscMessage myMessage = new OscMessage("/test");
- myMessage.add((int)colorX);
- myMessage.add((int)colorY);
- myMessage.add((float)activetoggle);
- /* send the message */
- oscP5.send(myMessage, myRemoteLocation);
- }
- }
Any help would be greatly appreciated.
Thanks
MilesTone
1