implement a runnable thread
in
Android Processing
•
5 months ago
Hello all. Here's a problem which is not just link to android mode I guess.
I would like to implement a runnable thread to increase the stack size in my android application. (stack size is smaller in android by default which causes stack overflow of blobs detection).
several try and weird things. The main problem is null pointer exception occurs (caused by the blobdetection instruction.)
In java mode I can make the thread work but first weird thing=
here's the whole code:
main tab:
I would like to implement a runnable thread to increase the stack size in my android application. (stack size is smaller in android by default which causes stack overflow of blobs detection).
several try and weird things. The main problem is null pointer exception occurs (caused by the blobdetection instruction.)
In java mode I can make the thread work but first weird thing=
- void run()
{
finished = false;
println("hello thread");
img1 = loadImage("1.jpg");// WHEN I REMOVE THIS I GOT NULL POINTER EXCEPTION //EVEN IN JAVA MODE !
img.loadPixels();
theBlobDetection.computeBlobs(img.pixels);
img.updatePixels();
finished = true;
println("thread finished");
}
here's the whole code:
main tab:
- // blob detection library= http://www.v3ga.net/processing/BlobDetection/index-page-download.html
Thread t ;
import blobDetection.*;
PGraphics img;
PImage img1;
BlobDetection theBlobDetection;
boolean finished;
void setup()
{
size(640, 480);
background(255, 0, 0);
graphics();
Thread t =new Thread(new trid());
ThreadGroup group = new ThreadGroup("group");
t.start();
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(false);
theBlobDetection.setThreshold(0.38f);
}
void draw()
{
if (finished)
{
image(img, 0, 0, width, height);
drawBlobsAndEdges(true, true);
}
}
draw blob tab:
- // ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{
noFill();
Blob b;
EdgeVertex eA, eB;
for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++)
{
b=theBlobDetection.getBlob(n);
if (b!=null)
{
// Edges
if (drawEdges)
{
strokeWeight(2);
stroke(0, 255, 0);
for (int m=0;m<b.getEdgeNb();m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(
eA.x*width, eA.y*height,
eB.x*width, eB.y*height
);
}
}
// Blobs
if (drawBlobs)
{
strokeWeight(1);
stroke(255, 0, 0);
rect(
b.xMin*width, b.yMin*height,
b.w*width, b.h*height
);
}
}
}
}
image graphics tab:
- void graphics()
{
img = createGraphics(640, 480);
img.beginDraw();
img.background(255);
img.noStroke();
img.fill(0);
for (int i=0;i<10;i++) {
float r = random(50);
img.ellipse(random(img.width), random(img.height), r, r);
}
img.endDraw();
}
thread tab:
- public class trid implements Runnable {
Thread t;
ThreadGroup group;
Runnable r;
void start()
{
t = new Thread(group, r, "My Thread", 65536);
}
void run()
{
finished = false;
println("hello thread");
img1 = loadImage("1.jpg");// WHEN I REMOVE THIS I GOT NULL POINTER EXCEPTION EVEN IN JAVA MODE !
img.loadPixels();
theBlobDetection.computeBlobs(img.pixels);
img.updatePixels();
finished = true;
println("thread finished");
}
}
Any help to implement this runnable would be just great ! maybe it should be extended to the blob detection class…don't really know…
merci
merci
1