Skip to content
Hive Vision

Webcam (HSV)

Set up your control hub webcam using the HSV vision processor

HSV track: no Limelight, no TensorFlow, no model but rather a pure color-threshold VisionProcessor runs on the Control Hub itself and reports ball candidates.

Detects in blobs based on color thresholding rather than a pre-trained Tensorflow model like the Limelight 3A

Prerequisites:

  • Webcam (Logitech recommended)
  • Control Hub
  • IDE code editor
  • MacOS, Linux, or Windows computer
  1. Add BallDetectorPipeline.java in TeamCode/ of your FTC project

    • DirectoryTeamCode
      • Directoryjava
        • Directoryorg.firstinspires.ftc.teamcode
          • BallDetectorPipeline.java //Add this
  2. Paste in the code from here

  3. Below that file in TeamCode/, add a file called BallBlobPipeline.java, this will act as your base program.

    • DirectoryTeamCode
      • Directoryjava
        • Directoryorg.firstinspires.ftc.teamcode
          • BallDetectorPipeline.java
          • BallBlobPipeline.java //Add this
  4. Paste in the code from here

  5. Register a new opmode with the following code, rename "Webcam 1" according to your webcam configuration name in the Driver Station.

    • DirectoryTeamCode
      • Directoryjava
        • Directoryorg.firstinspires.ftc.teamcode
          • BallDetectorPipeline.java
          • BallBlobPipeline.java
          • HiveVisionOpmode.java //Add this
    import org.firstinspires.ftc.vision.VisionPortal;
    import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
    import org.opencv.core.Size;
    BallDetectorPipeline baller = new BallDetectorPipeline();
    VisionPortal portal = new VisionPortal.Builder()
    .setCamera(hardwareMap.get(WebcamName.class, "Webcam 1"))
    .setCameraResolution(new Size(1280, 720))
    .addProcessor(baller)
    .enableLiveView(true)
    .build();
  6. Add telemetry for your pipeline’s active detections within the same opmode.

    BallDetectorPipeline.BallBlob red = baller.bestOf(BallDetectorPipeline.BallColor.RED);
    if (red != null) {
    telemetry.addData("red", "cx=%.2f cy=%.2f", red.cxNorm, red.cyNorm);
    }

    bestOf(...) returns null when no blob of that color passes the gates, and a BallBlob with cxNorm / cyNorm (0–1 screen-relative, centered) otherwise. Colors are BallColor.YELLOW, BallColor.RED, BallColor.BLUE.

  7. If your camera’s resolution is ** NOT 1920 x 1080**, follow these steps, otherwise continue to step 8.

    The size and area values in BallDetectorPipeline.java are measured in pixels at the camera resolution, so they have to be scaled to yours. The example in step 5 asks for 1280 x 720, so if you used it unchanged, this step applies to you.

    1. Work out your scale factor: (your width x your height) / (1920 x 1080).
    2. Multiply MIN_AREA_PX, MAX_AREA_PX, EXPECT_YELLOW_AREA, EXPECT_RED_AREA and EXPECT_BLUE_AREA by that factor.
    3. Leave the HSV ranges, MIN_ASPECT, MAX_ASPECT, MIN_FILL and MAX_FILL alone. They are colors and ratios, so they do not change with resolution.
    Constant Default (1920 x 1080) At 1280 x 720 (x 0.444)
    MIN_AREA_PX 900 400
    MAX_AREA_PX 12000 5333
    EXPECT_YELLOW_AREA 3500 1556
    EXPECT_RED_AREA 4200 1867
    EXPECT_BLUE_AREA 4200 1867
  8. Verify in 5 minutes

    1. Deploy your code, and run your OpMode in the driver station, open camera stream with the right 3 dots

    1. Put a pollen in the FOV of the webcam, to see an outline box around the entity

    1. Slide in across the FOV to see the telemetry value cxNorm move from 0 to 1 (left to right)

    1. Repeat the same with the blue and red nectar.

    Webcam camera stream with an outline box around a detected game piece

Success! Congratulations on setting up Hive Vision for your Webcam! Refer to the Webcam TeleOp page for how to apply this pipeline in FTC working code!