AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Object Detction using one webcam

The forum is to discuss topics related to robotics, like building robot, controlling it, its software and hardware, etc.

Object Detction using one webcam

Postby george » Mon Jul 20, 2009 6:01 pm

hi,

i am using the project "making a step to stereo vision" of two webcams which are used to detect the object and move both the cameras accordingly. i want to use only one camera which should detect the object and move the motors in the object direction. i have understood what the objectX, objctY, x1,x2,y1, and y2 are in the program but i cannot separate them. in the below line, the center of both cameras has been used which i want to change and use the center of image of only one camera. can you please help me find out where do i need to change or add the code???

// run motors for the specified amount of degrees (max 2 deg.)
RunMotors( 2 * targetX, -2 * targetY );

regards,

Gino George,
UK.
george
 
Posts: 5
Joined: Thu Jul 09, 2009 1:31 pm

Re: Object Detction using one webcam

Postby andrew.kirillov » Mon Jul 20, 2009 6:58 pm

Hello,

I would suggest you to take a look at another article - Lego Pan Tilt Camera and Objects Tracking. This one describes very similar project, but uses one camera only.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3446
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Object Detction using one webcam

Postby george » Mon Jul 20, 2009 7:14 pm

hi andrew,

i already had a look on that application, but the problem is that im using the webcam without using any lego kit, plus im also connecting the webcam directly using the drivers. when i try to run the lego application, it fails to connect the camera using COM when i click on connect button. i cannot go throught of it because of this problem. plus it also uses motor states rather than the runmotors which is used in the stereo vision. im very new to these applications and was wondering if i could get any help in this stereo vision project. any suggestion will be appriciated.

regards,

Gino George,
UK.
george
 
Posts: 5
Joined: Thu Jul 09, 2009 1:31 pm

Re: Object Detction using one webcam

Postby andrew.kirillov » Mon Jul 20, 2009 7:33 pm

Well, I am a bit confused :? I though your problem was with video and how to get object's coordinates using single camera only ...

You don't need to have any Lego stuff. You don't need even to run that application. Just open its sources and take a look how object detection is done and its coordinates are retrieved.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3446
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Object Detction using one webcam

Postby george » Tue Jul 21, 2009 11:33 am

hi andrew,

i have read the lego source and i got to know that SetMotorsPower(pan, tilt) method is used to drive the motors in the direction of detected object if im right? but i saw in SetMotorsPower method the builtin method SetMotorState() is used to handle the motors accordingly, while in other program, i can only see the method RunMotors(x,y) used where we are passing the x and y coordinates to moveCamerasForm and then it invokes the method UpdateValue() for running the motors. i tried passing the values of only one camera to this method i mean only x1 and y1 which configure the center point of first camera i think??? but the program still works in the same way rather than looking for only x1, and y1 which i cannot understand. can you please help me in this, also my task is to use two cameras in future which is why im not using that other lego application. i am just stuck in this problem and cannot exactly find out how i can run only one camera at a time and make other camera wait for the first and then work in the same way as the first one works?

regards,

George,
UK
george
 
Posts: 5
Joined: Thu Jul 09, 2009 1:31 pm

Re: Object Detction using one webcam

Postby andrew.kirillov » Tue Jul 21, 2009 2:22 pm

Hello,

OK, lets take a closer look into the application, which is provided with "Making a step to stereo vision" article. In MainForm.TrackingThread(), lines 378-379:
Code: Select all
// get middle point
targetX = ( x1 + x2 ) / 2;
targetY = ( y1 + y2 ) / 2;

change to
Code: Select all
// get middle point
targetX = x1;
targetY = y1;


That is all about object's coordinates. You may also need to remove/comment the code related to the second camera. At least you need to remove camera2Acquired.WaitOne( ); from the tracking thread - don't need to wait for the second camera.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3446
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Object Detction using one webcam

Postby allenborder » Wed Jul 22, 2009 11:15 am

Hi to all...
Same suggestion by me you must take a look at another article - Lego Pan Tilt Camera and Objects Tracking. This one describes very similar project, but uses one camera only.
allenborder
 
Posts: 3
Joined: Wed Jul 22, 2009 10:33 am

Re: Object Detction using 1 webcam (ArgumentOutofRangeException)

Postby george » Wed Jul 22, 2009 1:55 pm

hi andrew,

thank you very much for your help. i set the target values to x1, y1, and used another thread for camera2 by setting the targetX2, targetY2 to x2,y2. now both cameras are working properly without looking for the center point between them . they are working individualy. i am having another problem in the program that is its throwing an exception after some tracking operations. the exception is

ArgumentOutofRangeException was unhandled
Value of '-2267' is not valid for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'.
Parameter name: Value

as far as i have known it is the value of the angle that im passing to the invoke method for the tilt and pan operations. i think these values are going out of range which i just want to control. when i run the program for some time, it freezes and throws this exception. any help will be appreciated. thank you.

also i was just wondering to know bit more detail about the motor control. it takes the center point of the image and turns the motors according to the center. can you please write a little about how it is following the center point of the image. thank you again

Regards,

Gino George,
UK.
george
 
Posts: 5
Joined: Thu Jul 09, 2009 1:31 pm

Re: Object Detction using one webcam

Postby samosamo » Thu Sep 17, 2009 10:12 am

Hello!

I have one question. I have one web cam and two servo motors and I write program for control servo motor base on web cam. I dont know when I can sent fuction for move servo motors. I have two idea but dont know whitch is good.

When program finished with image procesing (in private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)) I will send fuction for move servo motor. Or I must do Thread in program?

Thanks for help!

Samo Simončič Slovenia
samosamo
 
Posts: 35
Joined: Thu Jul 23, 2009 1:11 pm

Re: Object Detction using one webcam

Postby andrew.kirillov » Thu Sep 17, 2009 4:17 pm

Hello,

I would do this (actually I did this in my apps) in separate thread, so image processing is not delayed/affected by motors/servo driving.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3446
Joined: Fri Jan 23, 2009 9:12 am
Location: UK



Next

Return to Robotics