Sapera Processing初步认识 ,使用伪代码

1.安装Sapera Processing环境。

2.项目导入所用的库文件

定制Mark点匹配区   轮廓

3.定义CProImage m_Image;

4.调用CProImage 的Load的方法,加载图片。

5.清理上次执行结果 m_Search->ClearResults()   CProSearch。

6.向搜索对象添加新模型m_pSearch->AddModel(dlg.m_ModelName, *m_pImage)     CProSearchEdge

7.设置相关信息

   m_pSearch->SetModelRoi(m_ModelIndex,
       CProRect(m_RoiLeft, m_RoiTop, m_RoiRight - m_RoiLeft + 1, m_RoiBottom - m_RoiTop + 1));

   m_pSearch->SetModelUseRotation(m_ModelIndex, false);  // Reset to avoid error message
   m_pSearch->SetModelUseScale(m_ModelIndex, false);     // Reset to avoid error message

   m_pSearch->SetModelUseRotation(m_ModelIndex, m_UseRotation ? true : false);
   m_pSearch->SetModelMinRotation(m_ModelIndex, m_MinRotation);
   m_pSearch->SetModelMaxRotation(m_ModelIndex, m_MaxRotation);
   m_pSearch->SetModelRotationIncr(m_ModelIndex, m_RotationIncr);
   m_pSearch->SetModelUseScale(m_ModelIndex, m_UseScale ? true : false);
   m_pSearch->SetModelMinScale(m_ModelIndex, m_MinScale);
   m_pSearch->SetModelMaxScale(m_ModelIndex, m_MaxScale);
   m_pSearch->SetModelScaleIncr(m_ModelIndex, m_ScaleIncr);
   m_pSearch->SetModelRotScaleWidth(m_ModelIndex, m_RotScaleWidth);
   m_pSearch->SetModelRotScaleHeight(m_ModelIndex, m_RotScaleHeight);

8.使所有对模型参数的修改都有效m_pSearch->ModelApply(m_ModelIndex);

匹配Mark点

3.定义CProImage m_Image,加载图片;

4.调用CProSearch::GetModeFromFile的方法加载Mark点文件.csa。

9.设置矩形区域CRect,设置成CProRect。(不是必要)

7.通过对典型目标图像的内部表示进行分析,优化搜索速度m_Search->Preprocess(*image)。(不是必要)

8.执行查询方法m_Search->Execute(*image)。

返回在上次执行中找到的匹配项的数量。此值表示所有模型的匹配总数。使用SetMaxMatches来限制要找到的匹配项的数量。m_Search->GetNumMatches()

m_Search->GetMatchModelName(i),
         m_Search->GetMatchLocationX(i),
         m_Search->GetMatchLocationY(i),
         m_Search->GetMatchScore(i),
         m_Search->GetMatchAngle(i),
         m_Search->GetMatchScale(i));

 

定制Mark点匹配区   面积(整体思路一样)

向搜索对象添加新模型m_pSearch->AddModel(dlg.m_ModelName, *m_pImage)     CProSearchEdge

设置参数

 m_pSearch->SetModelAutoResolution(m_ModelIndex, m_AutoResolution ? true : false);
    m_pSearch->SetModelCoarseResolution(m_ModelIndex, m_CoarseResolution);
    m_pSearch->SetModelFineResolution(m_ModelIndex, m_FineResolution);
   m_pSearch->SetModelEdgeStrengthMode(m_ModelIndex, (CProSearchEdge::EdgeStrengthMode) m_EdgeStrengthMode);
    m_pSearch->SetModelEdgeStrength(m_ModelIndex, m_EdgeStrength);
   m_pSearch->SetModelContourSelectionMode(m_ModelIndex, (CProSearchEdge::ContourSelectionMode) m_ContourSelectionMode);

    m_pSearch->SetModelRoi(m_ModelIndex,
      CProRect(m_RoiLeft, m_RoiTop, m_RoiRight - m_RoiLeft + 1, m_RoiBottom - m_RoiTop + 1));
    m_pSearch->SetModelOriginLocationX(m_ModelIndex, ((float)m_RoiLeft + (float)m_RoiRight + 1.0f) / 2.0f);
    m_pSearch->SetModelOriginLocationY(m_ModelIndex, ((float)m_RoiTop + (float)m_RoiBottom + 1.0f) / 2.0f);

 

更新模型

m_pSearch->ModelApply(m_ModelIndex);   CProSearchEdge

 

 

会出轮廓代码

void CModelEdgeDlg::DrawModel(CDC &dc)
{
    // Get contours
    const CProContours* contours = m_CoarseMode ?
      m_pSearch->GetModelCoarseContours(m_ModelIndex) :
      m_pSearch->GetModelFineContours(m_ModelIndex);

    float* pointXArray = (float*) contours->GetPointXArray();
    float* pointYArray = (float*) contours->GetPointYArray();

    // Offset viewport and set scale
    CPoint oldViewportOrg = dc.SetViewportOrg(m_DisplayRect.left + 1, m_DisplayRect.top + 1);

    // Draw contours and edition selection ...
    CPen normalPen( PS_SOLID, 0, RGB( 0xFF, 0x00, 0x00 ) );
    CPen pointPen( PS_SOLID, 0, RGB( 0x80, 0x00, 0x00 ) );
    CPen contourPen( PS_SOLID, 0, RGB( 0x00, 0xFF, 0xFF ) );

    dc.SelectObject(&normalPen);

    for (int i = 0; i < contours->GetNumContours(); i++)
    {
        // Set the current position to the coordinates of the first contour point
        int firstContourPointIndex = contours->GetContourFirstPointIndex(i);
        int lastContourPointIndex = contours->GetContourLastPointIndex(i);

        dc.MoveTo(
           (int)((pointXArray[firstContourPointIndex] - m_DispRoi.left) * m_ScaleX),
           (int)((pointYArray[firstContourPointIndex] - m_DispRoi.top) * m_ScaleY));

        if (i == m_Contour)
        {
            dc.SelectObject(&contourPen);
            for (int j = firstContourPointIndex; j <= lastContourPointIndex; j++)
            {
                if (m_ContourPointFirst <= m_ContourPointLast)
                {
                    if (j == m_ContourPointFirst)
                        dc.SelectObject(&pointPen);
                    else if (j == m_ContourPointLast + 1)
                        dc.SelectObject(&contourPen);
                }
                else
                {
                    if (j == firstContourPointIndex)
                        dc.SelectObject(&pointPen);
                    else if (j == m_ContourPointLast + 1)
                        dc.SelectObject(&contourPen);
                    else if (j == m_ContourPointFirst + 1)
                        dc.SelectObject(&pointPen);
                }

                dc.LineTo(
                    (int)((pointXArray[j] - m_DispRoi.left) * m_ScaleX),
                    (int)((pointYArray[j] - m_DispRoi.top) * m_ScaleY));
            }

            dc.SelectObject(&normalPen);
        }
        else
        {
            for (int j = firstContourPointIndex; j <= lastContourPointIndex; j++)
            {
                dc.LineTo(
                    (int)((pointXArray[j] - m_DispRoi.left) * m_ScaleX),
                    (int)((pointYArray[j] - m_DispRoi.top) * m_ScaleY));
            }
        }
    }

/*
    This next loop draws the selected contours. These contours, named
   model contours, correspond to the contours contained
    in the model coarse contour set.
*/
    // Draw model features
    CPen pen( PS_SOLID, 0, RGB( 0x00, 0xFF, 0x00 ) );
    CPen selectionPen( PS_SOLID, 0, RGB( 0xFF, 0xFF, 0x00 ) );

    dc.SelectObject(&pen);

    for (int i = 0; i < contours->GetModelNumContours(); i++)
    {
        // Select different pen for selection drawing
        if (i == m_ContourSelectedItem)
            dc.SelectObject(&selectionPen);

        // Set the current position to the coordinates of the 1st contour point
        int j = contours->GetModelContourFirstPointIndex(i);
        int last = contours->GetModelContourLastPointIndex(i);
        dc.MoveTo(
            (int)((pointXArray[j] - m_DispRoi.left) * m_ScaleX),
            (int)((pointYArray[j] - m_DispRoi.top) * m_ScaleY));

        // Scan the contour points of the model contour
        //while (j != -1)
        //{
        //    // Display the contour point
        //    dc.LineTo(
        //        (int)((pointXArray[j] - m_DispRoi.left) * m_ScaleX),
        //        (int)((pointYArray[j] - m_DispRoi.top) * m_ScaleY));

        //    j = contours->GetModelContourNextPointIndex(i);
        //}
        for (int k = j; k <= last; k++)
        {
            dc.LineTo(
                (int)((pointXArray[k] - m_DispRoi.left) * m_ScaleX),
                (int)((pointYArray[k] - m_DispRoi.top) * m_ScaleY));
        }

        // Select different pen for selection drawing
        if (i == m_ContourSelectedItem)
            dc.SelectObject(&pen);
    }
        
    // Bring viewport back to normal
    dc.SetViewportOrg(oldViewportOrg);

    // Draw model area
   Draw(&dc);
}

 

 

点击图片,找到模型。(思路)

得到轮廓上所有点,判断点击点是否在轮廓上(误差范围内)

通过模型上的点找模型  FindModelContourFromContourPoint

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值