Ask Your Question
1

Issue using OpenCV 4.1.1 and Tracking API in Java

asked 2019-11-12 12:00:52 -0500

dhirwinjr gravatar image

All,

I'm trying to leverage the opencv-contrib's Tracking API in a Java application but am currently seeing an "java.lang.UnsatisfiedLinkError: org.opencv.tracking.TrackerCSRT.create_0()J" exception in my Java program. Here's what I've done to get to that point...realizing that the Tracking API is not included in the pre-built OpenCV releases I successfully built OpenCV 4.1.1 from source along with the opencv-contrib-4.1.1 release (where the Tracking API code resides). I've never built OpenCV before so it was all new to me but I finally got that working (sort of). Here's my environment:

  • Windows 7 64-bit
  • CMake 3.16.0-rc3
  • Microsoft Visual Studio Community 2019 (version 16.3.8)
  • OpenCV 4.1.1

I followed the instructions from here: https://cv-tricks.com/how-to/installa...

Initially, I did NOT have the BUILD_opencv_world option selected in CMake and so it was just building all of the *.dll files separately (including the "opencv_tracking411.dll" file) and didn't know how to easily load the necessary native libraries into my Java program (as a comparison, when you download the pre-built release of OpenCV, there's a "opencv-411.jar" file along with a single "opencv_java411.dll" file that I use to load into my Java program). I did not see the "opencv_java411.dll" file in the "build/bin/Release" directory when I originally built OpenCV from source. So I turned on the BUILD_opencv_world option and it generated the "opencv_world411.dll" file. Being a bit confused about what *.dll files I now need, I'm currently only loading the "opencv_world411.dll" file into my Java program. The program runs and loads OpenCV and works until it hits the code that leverages the Tracking API. In particular it throws the following exception when instantiating a Tracker object (I'm assuming that this is because the "opencv_tracking411.dll file isn't actually being loaded):

Caused by: java.lang.UnsatisfiedLinkError: org.opencv.tracking.TrackerCSRT.create_0()J
at org.opencv.tracking.TrackerCSRT.create_0(Native Method)
at org.opencv.tracking.TrackerCSRT.create(TrackerCSRT.java:32)

So at this point I have the following questions:

  1. What steps in the OpenCV build process do I need to follow to generate the "opencv_java411.dll" file. Is the "opencv_world411.dll" that file just renamed?
  2. Is the "opencv_tracking411.dll" file linked and included in the "opencv_world411.dll" file? If not, is there a way to configure that in CMake? Or will I need to load the "opencv_tracking411.dll" file in my Java program separate from the "opencv_world411.dll" file?
  3. If I need to load the "opencv_tracking411.dll" file separately, where can I find the native name that should be used? For reference, to load the core OpenCV library in my Java program I use " System.loadLibrary(Core.NATIVE_LIBRARY_NAME);" which works.

Thanks for any feedback and help.

Dave

edit retag flag offensive close merge delete

Comments

after you build OpenCV if you have opencv_tracking411.dll and opencv-411.jar you should have opencv_java411.dll ( search it in build directories)

sturkmen gravatar imagesturkmen ( 2019-11-12 12:35:23 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-11-12 12:12:37 -0500

berak gravatar image

updated 2019-11-12 12:15:16 -0500

please try again with:

cmake -DBUILD_SHARED_LIBS=OFF

this should result in a fat opencv_java411.dll, which should be all you ever need. (not dependant on any other opencv dlls, also already including the tracking c++ code)

(also switch off BUILD_opencv_world)

edit flag offensive delete link more

Comments

1

Thanks so much for the response. Your suggestions did result in generating the "opencv_java411.dll" file in the "build/lib/Release" directory (I did a full clean build from scratch following your recommendation above).

At this point, however, I'm now just having issues using the newly compiled version of OpenCV to open a *.mp4 local video file using the Java VideoCapture object. Running against the pre-compiled version of OpenCV 4.1.1 and that part works, now opening the video file and checking if the recording is opened just returns false with no errors. I think I'm going to delete everything a do a full and complete re-compile. I'm totally new to building OpenCV; anything that I should look for when compiling?

Thanks, Dave

dhirwinjr gravatar imagedhirwinjr ( 2019-11-12 20:39:40 -0500 )edit
1

So I did a totally clean re-build of OpenCV 4.1.1 and also realized that I had accidentally included a 32-bit ffmpeg dll file in my java native path. I'm guessing it was the latter that was causing the problem with the video not starting. At this point I have the compiled OpenCV 4.1.1 running with the Tracking API in my Java application! Thank you again for the help.

Dave

dhirwinjr gravatar imagedhirwinjr ( 2019-11-12 22:26:08 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-11-12 12:00:52 -0500

Seen: 39 times

Last updated: Nov 12