opecv c++计算图像的曲率

avatar
作者
猴君
阅读量:0

公式

κ = z x x ⋅ z y 2 − 2 ⋅ z x ⋅ z y ⋅ z x y + z y y ⋅ z x 2 ( z x 2 + z y 2 + 1 ) 3 / 2 \kappa = \frac{z_{xx} \cdot z_y^2 - 2 \cdot z_x \cdot z_y \cdot z_{xy} + z_{yy} \cdot z_x^2}{(z_x^2 + z_y^2 + 1)^{3/2}}\newline κ=(zx2+zy2+1)3/2zxxzy22zxzyzxy+zyyzx2

其中:
z x = ∂ z ∂ x z_x = \frac{\partial z}{\partial x}\newline zx=xz
z y = ∂ z ∂ y z_y = \frac{\partial z}{\partial y}\newline zy=yz
z x x , z y y , z x y z_{xx}, z_{yy}, z_{xy} zxx,zyy,zxy 分别为 ( z ) 关于 ( x ) 和 ( y ) 的二阶导数和交叉导数。

代码

void computeCurvature(const cv::Mat& depth_map, cv::Mat& curvature_map) { 	cv::Mat gradient_x, gradient_y; 	cv::Mat gradient_xx, gradient_yy, gradient_xy;  	// 计算一阶导数 	Sobel(depth_map, gradient_x, CV_64F, 1, 0, 3); 	Sobel(depth_map, gradient_y, CV_64F, 0, 1, 3);  	// 计算二阶导数 	Sobel(gradient_x, gradient_xx, CV_64F, 1, 0, 3); 	Sobel(gradient_y, gradient_yy, CV_64F, 0, 1, 3); 	Sobel(gradient_x, gradient_xy, CV_64F, 0, 1, 3);  	// 计算曲率 	cv::Mat denominator = gradient_x.mul(gradient_x) + gradient_y.mul(gradient_y) +  		cv::Mat::ones(depth_map.size(), CV_64F); 	cv::pow(denominator, 1.5, denominator);  	curvature_map = (gradient_xx.mul(gradient_y.mul(gradient_y)) - 2.0 * gradient_x.mul(gradient_y.mul(gradient_xy)) + gradient_yy.mul(gradient_x.mul(gradient_x))) / denominator; } 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!