9

OpenCV Real-Time Performance in Java vs. C ++

 2 years ago
source link: https://www.codesd.com/item/opencv-real-time-performance-in-java-vs-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

OpenCV Real-Time Performance in Java vs. C ++

advertisements

I realize there are a number of similar questions on here, but I believe my situation is unique enough to warrant its own post.

I'm working on a "visual conductor" of sorts - I've built a program that tracks a person's hand gestures and extrapolates tempo (in beats per minute) from those gestures. What I'd like to do now is map the measured tempo to a MIDI file that plays while the person conducts. Basically, I'd like the program to allow someone to conduct a synthesized piece, where the tempo of the file being played is affected by the conductor's gestures in real time. I've written this in C++ using OpenCV libraries.

Here's where things get interesting/hairy. Directly modifying the tempo of a MIDI file looks like a daunting task, and given the limited time I have remaining this summer, I've decided to look elsewhere. I happened to find the Sequencer interface in the Java API, which has a lovely method called setTempoinBPM. It does exactly what I need it to; I've just been having trouble getting it to work within my C++ code.

I've tried creating my own JVM for calling Java methods within C++ code, to no avail. I've also tried calling Java programs by passing appropriate command line arguments to system(), but I can't alter the tempo of a MIDI file after I begin playback using this approach.

I'm considering converting my C++ code to Java code in order to call setTempoinBPM() directly, but I've been hearing contradictory reports on whether this would affect OpenCV's performance.

I'd like your opinion: is OpenCV's performance on Java comparable enough to its C++ performance that converting my project to Java would be worth the effort? (If you happen to know how to alter the tempo of a playing MIDI track easily, please feel free to share that as well.)


Instead of mapping to a MIDI file, perhaps you could follow the parsing/compiling method.

Treat MIDI as a representation of the data (one that is serialized). Parse the data into an intermediate representation (IR) that makes sense for your specific problem (ie. adjusting the tempo). Just think, "how could I best structure the in-memory data so that it's easy to manipulate the tempo?"

Then, using a package like this, you can parse the midi file and extract the important parts. That package may already have an IR that is appropriate for your problem. It certainly looks like it has a serialization method that might be required to input the file back into the player. Alternatively, you may find a player that you're able to pass your IR directly to. If you choose an IR that is already used for a known player (and is still suitable for your tempo manipulation), then you won't have to consider serializing your IR after you've modified it.

Hope that helps...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK