Exporting sketch - crash on startup (MAC)

Hi,

I’m really new to Processing but starting to get into it. Currently I’m stuck trying to export my sketch. I’m using three libraries: opencv, processing video and java.awt. The sketch is supposed to start the built in webcam (OS Mojave). The app crashes on startup and shows the following message:

Cannot load GStreamer plugins from /Users/…/sketch_190213a/application.macosx64/sketch_190213a.app/Contents/Java//plugins

The capture plugin does not support device query!

java.lang.RuntimeException: There are no capture devices connected to this computer.

Thanks in advance!

My full code (because I’m lost…)

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

int number = 1;
int wasCaptured = 0;
String rawSlice = "rawslice/";
String newSlice = "newslice/";
String systemStatus;
int c1 = color(2, 71, 254);
int c2 = color(255);
boolean keyDelay = false;
long lastTime = 0;

PImage slice, capturedImage, gray, dst, polySlice, drawNewSlice;

ArrayList<Contour> contours;
ArrayList<Contour> polygons;
Capture video;
OpenCV face;
OpenCV opencv;

void settings() {
  size(1080, 480);
}

void setup() {
  size(1080, 480);
  video = new Capture(this, 640/2, height/2);
  face = new OpenCV(this, 640/2, height/2);
  face.loadCascade(OpenCV.CASCADE_FRONTALFACE);
  background(c1);
  lastTime = millis(); 

  video.start();
}

void draw() {
  scale(2);
  face.loadImage(video);
  image(video, 0, 0 );

  noFill();
  stroke(0, 0, 255);
  strokeWeight(2);
  Rectangle[] faces = face.detect();

  for (int i = 0; i < faces.length; i++) {
    if (faces.length > 0  && faces[i].height <= 115 && faces[i].height >= 75) {
      rectMode(CORNER);
      rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
      slice = get(faces[i].x * 2, faces[i].y * 2, faces[i].width * 2, faces[i].height * 2);
    }
    
    //feedback face detection
    rectMode(CENTER);
    fill(c1);
    noStroke();
    rect(320/2, 5, 100, 10);
    if (faces.length > 0 && faces[i].height >= 115) {
      systemStatus = "Too close to camera";
    } else if (faces.length > 0 && faces[i].height <= 75) {
      systemStatus = "Too far from camera";
    } else {
      systemStatus = "Face detected";
    }
    textAlign(CENTER);
    fill(c2);
    textSize(6);
    text(systemStatus, 320/2, 6, 100, 10);
  }
  
    if (wasCaptured >= 1) {
      drawPoly();
    } else {
      println("No image selected");
    }
    
    if (millis() - lastTime > 1000 && keyDelay == true) {
      keyDelay = false;
    }
  
    println("Number = " + number + keyDelay);
}

void captureEvent(Capture c) {
  c.read();
}

void keyPressed() { // Create slice on keypress
  if (key == ' ' && keyDelay == false) {
    captureAndSave();
    capturedImage = loadImage(rawSlice + "rawSlice" + nf(number - 1, 1) + ".png");
    wasCaptured++;
    keyDelay = true;
    lastTime = millis();
  } else if (key == ' ' && keyDelay == true) {
    println("Please wait...");
  }

  if (key == 'r') {
    wasCaptured = 0;
    background(c1);
  }
}

void captureAndSave() { // Save slice and iterate
  slice.save(rawSlice + "rawSlice" + nf(number, 1) + ".png");
  number++;
}

void captureNewSlice() {
  polySlice = get(640, 15, 440, 440);
  polySlice.save(newSlice + "newSlice" + nf(number - 1, 1) + ".png");
  delay(50);
}

