how to find the distance between a webcam with an object ..?

 채택된 답변

Walter Roberson
Walter Roberson 2013년 11월 10일

0 개 추천

Take a snapshot. Convert to grayscale. threshold it. Use regionprops() on it to find the MajorAxisLength. If the MajorAxisLength is greater than a pre-determined value, but less than another pre-determined value, then the card is between 30cm and 10cm, so work with that image. Otherwise go back and try again.
To the two "pre-determined value", take a snapshot when you know that the ID card is 30 cm away, and determine the regionprops MajorAxisLength; the other pre-determined value should be found from a snapshot taken 10 cm away.
The Euclidean distance calculation will be done within the regionprops MajorAxisLength request.

댓글 수: 3

Malta
Malta 2013년 11월 10일
can you give me the source code, so that I can learn ..
Malta
Malta 2013년 11월 10일
thanks sir..

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Christopher Jones
Christopher Jones 2013년 10월 29일

0 개 추천

That's a rather general and open ended question. Care to elaborate?

댓글 수: 11

Malta
Malta 2013년 10월 29일
I would like to automatically capture an id card with a webcam with a distance of 10cm, help me...!
Image Analyst
Image Analyst 2013년 10월 29일
Then I think a tape measure or a scale/ruler would be the most appropriate tool to set up the distance between your camera and your subject (the id card).
Malta
Malta 2013년 10월 29일
I want use Euclidean Distance
Walter Roberson
Walter Roberson 2013년 11월 7일
You appear to have a known distance of "10cm". Is that the distance between the webcam and the ID card? Or is that the known physical distance between two items on the ID card? Are you trying to find the distance between the webcam and the ID card, or are you trying to find the "real-world" size of the ID card, or do you know the real size of the ID card and are trying to find the distance between two items on it, or something else?
Malta
Malta 2013년 11월 8일
Walter @ yes, I want to make an application to detect and capture the image id card automatically with a distance of 10cm-20cm, using euclidean distance .. please help me sir ..
Walter Roberson
Walter Roberson 2013년 11월 8일
What information do you have that is known ahead of time, other than that the id card is between 10cm and 20cm away from the webcam? For example, is the entire id card certain to be visible within the image, and is the ID card a known size?
Malta
Malta 2013년 11월 8일
@Walter Roberson : Question : How do I automatically detect and capture the id-card with only distance <30cm using Euclidean distance..?
Walter Roberson
Walter Roberson 2013년 11월 9일
Wait -- do you have a fixed size but moving object, and you want to capture the image only if the object is between 10 cm and 30 cm away?
Malta
Malta 2013년 11월 9일
@Walter Roberson : yes, you are absolutely right sir ..more than 30 cm object is not captured.
Walter Roberson
Walter Roberson 2013년 11월 9일
Is the ID card a fixed size?
Malta
Malta 2013년 11월 10일
편집: Malta 2013년 11월 10일
@Walter Roberson : Yes..sir.. logic like this sir.
  1. standby camera
  2. id card detection (with a distance of 30cm from the camera)
  3. if detected, automatically capture id card
  4. save results capture
  5. finish ..

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2013년 11월 8일

0 개 추천

Malta, like I said, just use a ruler to position your webcam about 10 cm from your card. Make sure that that you can still get an image that is in focus, because that is pretty close and it might be blurry. So once you have that you need to spatially calibrate your scene before you can make laterla measurements from it. For that, please see my calibration demo attached below (simply copy and paste and run).

댓글 수: 3

Malta
Malta 2013년 11월 8일
@Image Analyst : too difficult for me to understand, because I was just learning matlab. Do you have coding euclidean distance on my problem ..?
doc bwdist
bwdist has a euclidean option. I don't see how it'll help you (as IA has pointed out).
Malta: In the code you'll see the line:
lineLength = round(sqrt((xi(1)-xi(2))^2 + (yi(1)-yi(2))^2))
so I did use Euclidean distance.
At this point I don't know how to help you because after many questions we still don't know what you want to take the Euclidean distance of: the distance from your camera to the card, or laterally between two points on the card.
Moreover, I don't know what level of coding I can give you. If I give you something simple, like the line above, it's basically useless because you'll need other code to get the x and y coordinates. But if I give you code for that, like in the attached short and simple example, you say it's too complicated for your to understand. I don't know how to give you anything in between that would be usable by you. For example I could hard code x and y like this:
x = [2 4];
y = [5 9];
lineLength = sqrt((x(1)-x(2))^2 + (y(1)-y(2))^2))
but that's not really any help to you because those x and y are not what you'll be using, so then you're basically going to have to do something like I gave in the example, which you said was too difficult to understand. I'm sorry that I'm not able to find the right level of complexity that you will be able to understand, and at the same time be useful to you.

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2013년 11월 8일

0 개 추천

With that set-up it is not possible to find "distance between webcam with an object", "using euclidean distance". If an object in an image is 100 pixels long, you cannot tell if the object was 100 units long photographed at 10 cm, or 200 units long photographed at 20 cm.

질문:

2013년 10월 29일

댓글:

2013년 11월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by