Making a desktop app using opencv in java/kotlin on Linux (Ubuntu)

Hi,

I am trying to make a desktop app in kotlin to experiment with various ideas to analyze videos. However I am unable to get opencv on my app.

Things I have tried:

  • importing opencv as a dependency by adding it to my `build.gradle.kts` file (I tried to get it from jitpack,io or maven, and strangely adding `implementation(“org.opencv:opencv:4.10.0”)` works for including opencv to an android app)
  • build opencv myself and then link the jar file to my application. However, when building opecncv, java cannot be found. The command I ran was: `cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_JAVA=ON -D BUILD_opencv_java=ON -D BUILD_opencv_java_bindings_generator=ON ..`, but the output I got was:
    ```

– Java:
– ant: /usr/bin/ant (ver 1.10.14)
– Java: NO
– JNI: /usr/lib/jvm/java-17-openjdk-amd64/include /usr/lib/jvm/java-17-openjdk-amd64/include/linux /usr/lib/jvm/java-17-openjdk-amd64/include
– Java wrappers: YES (ANT)
– Java tests: NO
```

And then after building and obtaining the jar, the kotlin compilter would not recognize any opencv dependency.

I would really appreciate if someone could explain me either how to build opencv in a way that detects java or how to import it.

You got to “Use the Force” man. Install Cursor or VS Code or Antigravity editor. Then ask it to create a build script for you to acquire, build, and install a CV2, FFMPEG version for you. It will be an iterative process. Cut and paste the build errors you see into the prompt and it will keep fixing it until the build script is complete. Ask it to check the build flags because sometimes building the library’s are all it does, but it doesn’t build the binaries that use them so it looks like you never get a custom set built when you run ffmpeg -version (it shows the old stale version). Plan on spending 1-2 hours fighting the build scripts with Cursor, but you will make progress and achieve victory.