Limelight finding number of targets

How do you find the number of april tags detected by limelight?

You must use the JSON output (LimelightHelpers is helpful) and look for the length of the fiducals array result.targets_Fiducials.length

Yes everyone wishes it was easier. I made an issue here.

1 Like

Thanks, I counted the number of occurrences of “pts” in the JSON dump since “pts” only occurs once per tag.

public int getNumTargets() {
    return countStringOccurrences(NetworkTableInstance.getDefault().getTable(m_name).getEntry("json").getString(""), "pts");
}

private int countStringOccurrences(String str, String substr) {
    int occurrences = 0;
    for (int i = 0; i < str.length()-substr.length()+1; i++) {
        if (str.substring(i, i+substr.length()).equals(substr)) {
            occurrences++;
        }
    }
    return occurrences;
}
1 Like

Now Limelight provides a number for the tag count, it is the 7th index of the botpose array Complete NetworkTables API | Limelight Documentation

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.