目前在OpenCV中,有reduce函数可以进行水平或者垂直方向的投影。
C++: void reduce(InputArray mtx, OutputArray vec, int dim, int reduceOp, int dtype=-1)
Parameters:
- mtx – Source 2D matrix.
- vec – Destination vector. Its size and type is defined by dim and dtype parameters.
- dim – Dimension index along which the matrix is reduced. 0 means that the matrix is reduced to a single row. 1 means that the matrix is reduced to a single column.
- reduceOp –
Reduction operation that could be one of the following:
- CV_REDUCE_SUM The output is the sum of all rows/columns of the matrix.
- CV_REDUCE_AVG The output is the mean vector of all rows/columns of the matrix.
- CV_REDUCE_MAX The output is the maximum (column/row-wise) of all rows/columns of the matrix.
- CV_REDUCE_MIN The output is the minimum (column/row-wise) of all rows/columns of the matrix.
- dtype – When it is negative, the destination vector will have the same type as the source matrix. Otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels()) .
而在有些情况,我们可能需要对图像进行其他方向的投影,这时候简单的水平投影或者是垂直投影不能完全满足我们的需求,例如下图:
对这幅二值图像来说,单纯的水平或者垂直投影,并不能反映出图像中白色前景区域的某些特征,我们可能需要用到沿垂直于白色区域延伸部分的投影。
这里提出一种简单可行的解决思路:
-
先找到最小外接矩形
-
确定三角旋转矩阵
-
计算得旋转参数矩阵
-
旋转需要的部分
- 计算投影
基于三角映射的方法: