How cross-platform is OpenCV? Can I do anything with java that I can with python?

Is there anything that you can’t do, or works poorly in one language or the other?
I’m working on a OpenCV-project in python which uses template matching and color detection. I may need some blob-analysis and such later.

I want to switch to java, but I’m unsure whether it can do the same with OpenCV? Some years ago people argued against using OpenCV with java, but is that still the case?

I haven’t been able to find anything conclusive in official documentation, at the forum or on Google.
What I have found:
https://www.reddit.com/r/opencv/comments/d8exn7/question_what_programming_language_is_best_for/

All opinions and inputs are welcome :slight_smile:

all those things are handled fine with opencv’s java api.
instead of collecting 3rd party opinions on SO or such, rather get your own impression from the tutorials (they’re multi-language !)

that said, why would you want to switch to java ?

Yea you got a point. If there’s a java version in the tutorial of what I need, it’s safe to assume that those parts works well with java.

I see I forgot to include one of the sites I found, there was one who had to do a lot of additional setup to use java. But I don’t assume that’s needed anymore, I think that was 7 years ago.

I want to switch to java because it’s what my colleagues and I have the most experience with. Also, I believe python is more error-prone because it doesn’t support unsigned and private variables. Among other things.

And lastly, I saw on LinkedIn this morning which compared the energy consumption of various languages, where java ranked as one the best and python as one of the worst. However, it may not be that relevant with my application though.

Long story short, if I can switch to java, I would.

not relevant at all because all the computation is done by compiled C++ code, not java or python code.

any time you think you need to loop over a bunch of pixels, stop, and think, and look for ways to do that with library functions.

also: numba is a jit compiler for python. if you really needed to write your own pixel-touching loops in python, that would still perform well, with numba.

Thank you @crackwitz
While the heavy calculations of my application may be within the OpenCV library, it’s not the only parts. So it may still be relevant to some degree.

Currently I’m building an application which recognises colors on the screen and clicks it.

I may be going a bit of the original topic here, but I have two essential challenges to overcome before I know whether I can make the switch:

  1. object tracking by using color-space has a great tutorial in python but not in java, OpenCV: Changing Colorspaces
    The methods mentioned: cv.inrange, cv.bitwise_and and cv.imshow. Are they used in the same way in java?
    When I try to look them up in java docs I get a 404:

  2. How can I capture frames from the computer screen and perform opencv operations on them?
    Currently I’m using this python example:
    opencv_tutorials/004_window_capture/windowcapture.py at master · learncodebygaming/opencv_tutorials · GitHub
    It uses the libraries: win32gui, win32ui and win32con.

So far for java I’ve found: Robot: createScreenCapture(Rectangle screenRect) (can’t paste more links)

But there’s a risk that I won’t get it to work, or work as well with java.

bug in the docs.

go via index.

https://docs.opencv.org/4.x/javadoc/org/opencv/core/Core.html#inRange(org.opencv.core.Mat,org.opencv.core.Scalar,org.opencv.core.Scalar,org.opencv.core.Mat)

opencv does not capture screens. that is beyond the scope of opencv.

Thank you very much.
I’m using java.awt to capture the screen. It seems like it may work well.