将指向C ++的数组转换为Java(OpenCV)

时间:2022-09-01 11:27:15

I'm in the process of converting a function in OpenCV which is in C++ to Java. Link.

我正在将使用C ++的OpenCV中的函数转换为Java。链接。

I don't know too much about C++ and struggling to convert this part:

我不太了解C ++并努力转换这部分:

/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 } ; //the upper boundary is exclusive
const float* histRange = { range };

This is what I have so far:

这是我到目前为止:

//Set of ranges
float ranges[] = {0,256};
final float histRange = {ranges};

Edit:

Thanks for your help, I have managed to get it working. This question was in the context of OpenCV (Sorry if I didn't make it clear). Code:

感谢您的帮助,我设法让它工作。这个问题是在OpenCV的背景下(很抱歉,如果我没有说清楚)。码:

//Set of ranges
float ranges[] = {0,256};
MatOfFloat histRange = new MatOfFloat(ranges);

2 个解决方案

#1


4  

Unless I am mistaken with my pointers today, the second line in the c++ code duplicates pointer of range, so they both point at the same pair of values. What you want in Java should be this:

除非我今天误解了我的指针,否则c ++代码中的第二行会复制范围的指针,因此它们都指向同一对值。你想要的Java应该是这样的:

float ranges[] = {0,256};
final float histRange[] = ranges;

#2


0  

Thanks for your help, I have managed to get it working. This question was in the context of OpenCV (Sorry if I didn't make it clear). Code:

感谢您的帮助,我设法让它工作。这个问题是在OpenCV的背景下(很抱歉,如果我没有说清楚)。码:

//Set of ranges
float ranges[] = {0,256};
MatOfFloat histRange = new MatOfFloat(ranges);

#1


4  

Unless I am mistaken with my pointers today, the second line in the c++ code duplicates pointer of range, so they both point at the same pair of values. What you want in Java should be this:

除非我今天误解了我的指针,否则c ++代码中的第二行会复制范围的指针,因此它们都指向同一对值。你想要的Java应该是这样的:

float ranges[] = {0,256};
final float histRange[] = ranges;

#2


0  

Thanks for your help, I have managed to get it working. This question was in the context of OpenCV (Sorry if I didn't make it clear). Code:

感谢您的帮助,我设法让它工作。这个问题是在OpenCV的背景下(很抱歉,如果我没有说清楚)。码:

//Set of ranges
float ranges[] = {0,256};
MatOfFloat histRange = new MatOfFloat(ranges);