从openCV函数C ++ NDK访问返回的值 [英] Accessing a returned value from openCV function C++ NDK

查看:92
本文介绍了从openCV函数C ++ NDK访问返回的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在OpenCV中使用Knn findNearest函数,该函数具有以下参数:

I am using the Knn findNearest function in OpenCV, which takes in the following parameters:

Mat response;
Mat dist;

knn->findNearest(testFeature, K, noArray(), response, dist);

从response和dist返回的输出的类型为OutputArray.

The output returned from response and dist is of type OutputArray.

如何以这种格式访问response和dist的结果? 理想情况下,我想转换为Mat int.

How do I access the results of response and dist in this format? Ideally I would like to convert to Mat int.

推荐答案

如果要将Mat数据复制到cpp数组中,可以这样做. 我假设您要返回的Mat数据为浮点型.

If you want to copy the mat data into cpp array you can do like this. I assume the Mat data you want to return is of float type.

int size=response.rows*response.cols*resonse.channels();
float* outArr=new float[size];
std::memcpy(outArr,response.data,size*sizeof(float));

将outArr复制到JNIArray后,您需要删除它.

you need to delete outArr after copying it to JNIArray.

这篇关于从openCV函数C ++ NDK访问返回的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