title: opencv: convert Scalar to float or double type
body: <p>Can anyone help me in converting scalar type of openCV to basic types like float or double?</p>
  
  <pre><code>Scalar Sum1=sum(arg1),Sum2=sum(arg2);
  theta.at&lt;float&gt;(i,j)=0.5*atan(Sum1/Sum2);
  </code></pre>
  
  <p>I have to sum all elements of Mat objects <code>arg1</code> and <code>arg2</code> (neighbourhood sum), then I have to perform their division to find orientation field at each pixels. I performed sum, but since I have to apply arctan function, scalar type does not fit. Can anyone help me in converting scalar type to basic types?</p>
  
  <p>actually I'm trying to apply log-gabor filter and the code I've done so far is:</p>
  
  <pre><code>//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&lt;imgSz.width-block.width/2;++i)
      for(int j=block.height/2;j&lt;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&lt;float&gt;(i,j)=0.5*atan(Sum1/Sum2);
      }
  }
  </code></pre>