void drawPoly() {
  opencv = new OpenCV(this, capturedImage);
  opencv.gray();
  opencv.threshold(90);
  gray = opencv.getSnapshot();
  dst = opencv.getOutput();
  //image(gray, 325, 15, 200, 200); // Actual slice

  contours = opencv.findContours();
  println("found " + contours.size() + " contours");

  //image(dst, 325, 15, 200, 200); // Opencv slice

  noFill();
  strokeWeight(2);

  scale(0.8);
  translate(425, 40);
  for (Contour contour : contours) {
    //contour.draw();

    beginShape();
    stroke(c2);
    for (PVector point : contour.getPolygonApproximation().getPoints()) {
       vertex(point.x, point.y);
    }
    endShape();
  }
  
  captureNewSlice();
}

what export settings you used?
more:
https://github.com/processing/processing/wiki/Export-Info-and-Tips ,

I exported for Mac OS and Embedded Java. Didn’t change anything else

did you ever export and run a
5 line sketch ( no libraries… )?

Yeah, they just run fine

can you check on that directories pls,
i worry the “//”
is that possible on MAC

I noticed that aswell. It shouldn’t be a thing but I don’t know why there’s two slashes…
I also don’t know how I could change that (or if thats even possible)

Thanks for trying though: bear with me as I try to understand and keep up.

hope the MAC specialists can jump in

I’ve read somewhere that it could be a 32/64bit issue. But how to fix it; that I didn’t find.

Thanks anyway @kll

old but good info:
https://forum.processing.org/one/topic/exporting-application-with-gstreamer.html

Mhmmm… The ‘gstreamer-java.jar’ file was exported correctly though, its in the contents. Could it still be missing parts?

Were you able to resolve this issue?

Just to confirm: this is a problem with exporting the Processing Video library on the same machine with the same camera – you are able to run the sketch in PDE and it runs fine with video, but when you export and run on the same laptop it fails. Is that right?

You may need debugging advice from video library gurus.

1 Like

able to run the sketch in PDE and it runs fine with video, but when you export and run on the same laptop it fails. Is that right?

Exactly right.

Have not been able to fix it yet…

I’m not sure why that would be happening. Sounds like we need some video library / GStreamer experts to weigh in on this.

Perhaps @hamoid has a suggestion for how to start debugging…?

I don’t own a Mac, but the first thing I would try is to make a minimal program that shows this issue. Maybe the video playback example that comes with the library shows this problem already when exported as an application?

ps. @neilcsmith is the gstreamer expert here :slight_smile:

I have tried setting up a minimal program and exporting it. I can successfully export a program that includes the opencv and video capture library (and the facial recognition works).

Could the contour function from opencv be the one causing the problem?

1 Like

Thanks @hamoid :stuck_out_tongue_winking_eye:

That plugin error message in the first post definitely looks suspect, particularly with the empty folder name Java//plugins. I do wish the Video library just went with a system installed version of GStreamer - be so much easier! The way the code currently looks I don’t think it’s even easily possible to set it to use one.

You might want to look at Video library v2 and see if that’s any better. At least anything with gstreamer-java rather than gst1-java-core in it has not been supported for years!

Is this related?

With v2 you mean the one that can be downloaded here, right?

Have you with tried v2, @has_sanity ?

Yes, although that’s also a bit old - we’re about to release gst1-java-core v1 which has a lot of fixes in it. I’m hopeful someone will pick up the Processing Video library for GSoC!

A key change since the Video library was first written is that the GStreamer project now releases Mac and Windows installers which makes things far easier if you don’t need to bundle the library for any reason. I think that should be the default for Processing. I just checked the v2 code though and it’s doing things to explicitly disable a system install except on Linux.

Just really quickly tried (have to be somewhere lol) and got this. Idk if it’s because of changes to the library which I missed, but posting it regardless because I’m lost.

(Processing core video:7346): GLib-GObject-WARNING **: cannot register existing type 'gchar'
**
GLib-GObject:ERROR:gvaluetypes.c:457:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help → Troubleshooting.

@hamoid @neilcsmith
It’s not really a must to find a fix for this, but it’d be really sick if there is a fix for it. I’m using it for an art project (uni), being able to export it properly would just make a few things easier. Thanks already though