ImageBox painting mouse move

Request features to be added

ImageBox painting mouse move

Postby badrepent » Mon Nov 24, 2008 12:31 pm

Hi Canming, with your previous post help i'm finishing to implent watershed sample using Emgu CV... everything works fine but i dunno why ImageBox doesn't respond to line drawing in my MouseMove event... the lines drawed are displayed only after i release my left button... i show you my code so you can tell me if its my fault or if its ImageBox standard behaviour
Code: Select all
//startMasking is a bool variable

private void imageBoxOriginal_MouseMove(object sender, MouseEventArgs e)
        {
            if (startMarking)
            {
                Point2D<int> point = new Point2D<int>(e.X, e.Y);
                if (previousPoint.X < 0)
                    previousPoint = point;
                CvInvoke.cvLine(_markerMask, previousPoint, point, markerColor, 5, LINE_TYPE.EIGHT_CONNECTED, 0);
                CvInvoke.cvLine(_img, previousPoint, point, markerColor, 5, LINE_TYPE.EIGHT_CONNECTED, 0);
                previousPoint = point;
                imageBoxOriginal.Image = _img;
            }
        }

        private void imageBoxOriginal_MouseDown(object sender, MouseEventArgs e)
        {
            previousPoint = new Point2D<int>(e.X, e.Y);
            startMarking = true;
        }

        private void imageBoxOriginal_MouseUp(object sender, MouseEventArgs e)
        {
            previousPoint = new Point2D<int>(-1, -1);
            startMarking = false;
        }



Thanks again
Luca
badrepent
 
Posts: 96
Joined: Mon Nov 17, 2008 12:14 pm

Re: ImageBox painting mouse move

Postby canming » Tue Nov 25, 2008 9:30 am

There seems to be something wrong in this block of code.

Code: Select all
private void imageBoxOriginal_MouseMove(object sender, MouseEventArgs e)
        {
            if (startMarking)
            {
                Point2D<int> point = new Point2D<int>(e.X, e.Y);
                ...
                CvInvoke.cvLine(_img, previousPoint, point, markerColor, 5, LINE_TYPE.EIGHT_CONNECTED, 0);
                previousPoint = point;
                ..
            }
        }


Almost every time the mouse move a pixel this block of code will be called. At the end of the code you set previous point to the current point, which means the line you draw is just from the previous pixel to the current pixel.

Hope it helps.
canming
Site Admin
 
Posts: 875
Joined: Thu Feb 28, 2008 4:16 pm

Re: ImageBox painting mouse move

Postby badrepent » Tue Nov 25, 2008 3:31 pm

canming wrote:There seems to be something wrong in this block of code.

Code: Select all
private void imageBoxOriginal_MouseMove(object sender, MouseEventArgs e)
        {
            if (startMarking)
            {
                Point2D<int> point = new Point2D<int>(e.X, e.Y);
                ...
                CvInvoke.cvLine(_img, previousPoint, point, markerColor, 5, LINE_TYPE.EIGHT_CONNECTED, 0);
                previousPoint = point;
                ..
            }
        }


Almost every time the mouse move a pixel this block of code will be called. At the end of the code you set previous point to the current point, which means the line you draw is just from the previous pixel to the current pixel.

Hope it helps.


This approach is the one used in the watershed sample that comes with openCV... i have adopted it and used with EmguCV, i don't think there's something wrong in the code :) i leave here for reference the c++ code i have translated from
Code: Select all
void on_mouse( int event, int x, int y, int flags, void* param )
{
    if( !img )
        return;

    if( event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON) )
        prev_pt = cvPoint(-1,-1);
    else if( event == CV_EVENT_LBUTTONDOWN )
        prev_pt = cvPoint(x,y);
    else if( event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON) )
    {
        CvPoint pt = cvPoint(x,y);
        if( prev_pt.x < 0 )
            prev_pt = pt;
        cvLine( marker_mask, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
        cvLine( img, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
        prev_pt = pt;
        cvShowImage( "image", img );
    }
}

Hope this helps ;)
badrepent
 
Posts: 96
Joined: Mon Nov 17, 2008 12:14 pm

Re: ImageBox painting mouse move

Postby canming » Tue Nov 25, 2008 10:52 pm

Code: Select all
    private void imageBoxOriginal_MouseMove(object sender, MouseEventArgs e)
            {
                if (startMarking)
                {
                    Point2D<int> point = new Point2D<int>(e.X, e.Y);
                    ...
                    CvInvoke.cvLine(_img, previousPoint, point, markerColor, 5, LINE_TYPE.EIGHT_CONNECTED, 0);
                    previousPoint = point;
                    ..
                }
            }

Can you try to set a break point on exactly the line
Code: Select all
 previousPoint = point;
and see how often the break point is hit?
canming
Site Admin
 
Posts: 875
Joined: Thu Feb 28, 2008 4:16 pm

Re: ImageBox painting mouse move

Postby badrepent » Wed Nov 26, 2008 11:20 am

Thanks for the investigation, i have discovered that the problem was due to previous dll references, i have updated the code and reference using latest EmguCV code and now everything works fine!!!!
I finally managed to create an emguCV watershed example ;)
Just an idea, why don't you put a section about here on the forum where we can post various code that extend the well done standard Emgu CV example?
tnx a lot
Luca
badrepent
 
Posts: 96
Joined: Mon Nov 17, 2008 12:14 pm


Return to Feature Request

Who is online

Users browsing this forum: No registered users and 1 guest