OpenMVS Texture code reading

2 minute read

  • TextureMesh
    • FaceViewSelection
      • ListVertexFaces✔️ // extract array of triangles incident to each vertex
        • EmptyExtra✔️
        • ListIncidenteFaces✔️
        • ListBoundaryVertices✔️, // 边界点检查,在面中,只使用了1次的点是边界点,另外,代码中假设每个点通常不会超过12个面使用
          • 20210926235332
      • // create texture patches✔️
        • ListCameraFaces // list all views for each face
          • //create vertices octree of vertices✔️
          • //extract array of faces viewed by each image✔️
            • //compute gradient magnitude✔️
            • //select faces inside view frustum✔️
              • plane with AABB✔️
            • // project all triangles in this view and keep the closest ones
              • // skip face if not completely inside✔️
                • using TransformPointW2C and TransformPointC2I to check the point is in image plane, OpenMVS use 3 pixel as border width ✔️
              • // skip face if the (cos) angle between the view to face vector and the view direction is negative✔️
                • (faceCenter.z <= REAL(0))
                • faceCenter.dot(normalPlane) >= ZEROTOLERANCE<REAL>()
              • // draw triangle and for each pixel compute depth as the ray intersection with the plane✔️
                • Advanced Rasterization by Nick (Nicolas Capens) 2004
                • Advanced Rasterization🤔
                • libs/Common/Types.inl:2474/TImage<TYPE>::RasterizeTriangle
                • OpenMVS: Using block size eq 8, and Half-Space
            • // compute the projection area of visible faces
              • 遍历照片上的像素,获取最近的face最近的view, 计算face颜色均值✔️
            • (fOutlierThreshold > 0) // try to detect outlier views for each face
              • 取face 3个通道的均色,对均色做多元正太分布计算,如果偏差大于阈值,则视为outlier✔️
                • LU分解取逆
        • // create faces graph✔️
          • 遍历face以及面的邻接faceAdj, 若一个可见,一个不可见,则增加seam
        • // assign the best view to each face✔️
          • // find connected components✔️
            • 根据前面计算的face邻接关系计算连通图
          • // map face ID from global to component space✔️
            • 为每个面计算连通图的新id,component1: [1,2,3,...,c1], component2: [1,2,3,...,c2]
          • // normalize quality values✔️
            • 计算图片质量[二阶导积分]的95分位置近似值
          • // initialize inference structures✔️
            • numNodes=连通图face的数量,如果数量小于等于1,则忽略
            • SmoothCost=0[if node eq]~1000
            • Neighbors
          • // set data costs✔️
            • // set costs for label 0 (undefined)✔️
              • dataCost = fRatioDataSmoothness * 1000 for min of all labels
            • // set data costs for all labels (except label 0 - undefined)✔️
              • dataCost = $\big(1-\max(1, \frac{quality}{quality_{p95}})\big)*1000$
            • Label = 0, 未定义,label >= 1是指其他图片✔️
          • // assign the optimal view (label) to each face✔️
            • Optimize 优化单位是连通图✔️
              • ComputeEnergy✔️
                • $\sum{cost_{data}} + \sum(cost_{edge})$
                • $cost_{edge} = 1000$ if label is not equal
              • Optimize(n=1)✔️
                • for(n times)
                  • 计算每个面在选择不同label时得到的minEnergy
                  • Swap newMsgs and oldMsgs, oldMsgs - min(oldMsgs)
                • 更新选择的labeldataCost✔️
              • 根据能量差分提前返回✔️
          • // extract resulting labeling✔️
            • label-1,调整索引
        • // create texture patches✔️
          • // divide graph in sub-graphs of connected faces having the same label✔️
            • 计算图片不一致的边缝A,对于相邻一侧无label的也作为边缝B
            • 去掉A的连通边
          • // find connected components: texture patches✔️
            • 计算新的连通图
          • // last texture patch contains all faces with no texture✔️
            • 每个Texture 收集每个连通体的face
          • // remove all patches with invalid label (except the last one) and create the map from the old index to the new one✔️
    • GenerateTexture
      • // project patches in the corresponding view and compute texture-coordinates and bounding-box
      • // project vertices and compute bounding-box✔️
        • 对每个patch的面映射到图片中后,算一个2d的aabb
      • // compute relative texture coordinates✔️
        • 计算offset,修改相应的坐标
      • // init last patch to point to a small uniform color patch✔️
        • 默认纹理位置
      • // perform seam leveling
        • // create seam vertices and edges✔️
        • // perform global seam leveling🤔
          • 利用ConjugateGradient求解Tikhonov's Gamma matrix使得全局颜色差分较小的新解
          • // find the patch ID for each vertex✔️
            • 对点赋值patch_id,边缝点使用idxSeamVertex
          • // assign a row index within the solution vector x to each vertex/patch✔️
            • 生成一个patch数组vertpatch2rows, 行号为点索引,二阶索引为patch,对于单个patch的点,只赋值一个patch,对于边缝点多个patch的点,赋多个patch,值为递增值rowsX
          • // fill Tikhonov’s Gamma matrix (regularization constraints)✔️
        • // perform local seam leveling✔️
          • 优化patch间的线条颜色
      • // merge texture patches with overlapping rectangles
        • // translate texture coordinates
        • // join faces lists
        • // remove the small patch
      • // create texture
        • // arrange texture patches to fit the smallest possible texture image
        • // increase texture size till all patches fit
      • // create texture image
        • // copy patch image
          • // flip patch and texture-coordinates
        • // compute final texture coordinates
          • // translate, normalize and flip Y axis

Categories:

Updated: