I have built, and got working, a polar graphic plotter. The machine uses a processing sketch, which scans from left to right, top to bottom, on an image, (much like an old CRT scans an image). The data is churned out onto an arduino which plots the image.
it currently producesdiamond images: I use Gimp, to manually rotate the image through 135 degrees. The "top left" of the image, actually becomes the bottom point of the image.
I want to produce "square" not "diamond" images, while maintaining the 45 degree line passes (as a necessity, due to the way the plotter works)
does anyone have any suggestions for scanning an image at 45 degrees, rather than left to right.
I suppose instead of looping around, adding 1 to x every time, i could add 1 to both X and Y, simultaneously, but would need to keep track of the "edge" of the image, as each pass will be of a different length.
Is there a function for detecting the edge of an image?
Hi there all. I am currently using the following lines of code, to extract greyscale values from pixels in an image:
color c = get(x, y);
float greyscalein = brightness(c);
i have moved my project (a plotter, of sorts) onto working colour. therefore i would like to extract colour values instead.
Ideally in CMYK, but i'm sure it could be converted if it is in a different format.
i presume i need to change the "brightness" bit to something else, except what i really want is not to see what hue the pixel is, but rather, on 3 passes, HOW MUCH C, how much M and how much Y is on the pixel
The code below, does exactly as i want in terms of processing the image, and converting it into a stream of values.
however i want it to
1) wait for an initial "ready" command from the ardunio
2) wait for a "ready" command from the arduino in between each and every number transmission.
the arduino is processing the numbers physically, and therefore takes time.
I have used "300" as my ready command because the sketch is dealing in shades between 0 and 255. I figure it it one less thing to worry about if i dont start chucking ascii in there too.
My "commands" can be 300, 301, 302 etc.
I THINK i have narrowed down the lines which need attention to lines 17 and 33. I pressume i need a "serial Event" void in there? but i am dont know what to do with it. All the tutorials i have read and watched (of which there are many) do different things with it, none of which i understand properly. I presume what is required here depends on the context?
Many thanks
Ol
import processing.serial.* ;
Serial myPort;
int ready = 300; // greyscale is 0-255. decided to use 300+ as commands, to prevent from mixing ascii with numbers.
PImage img1;
int cellSize = 10; // size of cells into which the image is split, larger size = less cells
int squareSize = 300; // size of the working frame
float greyscale;
void setup() {
size(squareSize, squareSize);
println(Serial.list());
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
print("Port: ");
println(myPort);
myPort.clear();
myPort.read();
myPort.bufferUntil(ready); // ********this is SUPPOSED to wait for a "ready" signal from the arduino (sent on button press) It doesn’t, obviosuy
}
void draw() {
background(0);
img1 = loadImage("grad.jpg"); // image, 300 x 300
imageMode(CENTER);
image(img1, (squareSize/2), (squareSize/2)); // draws the image
for (int y = 0; y < squareSize; y = y + cellSize ) {
// "carrige return" instruction from processing to the arduino will go in here (probably)
for (int x = 0; x < squareSize; x = x + cellSize) {
color c = get(x + cellSize/2, y + cellSize/2);
float greyscale = brightness(c); // Sets 'greyscale' to 255-0
println(greyscale); //show the greyscale
myPort.write(c); // send it to the arduino
myPort.clear(); // clear the port
delay (300); // delay for easy reading
myPort.bufferUntil(ready); // ***** this is SUPPOSED to WAIT until the arduino replies that it is ready.
}
}
}
void serialEvent (Serial myPort) {
myPort.read(); // ******* Not really sure what is needed here., or if serial Event is needed at all?
The code is supposed to reference an image, return a greyscale value for a pixel (in this case 5 pixels in and then return the greyscale for the 15th pixel, then 25th, etc)
I havent yet bothered to build the "go to next line" or a "next pixel please" part into my arduino. I am just trying to get it to provide a series of numbers at present, then i will build on it.
the image (grad.jpg) is currently just a gradation from black to white, not that that matters i suppose
I think the first one (number), gets through (the arduino makes a suitable movement) but then it stops.
i do not get the value for the shade printed on the black box at the base of the processing window, as requested in line 34.
can anyone please tell me how to i make lines 30, through to 35 loop until the end of the image is reached?
I presume I cant just stick them in a loop, as they are already in a serialEvent void?
import processing.serial.* ;
Serial myPort;
boolean firstContact = false;
PImage img1;
int cellSize = 10; // size of cells into which the image is split, larger size = less cells
int squareSize = 300; // size of the image square (double horizontally to allow for processed image)
int x = 0;
int y = 0;
void setup() {
println(Serial.list());
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
myPort.bufferUntil('A');// waiting on response from arduino
size(squareSize, squareSize); // frame is 500 x 500
img1 = loadImage("grad.jpg"); // image, 300 x 300
imageMode(CENTER);
}
void draw() {
image(img1, 150, 150); // draws the image
}
void serialEvent(Serial myPort) {
int inByte = myPort.read();
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
else {
for (int x = 0; x < squareSize; x = x + cellSize ) {
for (int y = 0; y < squareSize; y = y + cellSize) {
I've literally started playing with processing this evening (2 hours or so) so please excuse me if my questions are REALLY stupid.
I am making a polargraphic plotter using an arduino (the physical arduino side of it i have working fine) and am venturing into the world of processing to process the images i wish to plot, into workable serial data (which i will then push into the arduino, or at least, thats the plan)
Because of the way a polargraphic plotter works, i have decided to rotate the image 45 degrees left, and centre it on a frame bigger than it needs.
this "setup" part of the sketch works fine, and gives the result i want.
I then want to process the image into much larger "pixels", which will then be used to proved lower resolution greyscale data.
i initially tried just to resize the image, but it wasnt very successful, and i want the option of controlling how the pixels are averaged in the future, so i am going for the effect shown in the "get()" tutorial:
I want to scan down the image, which is 300 x 300 px, and fill squares 10 px by 10 px, with the colour of the underlying image (at this time, i am just taking the pixel in the middle of each 10 x 10 square)
When i run the sketch, the image i have loaded loads briefly in the background, but is then overlaid by 30 x 30 squares of flat grey.
can anyone point out what i have done wrong, i am currently bashing at trial and error and not really getting anywhere.
here is my sketch:
PImage img1;
int x = 0;
int y = 0;
void setup() {
size(500, 500); // frame is 500 x 500
pushMatrix();
// Make a new instance of a PImage by loading an image file
img1 = loadImage("STRS.jpg"); // stormtrooper image, 300 x 300
translate(250, 250); // moves pivot to keep central
rotate(radians(315)); // rotates 45 degrees ACW
imageMode(CENTER);
image(img1, 0, 0); // draws the image
}
void draw() {
for (int x = 0; x < 500; x = x + 10 ) {
for (int y = 0; y < 500; y = y + 10) {
color c = get(x + 5, y + 5);
fill(c);
stroke(100); // bounded by a box, dark grey
rect(x, y, x + 10, y + 10);
}
}
}
Hope someone can help, and that i haven’t done something embarrassingly stupid.