简体   繁体   中英

How to convert opencv code into javacv code

How to convert this C++ opencv code . (this code is from camshift tracking demo in opencv https://github.com/Itseez/opencv/blob/master/samples/cpp/camshiftdemo.cpp )

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

into javacv code?

The neweast javacpp presets javacpp-presets-0.9 already hava whole opencv javacv version implementation. Check if the functions you need is available. 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.

And, google group of javacpp is also a best place to ask if you hava javacpp related questions. 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++ code:

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

The javacv counterpat should be:

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)

So, we can basically do the same thing:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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