Systems: Win 7 64 bit Home, HTC Evo 3d ICS, and Processing 2.0b6
Hello, I was able to figure out a work around for this, but it seemed a little funny so I thought I would post it and see if anyone has any ideas.
Just as a preface, I converted the EdgeDetection example to make it work with android and P3D by putting in a setup and draw functions. It crashes without a setup like that while using the P3D renderer.
Ok, so everything works fine when I run the sketch in java mode with P3D on my windows 7 machine, but as soon as I flip to android and run it on my device, I get what looks like noisy line streaks with very little resemblance to my image. After messing around a bit, I accidentally left a loadPixels() call in my draw loop, and strangely enough on the first loop it gave me noise, and then on the second loop the loadPixels() was called again and the image cleaned up showing the image with edges detected. Didn't get it but was slightly relieved something was happening, so I deleted the loadPixels() in the draw function and just added two loadPixels() in the setup function where the image first gets called, and after that, everything works as expected. Any Ideas? Code is below:
/**
* Edge Detection.
*
* Exposing areas of contrast within an image
* by processing it through a high-pass filter.
*/
float[][] kernel = { { -1, -1, -1 },
{ -1, 9, -1 },
{ -1, -1, -1 } };
PImage img;
PImage edgeImg;
void setup(){
orientation(PORTRAIT);
size(200, 200,P3D);
img = loadImage("house.jpg"); // Load the original image
edgeImg = createImage(200, 200, ARGB);
img.loadPixels();
img.loadPixels(); //Why do I have to call this twice?
edgeImg.loadPixels();
edgeImg.loadPixels(); //Why do I have to call this twice?
}
void draw(){
// Create an opaque image of the same size as the original
// Loop through every pixel in the image.
for (int y = 1; y < 200-1; y++) { // Skip top and bottom edges
for (int x = 1; x < 200-1; x++) { // Skip left and right edges
float sum = 0; // Kernel sum for this pixel
for (int ky = -1; ky <= 1; ky++) {
for (int kx = -1; kx <= 1; kx++) {
// Calculate the adjacent pixel for this kernel point
int pos = (y + ky)*200 + (x + kx);
// Image is grayscale, red/green/blue are identical
float val = brightness(img.pixels[pos]);
// Multiply adjacent pixels based on the kernel values
sum += kernel[ky+1][kx+1] * val;
}
}
// For this pixel in the new image, set the gray value
// based on the sum from the kernel
edgeImg.pixels[y*img.width + x] = color(sum);
edgeImg.updatePixels();
}
}
// State that there are changes to edgeImg.pixels[]