A simple OpenCV example for measuring the size of an object on a screen

after my other question , do you guys know a good example in OpenCV, with a simple black and white calibration image and suitable detection algorithms?

I just want to show some B&W image on the screen, take a snapshot of this image from afar and calculate the size of the displayed image to calculate the distance to the specified screen.

Before reinventing the wheel again, I find it so easy that it could be achieved in many different ways in OpenCV, but I thought I'd ask if there was a preferred way, perhaps with some code example.

(I already have a face recognition code using haarcascade-xml files)

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

EDIT:

I will make it very simple, I need:

  • A pattern that is easily recognized in the image. Right now I'm experimenting with a chessboard. The people who made ARDefender used this .
  • The appropriate algorithm for determining the exact pixel coordinates of Figure 1) in the picture using OpenCV.
+4
source share
2 answers

Well, it's hard to say which image is best recognized - in different lighting conditions, any color can be interpreted as a different color. A simple example:

sample example

As you can see, the road signs have a border with red color, but even in one image the upper border of the sign is obviously not red.

So, in my opinion, you should use an image with many different colors (like a rainbow). And also you said that it should be easily recognizable from different angles. Therefore, the round shape is the best for him.

This is why your image should look like this:

example

So, the idea of ​​detecting such an object is as follows:

  • Make different color segmentation (blue, red, green, etc.). Use the HSV color space for this.
  • Detection of circles of a certain color in the image.
  • This area, which has the most circles, seems to be your subject.
+1
source

you just need to photograph 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 this data you can 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. Greetings

0
source

All Articles