Plotting a Gradient Vector Field in OpenCV

后端 未结 2 1797
温柔的废话
温柔的废话 2021-02-09 23:19

I want to compute the gradient of a gray-scale image (smoothed_plane in the code) and plot it as a vector field in OpenCV, superposed to an existing image.

I tr

2条回答
  •  抹茶落季
    2021-02-10 00:20

    The following worked for me, after trying to use your code directly

    Scharr(smoothed_plane,grad_x,ddepth,1,0,scale);
    Scharr(smoothed_plane,grad_y,ddepth,0,1,scale);
    
    for (int i = 0 ; i < image_height ; i ++){
        for (int j = 0 ; j < image_width ; j ++){
            Scalar xval = grad_x.at(i,j); // Notice  not float
            Scalar yval = grad_y.at(i,j);
            gradient_field.at(i,j) = Point2f(xval.val[0],yval.val[0]);
        }
    }
    

    The < float > suggestion gave me high and unusable values.

提交回复
热议问题