Measure research - dnum-mi/basegun-ml GitHub Wiki

Different Ways to Measure Length Using Computer Vision

Measuring length from images or videos is a common task in computer vision. We have studied several computer vision techniques to determine the best solution for the use-case. Some methods require a reference object to determine the actual length, while others do not.

In the case of measurement using a reference object, here is the primary strategy:

  • Measure the reference object and the target object in the image in pixels.
  • Using the known length of the reference object, determine a length factor in px/cm.
  • Calculate the target length using the measurement in pixels and the length factor.

Measurement Without Reference: Augmented Reality

One approach to measuring actual lengths in an application without a reference object is the use of augmented reality algorithms. This allows you to measure distances in your environment from your phone, in real time.

Advantages Drawbacks
Precision of the measurement (Dependent on the user) CPU usage, battery drain
No need for a reference object User experience
Hardware compatibility

Useful Links

Measurement Without Reference: Using Focal Length

Another method for measuring actual lengths in an application without a reference object involves using the focal length and other parameters. This approach determines the real size of an object by proportionality, based on the following elements:

  • Focal length -> Photo metadata (depends on the phone model)
  • Sensor size -> Photo metadata
  • Object distance from the camera -> LiDAR or MIDaS depth estimation algorithm
  • Weapon size in pixels
Advantages Drawbacks
User experience (only a single photo is necessary) Availability of metadata
No need for a reference object Availability of LiDAR
Limited precision of depth estimation algorithms

Useful Links

Measurement with a Reference: Segmentation

Segmentation involves determining whether each pixel in an image belongs to the object of interest. The result is a cutout of the weapon. It's possible to use SOD algorithms that segment the object in the foreground, which requires no specific training, or algorithms to be retrained for our use case, such as YOLOv8.

Advantages Drawbacks
Precision of the algorithm Use of computational resources
No need for training with some models (SOD, SAM) GPU may be necessary for training

Segmentation Models

Measurement with a Reference: Object and Keypoint Detection

Object detection involves detecting the presence of an object in an image. The process is generally divided into two stages:

  • Determination of the object's potential locations, which are represented using bounding boxes,
  • Identification of the class of the object identified.

This method can be complemented by keypoint detection, which involves detecting the object's points of interest in the image. For example, the eyes in the case of face detection.

Advantages Drawbacks
Inference time on CPU compatible with use case Bounding box and keypoint precision
Good performance for object detection Transfer learning mandatory to specialize the models on the use-case

Useful Links

Measurement with a Reference: Computer Vision

To measure a distance in pixels on an image or detect an object, you don't necessarily need to use resource-intensive deep learning methods, as computer vision methods exist for shape recognition or contour detection. Once the object has been detected, it's simply a matter of calculating the distance based on the position of its extremities.

Advantages Drawbacks
Inference time on CPU compatible with use case Precision of the algorithms
Simplicity of treatments Precision highly dependent on background

Useful Links