Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Run OpenCV to MFC

I have reproduced this sample, in a MFC app.

The cv::Mat is a CDOcument variable member:

// Attributes
public:
std::vector<CBlob> m_blobs;
cv::Mat m_Mat;

and I draw rectangles over image, with an method:

DrawBlobInfoOnImage(m_blobs, m_Mat);

Here is the code of this method:

void CVisionDoc::DrawBlobInfoOnImage(std::vector<CBlob>& blobs, cv::Mat& Mat)
{
for (unsigned int i = 0;i < blobs.size();++i)
{
    if (blobs[i].m_bStillBeingTracked)
    {
        cv::rectangle(Mat, blobs[i].m_rectCurrentBounding, SCALAR_RED, 2);
        double dFontScale = blobs[i].m_dCurrentDiagonalSize / 60.0;
        int nFontThickness = (int)roundf(dFontScale * 1.0);
        cv::putText(Mat, (LPCTSTR)IntToString(i), blobs[i].m_vecPointCenterPositions.back(), CV_FONT_HERSHEY_SIMPLEX, dFontScale, SCALAR_GREEN, nFontThickness);
    }
}
}

but the result of this method is something like that:

image description

My question is: how can I draw only the last blobs result over my image ?

I have tried to clean up m_Mat, and to enable to draw only blobs.size() - 1 blob over image, none of this worked ...

Run OpenCV to MFC

I have reproduced this sample, in a MFC app.

The cv::Mat is a CDOcument variable member:

// Attributes
public:
std::vector<CBlob> m_blobs;
cv::Mat m_Mat;

and I draw rectangles over image, with an method:

DrawBlobInfoOnImage(m_blobs, m_Mat);

Here is the code of this method:

void CVisionDoc::DrawBlobInfoOnImage(std::vector<CBlob>& CMyDoc::DrawBlobInfoOnImage(std::vector<CBlob>& blobs, cv::Mat& Mat)
{
for (unsigned int i = 0;i < blobs.size();++i)
{
    if (blobs[i].m_bStillBeingTracked)
    {
        cv::rectangle(Mat, blobs[i].m_rectCurrentBounding, SCALAR_RED, 2);
        double dFontScale = blobs[i].m_dCurrentDiagonalSize / 60.0;
        int nFontThickness = (int)roundf(dFontScale * 1.0);
        cv::putText(Mat, (LPCTSTR)IntToString(i), blobs[i].m_vecPointCenterPositions.back(), CV_FONT_HERSHEY_SIMPLEX, dFontScale, SCALAR_GREEN, nFontThickness);
    }
}
}

but the result of this method is something like that:

image description

My question is: how can I draw only the last blobs result over my image ?

I have tried to clean up m_Mat, and to enable to draw only blobs.size() - 1 blob over image, none of this worked ...

Run OpenCV to MFC

I have reproduced this sample, in a MFC app.

The cv::Mat is a CDOcument variable member:

// Attributes
public:
std::vector<CBlob> m_blobs;
cv::Mat m_Mat;

and I draw rectangles over image, with an method:method (called at some time intervals, according FPS rate):

DrawBlobInfoOnImage(m_blobs, m_Mat);

Here is the code of this method:

void CMyDoc::DrawBlobInfoOnImage(std::vector<CBlob>& blobs, cv::Mat& Mat)
{
for (unsigned int i = 0;i < blobs.size();++i)
{
    if (blobs[i].m_bStillBeingTracked)
    {
        cv::rectangle(Mat, blobs[i].m_rectCurrentBounding, SCALAR_RED, 2);
        double dFontScale = blobs[i].m_dCurrentDiagonalSize / 60.0;
        int nFontThickness = (int)roundf(dFontScale * 1.0);
        cv::putText(Mat, (LPCTSTR)IntToString(i), blobs[i].m_vecPointCenterPositions.back(), CV_FONT_HERSHEY_SIMPLEX, dFontScale, SCALAR_GREEN, nFontThickness);
    }
}
}

but the result of this method is something like that:

image description

My question is: how can I draw only the last blobs result over my image ?

I have tried to clean up m_Mat, and to enable to draw only blobs.size() - 1 blob over image, none of this worked ...