# OpenCV error in Processing 4.0b2

**URL:** <https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284>\
**Category:** Libraries\
**Created:** [November 3, 2021, 3:42pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284 "2021-11-03T15:42:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dazzid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dazzid/32/2870_2.png) [@Dazzid](https://discourse.processing.org/u/Dazzid)\
**Post date:** [November 3, 2021, 3:42pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/1 "2021-11-03T15:42:18Z")

</div>

I’m preparing a workshop using Processing 4.02b, but OpenCV library seems to have an issue with permissions.

> WARNING: Illegal reflective access by gab.opencv.OpenCV (file:/Users/Name/Documents/Processing/libraries/opencv\_processing/library/opencv\_processing.jar) to field java.lang.ClassLoader.sys\_paths  
> WARNING: Please consider reporting this to the maintainers of gab.opencv.OpenCV  
> WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations  
> WARNING: All illegal access operations will be denied in a future release  
> NullPointerException

Any suggestion to run OpenCV again?

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [November 3, 2021, 4:03pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/2 "2021-11-03T16:03:44Z")

</div>

This a java feature since java 11, but is normally (up to jdk11 at least) only a warning that you can ignore. Ideally you want the OpenCV library updated to module version that explicitly [permits reflective access](https://www.oracle.com/corporate/features/understanding-java-9-modules.html).

---

<div class="post-metadata">

**Author:** ![Dazzid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dazzid/32/2870_2.png) [@Dazzid](https://discourse.processing.org/u/Dazzid)\
**Post date:** [November 3, 2021, 4:06pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/3 "2021-11-03T16:06:11Z")

</div>

hence, what would be the solution, in particular to that NullPointerException?

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [November 3, 2021, 6:01pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/4 "2021-11-03T18:01:32Z")

</div>

The problem is not the warnings themselves. The warnings are telling you the library is doing something it shouldn’t be. In this case, setting a private field to null in such a way that worked in JDK 8 and throws an exception in JDK 11 - the internal behaviour of ClassLoader has changed quite a bit.

Also see [java - Processing 4 error: WARNING: Illegal reflective access by gab.opencv.OpenCV - Stack Overflow](https://stackoverflow.com/questions/66285416/processing-4-error-warning-illegal-reflective-access-by-gab-opencv-opencv)

---

<div class="post-metadata">

**Author:** ![Dazzid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dazzid/32/2870_2.png) [@Dazzid](https://discourse.processing.org/u/Dazzid)\
**Post date:** [November 3, 2021, 7:02pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/5 "2021-11-03T19:02:19Z")

</div>

hi Neilcsmith  
Thanks for the link. The solution for Processing 4 is here in this link

> **[Releases · jaegonlee/opencv-processing](https://github.com/jaegonlee/opencv-processing/releases)**
>
> OpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API - jaegonlee/opencv-processing

---

<div class="post-metadata">

**Author:** ![kkirklewski](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@kkirklewski](https://discourse.processing.org/u/kkirklewski)\
**Post date:** [March 7, 2022, 8:07pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/6 "2022-03-07T20:07:31Z")

</div>

Thanks for OpenCV for Processing 4.

However, I still got the error “A library used by this sketch relies on native code that is not available. UnsatisfiedLinkError: no opencv\_java400 in java.library.path: :/Applications/Processing.app/Contents/Java/core/library/macos-x86\_64:…”

Do you maybe know what can cause this?

---

<div class="post-metadata">

**Author:** ![carterjohnson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/carterjohnson/32/8790_2.png) [@carterjohnson](https://discourse.processing.org/u/carterjohnson)\
**Post date:** [March 13, 2022, 7:01pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/7 "2022-03-13T19:01:43Z")

</div>

I am receiving the same exact error despite that fix. Have you been able to resolve this issue yourself?

---

<div class="post-metadata">

**Author:** ![kkirklewski](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@kkirklewski](https://discourse.processing.org/u/kkirklewski)\
**Post date:** [March 13, 2022, 7:37pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/8 "2022-03-13T19:37:32Z")

</div>

Yes, I solved it by copying the file “libopencv\_java400.dylib” to /Applications/Processing.app/Contents/Java/core/library  
Of course, with updated library from above. Let me know if it fixed your case.

---

<div class="post-metadata">

**Author:** ![bhaskar1955](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@bhaskar1955](https://discourse.processing.org/u/bhaskar1955)\
**Post date:** [August 13, 2022, 2:37pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/9 "2022-08-13T14:37:31Z")

</div>

I am new in Image/video processing field. I want to learn OpenCV in Processing 4.0b2.  
I could not run the very first example “BackgroundSubtraction”. IDE throws the following messages:

Processing video library using bundled GStreamer 1.16.2  
java.lang.NoSuchFieldException: sys\_paths  
at java.base/java.lang.Class.getDeclaredField(Class.java:2610)  
at gab.opencv.OpenCV.addLibraryPath(Unknown Source)  
at gab.opencv.OpenCV.initNative(Unknown Source)  
at gab.opencv.OpenCV.(Unknown Source)  
at BackgroundSubtraction.setup(BackgroundSubtraction.java:30)  
at processing.core.PApplet.handleDraw(PApplet.java:2142)  
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1440)  
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)  
OpenCV for Processing 0.5.4 by Greg Borenstein [http://gregborenstein.com](http://gregborenstein.com)  
Using Java OpenCV 2.4.5.0  
IllegalArgumentException: Width (0) and height (0) cannot be \<= 0  
IllegalArgumentException: Width (0) and height (0) cannot be \<= 0  
IllegalArgumentException: Width (0) and height (0) cannot be \<= 0  
Could not run the sketch (Target VM failed to initialize).  
For more information, read Help ? Troubleshooting.

At line no. 20 IDE shows the command " opencv.loadImage(video); " highlighted.

Please help me.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 13, 2022, 3:12pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/10 "2022-08-13T15:12:45Z")

</div>

Hello @bhaskar1955,

The example works with:

- Windows 10
- Processing 4.01 (August 9, 2022)
- [Releases · jaegonlee/opencv-processing · GitHub](https://github.com/jaegonlee/opencv-processing/releases)

I did get this error:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/7/b7970501fe497b9a05476d52a87b7d19aa722ecf.png)

And added this delay to correct that problem:

```auto
void setup() 
  {
  size(720, 480);
  video = new Movie(this, "street.mov");
  opencv = new OpenCV(this, 720, 480);
  
  opencv.startBackgroundSubtraction(5, 3, false);
  
  println(frameCount, video.width, video.height);
  
  video.loop();
  video.play();
  
  int t1 = millis();
  while (video.width == 0 )
    {
    //println(millis());
    if (millis() - t1 > 1000)
      {
      // Can add a message here if over 1000 ms or 1 s
      }
    }
  int t2 = millis();   
  println(t2-t1, video.width, video.height); 
  }

```

Relate discussion about that error:  
[https://forum.processing.org/two/discussion/23389/resizing-a-movie-possible-bug.html](https://forum.processing.org/two/discussion/23389/resizing-a-movie-possible-bug.html)

Working:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/6/168b131a7a7cf01962fb7016d913df5e04973ef2.jpeg)

---

<div class="post-metadata">

**Author:** ![bhaskar1955](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@bhaskar1955](https://discourse.processing.org/u/bhaskar1955)\
**Post date:** [August 13, 2022, 3:28pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/11 "2022-08-13T15:28:12Z")

</div>

Thanks a lot **glv** for your kind and quick response. Soon I shall post my experience.

---

<div class="post-metadata">

**Author:** ![bhaskar1955](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@bhaskar1955](https://discourse.processing.org/u/bhaskar1955)\
**Post date:** [August 14, 2022, 1:07pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/12 "2022-08-14T13:07:42Z")

</div>

Yes, @glv , it worked. Thanks again. I hope you will help me in the future also.

Regards

---

<div class="post-metadata">

**Author:** ![pleek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pleek/32/21071_2.png) [@pleek](https://discourse.processing.org/u/pleek)\
**Post date:** [October 24, 2022, 4:38pm UTC](https://discourse.processing.org/t/opencv-error-in-processing-4-0b2/33284/13 "2022-10-24T16:38:58Z")

</div>

Thanx a lot @Dazzid …!! This really help me. And also thanx @kkirklewski for the tip on moving the file.  
I was going crazy trying to make it work on a mac M1 Monterey, processing 4.

Though this might help:  
With the info on this current thread, and the following line of code (for gstreamer), I was able to run it correctly.

Instead of initializing the Capture instance like this:  
video = new Capture(this, width, height);

Do it like this:  
video = new Capture(this, 640, 480, “pipeline:avfvideosrc device-index=0 ! video/x-raw, width=640, height=480, framerate=30/1”);
