Page 2 of 2

Re: Object Detction using one webcam

PostPosted: Thu Sep 17, 2009 8:56 pm
by samosamo
Thanks Andrew Kirillov!

I have still one question. How I can to find relationship between real size of object and object on web cam?

Thanks

Re: Object Detction using one webcam

PostPosted: Fri Sep 18, 2009 8:15 am
by andrew.kirillov
Hello,

If all objects appear on the same distance from camera (which is hard to guarantee in real environment), then you may try to estimate object size. You need to present to camera some objects of the know size - meter, 10 cm, 50 cm, 2 m - learning phase. On this phase your application should try to find relation between real object’s size and size in pixels. After this relation is found, you may try estimating size of other objects. BUT! This may work if all objects appear on the same distance from camera.

If object may have arbitrary distance from camera, then you will not solve this task with one camera. You will need to get a stereo system - 2 cameras.

Re: Object Detction using one webcam

PostPosted: Fri Sep 18, 2009 12:44 pm
by samosamo
Hello

Where I can get some information about stero system? With 2 cameras I can get olny 3D picture.

thanks for help

Re: Object Detction using one webcam

PostPosted: Fri Sep 18, 2009 12:55 pm
by andrew.kirillov
samosamo wrote:Where I can get some information about stero system?

As usually - Google. Stereopsis on Wikipedia is a good start. Here is one project on Code Google. Just make a search ...

Re: Object Detction using one webcam

PostPosted: Sun Jun 16, 2013 2:05 pm
by Dinesh8818
Hi,
I am doing a project on making a pan tilt camera using Arduino duemilanove + motor shield and servo motors.Hardware part is working properly with manual trackbar movements.I have implemented the object detection algorithm using the article on http://www.aforgenet.com/aforge/articles/lego_pan_tilt_camera/ and it also working correctly.When I using my lap top web cam, pan tilt mechanism work properly.But when i switch to the pan tilt camera it do not work.If you can give any support on passing the correct center value of the detected blob to ardunio,it will be a great help for me.
waiting for your reply,please help.

Thanks,
Dinesh

Re: Object Detction using one webcam

PostPosted: Tue Jun 18, 2013 4:33 am
by Dinesh8818
Hi,
I change my code to as following
Code: Select all
////////////////////////////////////    
   int servoTiltPosition = 90;
        int servoPanPosition = 90;
        int tiltChannel = 0;
        int panChannel = 1;
        int midRectY = 0;
        int midRectX = 0;
        int midScreenY;
        int midScreenX;
        int midScreenWindow = 10;
        int stepSize = 1;
///////////////////////////
if (rects.Length > 0)
            {
                Rectangle objectRect = rects[0];
                Graphics g = Graphics.FromImage(image);

                midScreenX = image.Width / 2;
                midScreenY = image.Height / 2;

                using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 3))
                {
                    g.DrawRectangle(pen, objectRect);
                }

                midRectY = objectRect.Y + (objectRect.Height / 2);
                midRectX = objectRect.X + (objectRect.Width / 2);

                g.Dispose();         
            }
////////////////////////////////////////////
      if (midRectY < (midScreenY - midScreenWindow))
                    {
                        if (servoTiltPosition >= 5)
         servoTiltPosition -= stepSize;
                    }
                    else if (midRectY > (midScreenY + midScreenWindow))
                    {
                        if (servoTiltPosition <= 175)
         servoTiltPosition += stepSize;
                    }
                    if (midRectX < (midScreenX - midScreenWindow))
                    {
                        if (servoPanPosition >= 5)
         servoPanPosition -= stepSize;
                    }
                    else if (midRectX > midScreenX + midScreenWindow)
                    {
                        if (servoPanPosition <= 175)
         servoPanPosition += stepSize;
                    }
                    serialPort1.Write(tiltChannel + servoTiltPosition.ToString() + "@");//this is the format i sent values to the ardunio via serial port.
                    serialPort1.Write(panChannel + servoPanPosition.ToString() + "@");


but when the system detects an blob pan tilt camera moves away from the blob,,I cant understand why is happening like that..I hope any one can help me

Thanks,
Dinesh

Re: Object Detction using one webcam

PostPosted: Tue Jun 18, 2013 4:44 am
by andrew.kirillov
Hello,

I would suggest to try debuggin. Check what is the center coordinate of your blob, what is the coordinate relative to image's center (which tells direction to move), check what is the instruction given to servos/motors. Keep in mind that positive direction of your servos/motors may be different from positive direction of image's coordinate system, so some negation may be required. In general - try to debug and understand what the code does.

Re: Object Detction using one webcam

PostPosted: Tue Jun 18, 2013 5:06 am
by Dinesh8818
Hi Andrew,,

Thank you very much for replying me.The picture box where I open the web cam has the size of (540,360).And previously I had a code like following
Code: Select all
int detectedX, detectedY;
//////////////////////////////////   
   if (rects.Length > 0)
            {
                Rectangle objectRect = rects[0];
                Graphics g = Graphics.FromImage(image);

      detectedX = getCenter(rects[0]).X;
      detectedY = getCenter(rects[0]).Y;

                using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 3))
                {
                    g.DrawRectangle(pen, objectRect);
                }
                g.Dispose();   
            }
//////////////////////////////////////
   private Point getCenter(Rectangle refRectangel)
        {
            int centerX, centerY;

            centerX = Convert.ToInt32(refRectangel.Width / 2) + refRectangel.X;
            centerY = Convert.ToInt32(refRectangel.Height / 2) + refRectangel.Y;

            return new Point(centerX, centerY);

        }
///////////////////////////////////in a seperate thread
int p,q;
p = Convert.ToInt32(detectedX/3);
q = (Convert.ToInt32(detectedY / 2)-180)*-1;
serialPort1.Write("2" + p.ToString() + "@");
serialPort1.Write("1" + q.ToString() + "@");


This work nice with the static laptop web cam.But when I switch to Pan tilt web cam it runs here and there when it detects a blob..I understand that with the movements of the camera the x,y coordinates get change and this logic is no longer suitable for dynamic camera..Then i implement the previous code.It also do the same..I checked several times,,but i can't catch the error..

Thanks

Dinesh

Re: Object Detction using one webcam

PostPosted: Tue Jun 18, 2013 5:13 am
by Dinesh8818
I am a university student of Sri Lnaka and I doing this as my final year research project.My application has facility to track the object based on color which is selected by a user,by clicking on the video.I have to implement live video streaming part to the client application also,But without completing the server application i cant go further.So your help will be appreciated..

Thank you,
Dinesh

Re: Object Detction using one webcam

PostPosted: Sat Jun 29, 2013 5:51 am
by Dinesh8818
Hi,
I found a solution for my problem and now it works properly. :D

Thanks all.
Dinesh