在图像处理中阅读更多种子点

时间:2014-05-26 17:25:51

标签: c++ image-processing

我是图像处理和C ++的新手,我必须为使用多个种子点增长的种子区域实施一个应用程序。 我必须通过鼠标双击来读取种子点。我需要阅读更多的种子点,我有一个问题。我尝试在FOR LOOP中读取它们但是它只读取了几个点(与FOR LOOP一样多)。

void CDibView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    BEGIN_SOURCE_PROCESSING;
    CPoint pos[10];

    for (int i=0; i<4; i++)
    {
        pos[i] = GetScrollPosition() + point;

        int x= pos[i].x;
        int y= dwHeight-pos[i].y-1;

        if(x > 0 && x < dwWidth && y > 0 && y < dwHeight)
        {
            CString info;
            info.Format("x=%d,y=%d,color=%d", x, y, lpSrc[y * w + x]);
            AfxMessageBox(info);
        }
    }

    END_SOURCE_PROCESSING;
    CScrollView::OnLButtonDblClk(nFlags, point);
}

这是我尝试过的。怎么了? 谢谢。

1 个答案:

答案 0 :(得分:0)

首先,向您的班级添加pos向量以保存您的积分:

class CDibView
{
    ...
    std::vector<CPoint> pos;
};

然后删除双击事件处理程序中的for循环,将您的双击位置保存到pos

void CDibView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    BEGIN_SOURCE_PROCESSING;

    CPoint p = GetScrollPosition() + point;
    pos.push_back(p); // the current point is added to the vector

    int x = p.x;
    int y = dwHeight - p.y - 1;

    if(x > 0 && x < dwWidth && y > 0 && y < dwHeight)
    {
        String info;
        info.Format("x=%d,y=%d,color=%d", x, y, lpSrc[y * w + x]);
        AfxMessageBox(info);
    }

    END_SOURCE_PROCESSING;
    CScrollView::OnLButtonDblClk(nFlags, point);
}

然后你班上的任何地方都可以参考pos[i]来访问你的点坐标(但首先检查矢量边界)。