Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullpointer exception with Video Library and Processing 4 #7

Closed
cansik opened this issue Feb 15, 2021 · 2 comments
Closed

Nullpointer exception with Video Library and Processing 4 #7

cansik opened this issue Feb 15, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@cansik
Copy link
Owner

cansik commented Feb 15, 2021

Currently it's not possible to use processing 4 and the video library to inference webcam images. Here the stacktrace:

Processing video library using GStreamer 1.16.2
java.lang.NullPointerException
	at ch.bildspur.vision.util.CvProcessingUtils.toCv(CvProcessingUtils.java:104)
	at ch.bildspur.vision.network.BaseNeuralNetwork.convertToMat(BaseNeuralNetwork.java:28)
	at ch.bildspur.vision.network.BaseNeuralNetwork.run(BaseNeuralNetwork.java:18)
	at YOLOWebcamExample.draw(YOLOWebcamExample.java:71)
	at processing.core.PApplet.handleDraw(PApplet.java:2460)
	at processing.javafx.PSurfaceFX$1.handle(PSurfaceFX.java:91)
	at processing.javafx.PSurfaceFX$1.handle(PSurfaceFX.java:87)
	at com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(TimelineClipCore.java:239)
	at com.sun.scenario.animation.shared.TimelineClipCore.playTo(TimelineClipCore.java:197)
	at javafx.animation.Timeline.doPlayTo(Timeline.java:177)
	at javafx.animation.AnimationAccessorImpl.playTo(AnimationAccessorImpl.java:39)
	at com.sun.scenario.animation.shared.InfiniteClipEnvelope.timePulse(InfiniteClipEnvelope.java:110)
	at javafx.animation.Animation.doTimePulse(Animation.java:1101)
	at javafx.animation.Animation$1.lambda$timePulse$0(Animation.java:186)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at javafx.animation.Animation$1.timePulse(Animation.java:185)
	at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
	at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:515)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:499)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:492)
	at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:320)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
	at java.base/java.lang.Thread.run(Thread.java:834)
NullPointerException
NullPointerException
WARNING: no real random source present!
@cansik cansik added the bug Something isn't working label Feb 15, 2021
@cansik cansik self-assigned this Feb 15, 2021
@cansik
Copy link
Owner Author

cansik commented Feb 15, 2021

The problem can be reproduced with the following example:

import processing.video.*;

import java.awt.image.*;
import java.nio.*;

Capture cam;

void setup() {
  size(640, 480);
  cam = new Capture(this, "pipeline:autovideosrc");
  cam.start();
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }

  image(cam, 0, 0, width, height);

  // expect NPE in Processing 4.0a3
  demo(cam);
}

void demo(PImage img) {
  BufferedImage image = (BufferedImage) img.getNative();
  WritableRaster raster = image.getRaster();
  DataBuffer dataBuffer = raster.getDataBuffer();
  DataBufferInt pixelBuffer = (DataBufferInt)dataBuffer;
  int[] pixels = pixelBuffer.getData();

  println("Pixels: " + pixels.length);
}

This code is used in OpenCV for Processing to convert a PImage into a Mat.
Related to processing/processing4#80 (removal of AWT in PImage)

@cansik
Copy link
Owner Author

cansik commented Feb 15, 2021

Fixed by using internal PImage.pixels directly. Please use loadPixels() if necessary (96065fb)

@cansik cansik closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant