简体   繁体   English

如何将OpenCV代码转换为JavaCV代码

[英]How to convert opencv code into javacv code

How to convert this C++ opencv code . 如何转换此C ++ opencv代码。 (this code is from camshift tracking demo in opencv https://github.com/Itseez/opencv/blob/master/samples/cpp/camshiftdemo.cpp ) (此代码来自opencv https://github.com/Itseez/opencv/blob/master/samples/cpp/camshiftdemo.cpp中的 camshift跟踪演示)

Mat roi(hue,selection), maskroi(mask,selection);

into javacv code? 成javacv代码?

The neweast javacpp presets javacpp-presets-0.9 already hava whole opencv javacv version implementation. neweast javacpp预设javacpp-presets-0.9已经具有整个opencv javacv版本的实现。 Check if the functions you need is available. 检查所需功能是否可用。 https://github.com/bytedeco/javacpp-presets/tree/master/opencv https://github.com/bytedeco/javacpp-presets/tree/master/opencv

If not, I think you need to see the definition(implemetaion) of the two c++ function roi() and maskroi() to convert very line code into javacv counterpart by yourself. 如果没有,我想您需要查看两个c ++函数roi()和maskroi()的定义(实现),以便将行代码自行转换为javacv对应项。

And, google group of javacpp is also a best place to ask if you hava javacpp related questions. 并且,javacpp的google组也是询问您是否有javacpp相关问题的最佳场所。 http://groups.google.com/group/javacpp-project http://groups.google.com/group/javacpp-project

Note: 注意:

for c++ output parameter type(call by pointer or call by reference), you need to understand java function parameter has no output type, so you need to use array instead as workaround, for example: 对于c ++输出参数类型(通过指针调用或通过引用调用),您需要了解java函数参数没有输出类型,因此您需要使用数组作为替代方法,例如:

C++ code: C ++代码:

void detectBothEars(Mat input, Rect* left, Rect* right);

The javacv counterpat should be: javacv对应应为:

void detectBothEarsRect(Mat input, Rect[] left, Rect[] right);

And the client code is: 客户端代码为:

Rect[] leftRect = new Rect[1];
Rect[] rightRect = new Rect[1];
detectBothEars(face, leftRect , rightRect);

The same constructor is available from Java: public Mat(Mat m, Rect roi) Java提供了相同的构造函数: public Mat(Mat m,Rect roi)

So, we can basically do the same thing: 因此,我们基本上可以做同样的事情:

Mat roi = new Mat(hue, selection), maskroi = new Mat(mask, selection);

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

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