Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw on webcam using OpenCV

I want to draw/paint on a webcam screen using OpenCV. Since I'm reading from a cam, the frames are constantly changing, so I'm trying to figure out a way to keep or save the drawing on the current frame and use it for the next frame. The code below allows you to draw on the screen but when it gets the next frame, the drawing is gone and it starts over.

Could someone please help me ... Thanks.

          CvCapture *input;
          input = cvCaptureFromCAM( 0 );

          cvSetMouseCallback("Demo",&on_mouse, 0);

                 for(;;)
                    {
                        frame = cvQueryFrame(input);

                        if(!image)
                        {
                            image = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3);
                            screenBuffer = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3);
                        }

                        cvCopy(frame, image, 0);

                        if(drawing) //drawing is a global variable
                        { 
                           cvCircle(image, cvPoint(last_x,last_y), 10,CV_RGB(red,green,blue), -1, CV_AA, 0);
                           cvCopy(image, screenBuffer, 0);
                        }

                        cvShowImage( "Demo", screenBuffer );
                }


        void on_mouse( int event, int x, int y, int flags, void* param )
        {
            last_x = x;
            last_y = y;

            if(event==CV_EVENT_LBUTTONDOWN)
                {
                    drawing = 1;
                }
        }
like image 710
Aziz Avatar asked Mar 30 '11 18:03

Aziz


People also ask

Can we use mobile camera in OpenCV?

Download and install IP Webcam application on your mobile phone. Then make sure your PC and Phone both are connected to the same network. Open your IP Webcam application on your both, click “Start Server” (usually found at the bottom). This will open a camera on your Phone.

What is virtual pen?

virtual pen is a computer vision program to track object movement and draw line according the movement.


1 Answers

Draw into a separate image and then cvAdd() that to the video image immediately before dispalying it

like image 67
Martin Beckett Avatar answered Oct 26 '22 10:10

Martin Beckett