Ask Your Question
0

Run OpenCV to MFC

asked 2018-06-15 04:03:52 -0600

flaviu2 gravatar image

updated 2018-06-15 04:38:03 -0600

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 (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 ...

edit retag flag offensive close merge delete

Comments

2

How did you "clean up m_Mat"? What is the code you used? That code probably didn't work correctly. If it is too hard to "undo" a modification (drawing of rectangles), perhaps it is necessary to copy (to create a clone) of the matrix before drawing, using Mat.clone() method

rwong gravatar imagerwong ( 2018-06-15 05:35:26 -0600 )edit

Draw the blobs as a dialog,IOW,do not draw in MAT.after all ,you are using MFC

jsxyhelu gravatar imagejsxyhelu ( 2018-06-22 07:02:59 -0600 )edit

Can you detail a little bit ? These blobs should not be drawn on m_Mat ? But where then ?

P.S. And do you mean with IOW ?

flaviu2 gravatar imageflaviu2 ( 2018-06-28 04:30:46 -0600 )edit

i think ,IOW = in other words

jsxyhelu gravatar imagejsxyhelu ( 2018-07-01 07:32:53 -0600 )edit

2 answers

Sort by » oldest newest most voted
0

answered 2018-07-01 07:41:32 -0600

actually ,i have a code ,very like what yours. image description

from my blog https://www.cnblogs.com/jsxyhelu/p/6336429.html

the idea is: when we use MFC,in the on_draw() function,we can always draw sth at the image we will show to user.why not draw the rect in on_draw()? may it help you .

edit flag offensive delete link more
0

answered 2018-07-28 19:31:09 -0600

rwong gravatar image

(1) Check whether you are using GDI or GDI+. (2) In case you are using GDI, here is the documentation for the function you can use to paint a rectangle (but not filling the inside with color):

BOOL Rectangle( HDC hdc, int left, int top, int right, int bottom );

https://docs.microsoft.com/en-us/wind...

Example usage:

https://stackoverflow.com/questions/1...

To confirm that your application uses GDI, search your source code for a data type called HDC. This data type is a Handle to a Device Context.

Selecting the color and thickness for the rectangle border is slightly complicated in GDI programming. You need to create a GDI Pen object with the color and thickness, then temporarily swap (or "select", which is a terminology with special meaning in GDI) your Pen with the currently-in-use Pen in the HDC, then issue the Rectangle command to the HDC, and finally restore the original Pen object.

It is best to get a book "GDI programming with Windows 32 API". Without a book, it is hard to learn.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-15 04:03:52 -0600

Seen: 1,037 times

Last updated: Jul 28 '18