基於OpenCV的任意方向投影


目前在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()) .

而在有些情況,我們可能需要對圖像進行其他方向的投影,這時候簡單的水平投影或者是垂直投影不能完全滿足我們的需求,例如下圖:

對這幅二值圖像來說,單純的水平或者垂直投影,並不能反映出圖像中白色前景區域的某些特征,我們可能需要用到沿垂直於白色區域延伸部分的投影。

這里提出一種簡單可行的解決思路:

  • 先找到最小外接矩形

     

  • 確定三角旋轉矩陣

     

  • 計算得旋轉參數矩陣

     

  • 旋轉需要的部分

     

  • 計算投影

基於三角映射的方法:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM