001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.vision; 006 007import edu.wpi.first.cscore.VideoSource; 008 009/** 010 * A vision thread is a special thread that runs a vision pipeline. It is a <i>daemon</i> thread; it 011 * does not prevent the program from exiting when all other non-daemon threads have finished 012 * running. 013 * 014 * @see VisionPipeline 015 * @see VisionRunner 016 * @see Thread#setDaemon(boolean) 017 */ 018public class VisionThread extends Thread { 019 /** 020 * Creates a vision thread that continuously runs a {@link VisionPipeline}. 021 * 022 * @param visionRunner the runner for a vision pipeline 023 */ 024 public VisionThread(VisionRunner<?> visionRunner) { 025 super(visionRunner::runForever, "WPILib Vision Thread"); 026 setDaemon(true); 027 } 028 029 /** 030 * Creates a new vision thread that continuously runs the given vision pipeline. This is 031 * equivalent to {@code new VisionThread(new VisionRunner<>(videoSource, pipeline, listener))}. 032 * 033 * @param videoSource the source for images the pipeline should process 034 * @param pipeline the pipeline to run 035 * @param listener the listener to copy outputs from the pipeline after it runs 036 * @param <P> the type of the pipeline 037 */ 038 public <P extends VisionPipeline> VisionThread( 039 VideoSource videoSource, P pipeline, VisionRunner.Listener<? super P> listener) { 040 this(new VisionRunner<>(videoSource, pipeline, listener)); 041 } 042}