3

I'm trying to use OpenCV with Processing 4 on a MAC with Catalina. However, I am getting the following error:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by gab.opencv.OpenCV (file:/Users/mmemmo/Documents/Processing/libraries/opencv_processing/library/opencv_processing.jar) to field java.lang.ClassLoader.sys_paths

when I run this code

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

Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  //CASCADE_EYE
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
 // opencv.loadCascade(OpenCV.CASCADE_EYE);  

  video.start();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
  
  if(faces.length > 0 ){
    println("Hello Human");enter code here
  }
}

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

I know Processing has camera issues with Catalina. That doesn't seem to be the issue here. I was able to get the camera working just fine in other sketches.

I would appreciate any feedback. Thanks.

stateMachine
  • 5,227
  • 4
  • 13
  • 29

2 Answers2

3

The module system introduced in Java 9 has more limitations in what modules can use of the functionality of other modules. See this question and answers for more information: what is an illegal reflective access

Is there a specific reason that you are using Processing 4? There are only alpha releases available at the moment, so I would use Processing 3 if possible. When I try to run your code in Processing 4, I get the same error as you. When I run your code in Processing 3.5.4 (on Ubuntu), it runs without any issues and facial recognition is working. I would recommend giving Processing 3 a try.

Freek de Bruijn
  • 3,552
  • 2
  • 22
  • 28
  • 2
    Thank you for your response. That was very helpful. I was using Processing 4 because there were reported issues with all previous versions of processing and MAC OS Catalina. However. this worked with 3.5.4!! As a note, I did have to run it through terminal to get the camera to work. Otherwise, MAC OS doesn't give you permission to access the camera. Thanks again. – Matthew Memmo Feb 20 '21 at 18:04
0

I modified opencv-processing library and it works with processing 4. Not perfect, but it works anyway. https://github.com/jaegonlee/opencv-processing/releases

The original opencv-processing library set library path with this code. But it doesn't work with Java 11(Processing 4), and causes warnings.

public static void setLibraryPath(String path) throws Exception {
    System.setProperty("java.library.path", path);

    //set sys_paths to null so that java.library.path will be reevalueted next time it is needed
    final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
    sysPathsField.setAccessible(true);
    sysPathsField.set(null, null);
}

I deleted it and the warnings are gone. The modified library works fine with Processing IDE, but exported application does not work on macOS.

Jaegon Lee
  • 11
  • 1
  • Link only answers are considered very low quality because it does not directly answer the question and solve the problem. Links are usually used as a reference to the answer that is given – I_love_vegetables Jul 23 '21 at 07:31