Tech Toolbox
  • Please Visit https://ftc-tech-toolbox.vercel.app/ for the new tech toolbox!!
    • Introduction
    • Choosing an IDE
    • Creating an OpMode
    • Motors and Encoders
    • Servos
    • Gamepad Controls
    • Drive Systems
    • Lynx Modules
    • Telemetry
    • Wireless Download
    • The Sleep Command
  • Please Visit the New Link
    • Tank Drive / Skid Steer (Part 1)
    • Mecanum Drive (Part 1)
    • Turrets
    • Linear Slides
    • Kicker
    • Active Intake / Sweepers
    • Flywheels / Shooters
  • Please Visit the new Link
    • Base Class (Step 1)
    • Module Classes (Step 2)
    • OpMode Classes (Step 3)
  • This domain is now depreciated and is no longer updated!
  • This domain is now depreciated and is no longer updated!
    • What is Localization?
    • General Odometry Logic
    • Tank (No Deadwheels)
    • Mecanum (No Deadwheels)
    • Deadwheel Odometry (Mecanum and Tank)
    • VSLAM
  • This domain is now depreciated and is no longer updated!
    • What is Control Theory?
    • Custom PID Loops
    • Essential Control Theory Concepts
    • Resources for Learning Advanced Control Theory
  • This domain is now depreciated and is no longer updated! Please visit this domain for the new TT!
    • Introduction
    • Mecanum Drive (Part 2)
    • Tank Drive (Part 2)
    • Introduction to Pure Pursuit
    • Pure Pursuit: Mecanum
    • Pure Pursuit: Tank
    • Advanced Pure Pursuit
    • Guided Vector Fields
    • Autonomous Movement Libraries
  • Sensors
    • IMU
    • Color Sensors
      • Advanced Sensing Code
    • Distance Sensors
    • Touch Sensor
  • Computer Vision
    • Setting up Camera/Intro to Computer Vision Tools
      • Intro to OpenCV
      • Vuforia
    • Streaming Frames
    • Color Thresholding
    • April Tags
    • Linear Regression
    • Machine Learning Toolchain
    • Object Distance Estimation
    • Object Tracking / Driving to an Object
    • Computer Vision Simulators
  • Simulators
    • Beta8397 Simulator
    • VRS
  • Cool Codebases
Powered by GitBook
On this page
  1. Computer Vision

Object Distance Estimation

PreviousMachine Learning ToolchainNextObject Tracking / Driving to an Object

Last updated 1 year ago

This module shows you how to estimate the distance of a detected game element.

For mono camera depth estimation use this tutorial:

The following tutorial only covers finding the object's distance on the z-axis (how far in front the object is compared to the camera). However to navigate to the object we will need the distances on the x and y axis (how far the object is to the side of the camera and above the camera). Our code will implement the specified additions. For more information on the derivation of these equations, refer to page 5 of this paper:

Implementation

Here are a couple of important notes about the tutorial:

  • The focal length for your webcam can easily be found through a simple Google search (ex. logitech xyz focal length)

  • Remember all of the measurement values must be in the same units, so make sure your code converts the units correctly.

  • To attain the pixel width of the object (object_width_in_frame) you must measure the width of the detected object's bounding box.

Your distance computation code should look something like this:

/*Finds the distance of a detected object in real-world units
* camera_center_pixel_x = horizontal_resolution/2
* camera_center_pixel_y = vertical_resolution/2
* Focal_Length: focal length of the camera
* real_object_width: measured width of the game element (must be in the same units as the focal length)
* object_width_in_frame: width of the bounding box (in pixels)
*/
public double[] Distance_finder(
double Focal_Length, 
double camera_center_pixel_x, 
double camera_center_pixel_y,
double real_object_width, 
double object_width_in_frame, 
double object_x_pixel_coordinate, 
double object_y_coordinate){ 
    // how far in front the object is from the camera
    distance_z = (real_object_width * Focal_Length)/object_width_in_frame; 
    // how far to the side the object is from the camera
    distance_x = (distance_z / Focal_Length) *
    (object_x_pixel_coordinate - camera_center_pixel_x);        
    // how far above the object is from the camera 
    distance_y = (distance_z / Focal_Length) *
    (object_y_pixel_coordinate - camera_center_pixel_y); 
    return {distance, distance_x, distance_y}
}
https://github.com/MrinallU/Image-Depth-Estimation-Via-Stereo-Vision/blob/master/Paper%20(1).pdf
Distance(webcam) Estimation with single-camera 📷 OpenCV-pythonMedium
Logo