Scanning Line
in
Contributed Library Questions
•
1 years ago
Can anyone Help?
I have a an image in processing that is being scanned to look for black pixels which, once a black pixel is found, prints the y axis coordinate.
I need a line to be scanning down the image as it reads it, can anyone help me with this? I have a line drawn on the image but I need it to move down as it scans. Here is the code so far.
/**
* oscP5sendreceive by andreas schlegel
* example shows how to send and receive osc messages.
* oscP5 website at
http://www.sojamo.de/oscP5
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
PImage img;
int myx = 1;
int pixelMessage;
void setup() {
size(398, 5184);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
/* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
* an ip address and a port number. myRemoteLocation is used as parameter in
* oscP5.send() when sending osc packets to another computer, device,
* application. usage see below. for testing purposes the listening port
* and the port of the remote location address are the same, hence you will
* send messages back to this sketch.
*/
myRemoteLocation = new NetAddress("127.0.0.1",12001);
img = loadImage("final.jpg");
}
void draw() {
background(0);
img.loadPixels();
image(img,0,0);
//creates a loop that will consider each pixel in turn
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int loc = x + y*width;
{ line(0, 350, width, 350);
stroke(255, 0, 0); }
//test to see if the pixel being considered is black
if(img.pixels[loc]==color(0,0,0)){
//delay slows down the process so we can see it
delay(100);
//print the column (x)
println (x);
/* in the following different ways of creating osc messages are shown by example */
OscMessage myMessage = new OscMessage("/test");
myMessage.add(x); /* add an int to the osc message */
/* send the message */
oscP5.send(myMessage, myRemoteLocation);
}
}
}
}
1