我有麻烦,下面的代码转换为javacv:如何OpenCV的转换javacv代码
((int*)(srcArg->imageData + srcArg->widthStep*P2.y))[P2.x]
什么的这个tranlation对我来说,它看起来就像一个数组,但value
类型为浮动?我不知道如何将值设置为value
。
float Saliency::getMean(IplImage * srcArg, CvPoint PixArg, int neighbourhood, int centerVal)
{
CvPoint P1, P2;
float value;
P1.x = PixArg.x - neighbourhood + 1;
P1.y = PixArg.y - neighbourhood + 1;
P2.x = PixArg.x + neighbourhood + 1;
P2.y = PixArg.y + neighbourhood + 1;
if(P1.x < 0)
P1.x = 0;
else if(P1.x > srcArg->width - 1)
P1.x = srcArg->width - 1;
if(P2.x < 0)
P2.x = 0;
else if(P2.x > srcArg->width - 1)
P2.x = srcArg->width - 1;
if(P1.y < 0)
P1.y = 0;
else if(P1.y > srcArg->height - 1)
P1.y = srcArg->height - 1;
if(P2.y < 0)
P2.y = 0;
else if(P2.y > srcArg->height - 1)
P2.y = srcArg->height - 1;
// we use the integral image to compute fast features
value = (float) (
((int*)(srcArg->imageData + srcArg->widthStep*P2.y))[P2.x] +
((int*)(srcArg->imageData + srcArg->widthStep*P1.y))[P1.x] -
((int*)(srcArg->imageData + srcArg->widthStep*P2.y))[P1.x] -
((int*)(srcArg->imageData + srcArg->widthStep*P1.y))[P2.x]
);
value = (value - centerVal)/ (((P2.x - P1.x) * (P2.y - P1.y))-1) ;
return value;
}
我的翻译:
private float getMean(IplImage srcArg, CvPoint PixArg, int neighbourhood, int centerVal)
{
CvPoint P1, P2;
float value;
P1.put(PixArg.x() - neighbourhood + 1, PixArg.y() - neighbourhood + 1);
P2.put(PixArg.x() + neighbourhood + 1, PixArg.y() + neighbourhood + 1);
if(P1.x() < 0)
P1.position(0).put(0);
else if(P1.x() > srcArg.width()- 1)
P1.position(0).put(srcArg.width()- 1);
if(P2.x() < 0)
P2.position(0).put(0);
else if(P2.x() > srcArg.width()- 1)
P2.position(0).put(srcArg.width()- 1);
if(P1.y() < 0)
P1.position(1).put(0);
else if(P1.y() > srcArg.height()- 1)
P1.position(1).put(srcArg.height()- 1);
if(P2.y() < 0)
P2.position(1).put(0);
else if(P2.y() > srcArg.height()- 1)
P2.position(1).put(srcArg.height()- 1);
// we use the integral image to compute fast features
value = (float) (
((int)(srcArg.imageData().get() + srcArg.widthStep()*P2.y()))[P2.x()] +
((int)(srcArg.imageData().get() + srcArg.widthStep()*P1.y()))[P1.x()] -
((int)(srcArg.imageData().get() + srcArg.widthStep()*P2.y()))[P1.x()] -
((int)(srcArg.imageData().get() + srcArg.widthStep()*P1.y()))[P2.x()]);
);
float[] bla= (srcArg.imageData().get()+srcArg.widthStep())[P2.x()];
value = (value - centerVal)/ (((P2.x - P1.x) * (P2.y - P1.y))-1) ;
return value;
}
这就意味着:开始与'srcArg-> imageData'指针,计算整数值'srcArg-> widthStep * P2.y'然后添加这个指针,使用的imageData结构为的宽度抵消。 ImageData看起来是一个char *指针,所以这是一个字节偏移量 - 从该数组中的srcArg-> widthStep * P2.y'中读取一个指针值,然后将其转换为整数数组,最后读取整数值“P2”。 x'来自该阵列。我不知道如何通过JavaCV处理这个问题,但是 - IplImage是一个真正的Java类吗?如果是这样,希望从imageData成员在那里显而易见。 – Rup 2012-07-09 14:11:32
谢谢,IplImage是一个JavaCV类。 JavaCV也有一个BytePointer类。非常丑陋...但我会尝试转换它...感谢您的描述 – 2012-07-09 16:07:34