Vincentthe0ne Vincentthe0ne - 1 month ago 9x
C++ Question

Get Orientation Histogramm from Pixel Patch OpenCV

I try to get an Orientation Histogramm out of the Result of the phase() Method from CV. I try to get the rounded Orientation of each pixel and divide it by 10. So that it would look like that for example for a 5x5 Pixel Patch:

{ 1 36 20 3 14
5 16 11 6 9
7 12 34 22 0
34 5 9 21 4
5 21 28 30 1}

My Problem is, that I dont really know how to scan each pixel of the Patch and then get the OrientationValue of it to calculate the value for the histogram.

My code for getting the Orientation Mat looks like this:

Mat patch = src(Rect(px,py,15,15));

Mat Sx;
Sobel(patch, Sx, CV_32F, 1, 0, 3);

Mat Sy;
Sobel(patch, Sy, CV_32F, 0, 1, 3);

Mat mag, ori;
magnitude(Sx, Sy, mag);
phase(Sx, Sy, ori, true);

int** hist;

In the variable hist I want to add the values through another method.
I hope somebody understands what I'm thinking of and can help me.

I have a plan now, how to Iterate through the given Orientation Image I use the loop that is shown in the Documentation OpenCV Docu

for( i = 0; i < ori.rows; i++){
for( j = 0; j < ori.cols; j++){
cout <<<uchar>(i,j) << endl;

But accessing the Values like that wont give me the Orientation Value. Any Clues?


Ori is from type CV_32F not CV_8U, so try<float>(i,j) ro access the orientation values