Bersaelor
Bersaelor

Reputation: 2577

Simple OpenCV example to measure Size of Object on a screen

following up on my other question, do you guys know a good example in OpenCV, with a simple Black/White-Calibration Picture and appropriate detection-algorithms?

I just want to show some B&W-image on a screen, take a picture of that image from afar and calculate the size of the shown image, to calculate the distance to said screen.

Before I invent the wheel again, I recon this is so easy that it could be achieved through many different ways in OpenCV, yet I thought I'd ask if there's a preferred way around, possibly with some sample code.

(I got some face-detection code running using haarcascade-xml files already)

PS: I already have the resolution/dpi-part of my screen covered, so I know how big a picture would be in cm on my screen.

EDIT:

I'll make it real simple, I need:

  1. A pattern, that is easily recognizable in an Image. Right now I'm experimenting with a checkerboard. The people who made ARDefender used this.
  2. An appropriate algorithm to tell me the exact pixel coordinates of pattern 1) in a picture using OpenCV.

Upvotes: 4

Views: 6774

Answers (2)

ArtemStorozhuk
ArtemStorozhuk

Reputation: 8725

Well, it's hard to say which image is the best for recognition - in different illumination any color could be interpret as another color. Simple example:

sample example

As you can see both traffic signs have red color border but even on one image upper sign border is obviously not red.

So in my opinion you should use image with many different colors (like a rainbow). And also you said that it should be easy recognizable in different angles. That's why circle shape is the best for it.

That's why your image should look like this:

example

So idea of detection such object is the following:

  1. Make different color segmentation (blue, red, green etc). For this use HSV color space.
  2. Detect circles of specific color on image.
  3. That area which has the biggest count of circles seems to be your object.

Upvotes: 1

CTZStef
CTZStef

Reputation: 1715

you just have to take pictures of your B&W object from several known distances (1m, 2m, 3m, ...) and then for each distance check the size of your object in the corresponding image. From those datas, you will be able to create a linear function giving you the distance from the size in pixels (y = ax + b should do ;) ), translate it into your code and you're done. Cheers

Upvotes: 0

Related Questions