简体   繁体   English

OpenCV在Java与C ++中的实时性能

[英]Real-time performance of OpenCV in Java vs. C++

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. 我现在要做的是将测量的速度映射到人员进行时播放的MIDI文件。 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. 我用C ++使用OpenCV库编写了这个。

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. 直接修改MIDI文件的速度看起来像是一项艰巨的任务,鉴于我今年夏天剩下的时间有限,我决定去其他地方寻找。 I happened to find the Sequencer interface in the Java API, which has a lovely method called setTempoinBPM . 我碰巧在Java API中找到了Sequencer接口,它有一个名为setTempoinBPM的可爱方法。 It does exactly what I need it to; 它完全符合我的需要; I've just been having trouble getting it to work within my C++ code. 我一直无法让它在我的C ++代码中工作。

I've tried creating my own JVM for calling Java methods within C++ code, to no avail. 我已经尝试创建自己的JVM来在C ++代码中调用Java方法,但无济于事。 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. 我也尝试通过将适当的命令行参数传递给system()来调用Java程序,但是在使用这种方法开始回放后我无法改变MIDI文件的速度。

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. 我正在考虑将我的C ++代码转换为Java代码,以便直接调用setTempoinBPM() ,但我一直听到有关这是否会影响OpenCV性能的矛盾报道。

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? 我想你的意见:OpenCV在Java上的表现是否与其C ++性能相当,将我的项目转换为Java值得付出努力? (If you happen to know how to alter the tempo of a playing MIDI track easily, please feel free to share that as well.) (如果您碰巧知道如何轻松改变播放MIDI音轨的速度,请随时分享。)

Instead of mapping to a MIDI file, perhaps you could follow the parsing/compiling method. 也许您可以遵循解析/编译方法,而不是映射到MIDI文件。

Treat MIDI as a representation of the data (one that is serialized). 将MIDI视为数据的表示(序列化的数据)。 Parse the data into an intermediate representation (IR) that makes sense for your specific problem (ie. adjusting the tempo). 将数据解析为对您的特定问题有意义的中间表示(IR)(即调整速度)。 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. 然后,使用一个包这样 ,你可以解析MIDI文件并解压的重要组成部分。 That package may already have an IR that is appropriate for your problem. 该软件包可能已经有适合您问题的IR。 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. 或者,您可以找到一个能够直接将IR传递给的玩家。 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. 如果您选择已经用于已知播放器的IR(并且仍然适合您的速度操作),那么您在修改后不必考虑序列化IR。

Hope that helps... 希望有帮助......

I'm not very experienced with c++ but have used midi a bit through openFrameworks and ofxMidi . 我对c ++不是很熟悉,但是通过openFrameworksofxMidi使用了midi。

Behind the scenes it uses rtMidi . 在幕后它使用rtMidi

Doing a quick search it looks like it might be possible to control the tempo straight from c++ (see bottom of void RtMidiIn :: initialize method). 快速搜索看起来可能直接从c ++控制速度 (参见bottom of void RtMidiIn :: initialize方法的bottom of void RtMidiIn :: initialize )。 Not sure there's a nice clean API because I haven't used rtMidi that much, but might be worth checking. 不确定是否有一个很好的干净的API,因为我没有那么多使用rtMidi,但可能值得检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM