Hello all,
I am trying to draw an .obj file offscreen under Android.
The image should then be passed to OpenCV for further use as a matrix.
In 2D the whole thing already works without problems.
public class ObjDrawer extends PApplet {
PGraphics buffer;
PShape obj;
int width;
int height;
public ObjDrawer(int width, int height) {
this.width = width;
this.height = height;
setup();
}
@Override
public void setup() {
buffer = createGraphics(this.width, this.height, P3D);
//obj = loadShape("Wuerfel_40mm.obj");
noLoop();
}
public Mat testDraw() {
buffer.beginDraw();
buffer.background(255);
buffer.ellipse(200, 200, 100, 100);
//buffer.shape(obj);
buffer.endDraw();
return toMat(buffer.get());
}
Mat toMat(PImage image) {
//source: https://gist.github.com/Spaxe/3543f0005e9f8f3c4dc5
int w = image.width;
int h = image.height;
Mat mat = new Mat(h, w, CvType.CV_8UC4);
byte[] data8 = new byte[w * h * 4];
int[] data32 = new int[w * h];
arrayCopy(image.pixels, data32);
ByteBuffer bBuf = ByteBuffer.allocate(w * h * 4);
IntBuffer iBuf = bBuf.asIntBuffer();
iBuf.put(data32);
bBuf.get(data8);
mat.put(0, 0, data8);
return mat;
}
}
When using 3D, I now get the following error message:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean processing.core.PGraphics.isGL()' on a null object reference
at processing.core.PApplet.makeGraphics(PApplet.java:1584)
at processing.core.PApplet.createGraphics(PApplet.java:1568)
at Analyzer.ObjDrawer.setup(ObjDrawer.java:52)
at Analyzer.ObjDrawer.<init>(ObjDrawer.java:45)
at com.quickbirdstudios.opencvexample.MainActivity$cvCameraViewListener$1.onCameraFrame(MainActivity.kt:75)
at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)
at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373)
at java.lang.Thread.run(Thread.java:920)
In my research I read about a3d, this is missing for me. Since all the stuff I found regarding a3d was about 10 years old: has anything changed in this regard or has it been replaced or do I need to include this separately?
I have included Processing as in the tutorial on https://android.processing.org/tutorials/android_studio/index.html
integrated. I use Android Mode for Processing 3 4.3.0, because the mode manager in Processing 4 is currently broken.
many thanks in advance!