谁能帮我将openCV的标量类型转换为浮点或双精度等基本类型?
Scalar Sum1=sum(arg1),Sum2=sum(arg2);
theta.at<float>(i,j)=0.5*atan(Sum1/Sum2);
我必须对 Mat 对象arg1
和arg2
(邻域总和)的所有元素求和,然后我必须执行它们的除法以找到每个像素的方向场。我执行了 sum,但由于我必须应用 arctan 函数,所以标量类型不适合。谁能帮我将标量类型转换为基本类型?
实际上我正在尝试应用 log-gabor 过滤器,到目前为止我所做的代码是:
//function to enhance fingerprint by log-gabor filter
void filter(Mat src, Mat finalImage)
{
//Sobel derivatives for orientation estimation
Mat grad_x,grad_y,grad2_x,grad2_y,fImage;
src.convertTo(fImage, CV_32F);
//1st and second order gradient
Sobel(fImage,grad_x,CV_32F,1,0,3);
Sobel(fImage,grad_y,CV_32F,0,1,3);
Sobel(fImage,grad2_x,CV_32F,2,0,3);
Sobel(fImage,grad2_y,CV_32F,0,2,3);
//orientation estimation
Mat theta=Mat::zeros(fImage.size(),CV_32F);
Size block=Size(12,12);
copyMakeBorder(grad_x, grad_x, block.height/2, block.height/2,
block.width/2,block.width/2 , BORDER_CONSTANT, Scalar::all(0));
copyMakeBorder(grad2_x, grad2_x, block.height/2, block.height/2,
block.width/2,block.width/2 , BORDER_CONSTANT, Scalar::all(0));
copyMakeBorder(grad_y, grad_y, block.height/2, block.height/2,
block.width/2,block.width/2 , BORDER_CONSTANT, Scalar::all(0));
copyMakeBorder(grad2_y, grad2_y, block.height/2, block.height/2,
block.width/2,block.width/2 , BORDER_CONSTANT, Scalar::all(0));
Size imgSz=grad_x.size();
for(int i=block.width/2;i<imgSz.width-block.width/2;++i)
for(int j=block.height/2;j<imgSz.height-block.height/2;++j)
{
Mat roi_gradX=grad_x(Range(i-block.width/2,i+block.width/2),
Range(j-block.width/2,j+block.width/2));
Mat roi_gradY=grad_y(Range(i-block.width/2,i+block.width/2),
Range(j-block.width/2,j+block.width/2));
Mat roi_gradX2=grad2_x(Range(i-block.width/2,i+block.width/2),
Range(j-block.width/2,j+block.width/2));
Mat roi_gradY2=grad2_y(Range(i-block.width/2,i+block.width/2),
Range(j-block.width/2,j+block.width/2));
Mat arg1,arg2;
multiply(roi_gradX,roi_gradY,arg1);
arg1*=2;
subtract(roi_gradX2,roi_gradY2,arg2);
Scalar Sum1=sum(arg1),Sum2=sum(arg2);
theta.at<float>(i,j)=0.5*atan(Sum1/Sum2);
}
}