Hi,
I am trying to calculate the gradient direction of an image.
I tried the following function:
Mat computeArcTan(Mat &dst1, Mat &dst2)
{
Mat angle;//(dst1.rows,dst1.cols,CV_32F);
ofstream myFile("angle.csv");
const double pi = 3.14159;
for(int row = 0; row < dst1.rows; row++)
{
for(int col = 0; col < dst1.cols; col++ )
{
//angle.at<uchar>(row,col)=(double)atan2(dst1.at<uchar>(row,col),dst2.at<uchar>(row,col)*180/pi);
angle.push_back((double)atan2(dst1.at<uchar>(row,col),dst2.at<uchar>(row,col))*180/pi);
myFile << angle.at<double>(row,col) <<",";
}
myFile << endl;
}
return angle;
}
the dst1 and dst2 are the gradient of x and y direction. However, I believe I am not getting the correct direction values. The values printed in the csv file is a repetition of values of 0, 18.435, 45 and 71.3872. When i checked with matlab, it is totally wrong. I know openCV has the function cartToPolar() but I'm trying to hard code it just to understand the process behind it.
Any Ideas or direction/suggestion on what am i doing wrong ?
thanks,