[英]How to convert c++ operator to Java
I'm trying to use the OpenCV
library ( Java
version). 我正在尝试使用
OpenCV
库( Java
版本)。 I found some code written in C++
and I'm trying to rewrite it to Java
. 我找到了一些用
C++
编写的代码,并试图将其重写为Java
。 However, I can't understand one construction. 但是,我无法理解一种构造。
Here is the C++
code: 这是
C++
代码:
void scaleDownImage(cv::Mat &originalImg,cv::Mat &scaledDownImage )
{
for(int x=0;x<16;x++)
{
for(int y=0;y<16 ;y++)
{
int yd =ceil((float)(y*originalImg.cols/16));
int xd = ceil((float)(x*originalImg.rows/16));
scaledDownImage.at<uchar>(x,y) = originalImg.at<uchar>(xd,yd);
}
}
}
I can't understand how to translate this line: 我不明白如何翻译这一行:
scaledDownImage.at<uchar>(x,y) = originalImg.at<uchar>(xd,yd);
have a look at the Mat accessor functions here: http://docs.opencv.org/java/org/opencv/core/Mat.html#get(int,%20int) 在这里查看Mat访问器函数: http : //docs.opencv.org/java/org/opencv/core/Mat.html#get(int,%20int)
so, to translate your example: 因此,请翻译您的示例:
scaledDownImage.at<uchar>(r,c) = originalImg.at<uchar>(rd,cd); // c++
would be : 将会 :
byte [] pixel = new byte[1]; // byte[3] for rgb
originalImg.get( rd, cd, pixel );
scaledDownImage.put( r,c, pixel );
note, that it's (row,col), not (x,y) ! 请注意,它是(row,col),而不是(x,y)!
uchar
= unsigned char. uchar
=无符号字符。
This statement: 这个说法:
scaledDownImage.at<uchar>(x,y)
returns unsigned char(I guess, pointer) at positions(x,y). 返回在位置(x,y)的无符号字符(我猜想,指针)。
So, in java it will be like: 因此,在Java中它将类似于:
unsigned char scaledDownImageChar = scaledDownImage.charAt(x, y);
scaledDownImageChar = originalImg.charAt(x, y);
This is not real code, just an example. 这不是真实的代码,仅是示例。
It is called template, search generics for java. 它称为模板,搜索Java的泛型。
Basically, the "at" method´s code uses some type T 基本上,“ at”方法的代码使用某种类型T
(don´t know if it is called T or something else) (不知道它是否称为T或其他名称)
which could be int, float, char, any class... 可以是int,float,char,任何类...
just something which is unspecified at the moment 只是目前还没有指定的东西
And in this case, you´re calling the method with T being an uchar 在这种情况下,您以T为uchar调用方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.