<commit_before>package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.CriteriaCollection;
import edu.wpi.first.wpilibj.image.NIVision.MeasurementType;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;

/**
 * TargetLocator determines the location of the target relative to the camera.
 * An image from the camera is stored on the cRio flash memory, and then
 * filtered to eliminate everything except potential targets. Then, a particle
 * analysis report uses criteria defined in this class to determine all
 * particles on the screen. Finally, the positions of the centers of these
 * particles is printed to the console.
 *
 *
 * @author (<NAME>, Team 3167)
 * @version (March 2, 2014)
 */
class TargetLocator {

    AxisCamera camera = AxisCamera.getInstance("10.31.67.11");  //create an instance of the camera
    CriteriaCollection criteria = new CriteriaCollection();  //criteria for what constitutes a particle
    double x;

    public double findTarget() throws NIVisionException, AxisCameraException {  //determines the x-positions of the centers of mass of all particles

        try {

            criteria.addCriteria(MeasurementType.IMAQ_MT_AREA, 30, 400, false);  //minimum size of a particle
            criteria.addCriteria(MeasurementType.IMAQ_MT_AREA, 30, 400, false);

            ColorImage image;
            image = camera.getImage();  //store the image from the camera
            BinaryImage thresholdImage = image.thresholdRGB(79, 255, 71, 255, 113, 255);  //filter out parts of image that do not possess a significant green component
            BinaryImage bigObjectsImage = thresholdImage.removeSmallObjects(false, 2);  //filter out green objects too small to be the target
            BinaryImage convexHullImage = bigObjectsImage.convexHull(false);  //fill in occluded rectangles
            BinaryImage filteredImage = convexHullImage.particleFilter(criteria);  //apply the criteria defined above

            ParticleAnalysisReport[] reportArray = filteredImage.getOrderedParticleAnalysisReports();  //creates an array of particle analysis reports

            filteredImage.free();  //delete all images used above
            convexHullImage.free();
            bigObjectsImage.free();
            thresholdImage.free();
            image.free();

            double x1 = reportArray[1].center_mass_x_normalized; //return center of mass of one bar
            double x2 = reportArray[2].center_mass_x_normalized; //return center of mass of the other
            x = (x1 + x2) / 2;  //take the average of both

        } catch (NIVisionException e) {

            e.printStackTrace();

        } catch (AxisCameraException e) {<commit_msg>Updated thresholdRGB for our ring lights<commit_after>package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.CriteriaCollection;
import edu.wpi.first.wpilibj.image.NIVision.MeasurementType;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;

/**
 * TargetLocator determines the location of the target relative to the camera.
 * An image from the camera is stored on the cRio flash memory, and then
 * filtered to eliminate everything except potential targets. Then, a particle
 * analysis report uses criteria defined in this class to determine all
 * particles on the screen. Finally, the positions of the centers of these
 * particles is printed to the console.
 *
 *
 * @author (<NAME>ato, Team 3167)
 * @version (March 2, 2014)
 */
class TargetLocator {

    AxisCamera camera = AxisCamera.getInstance("10.31.67.11");  //create an instance of the camera
    CriteriaCollection criteria = new CriteriaCollection();  //criteria for what constitutes a particle
    double x;

    public double findTarget() throws NIVisionException, AxisCameraException {  //determines the x-positions of the centers of mass of all particles

        try {

            criteria.addCriteria(MeasurementType.IMAQ_MT_AREA, 5, 400, false);  //minimum size of a particle

            ColorImage image;
            image = camera.getImage();  //store the image from the camera
            BinaryImage thresholdImage = image.thresholdRGB(0, 0, 67, 255, 0, 111);  //filter out parts of image that do not possess a significant green component
            BinaryImage bigObjectsImage = thresholdImage.removeSmallObjects(false, 4);  //filter out green objects too small to be the target
            BinaryImage convexHullImage = bigObjectsImage.convexHull(false);  //fill in occluded rectangles
            BinaryImage filteredImage = convexHullImage.particleFilter(criteria);  //apply the criteria defined above

            ParticleAnalysisReport[] reportArray = filteredImage.getOrderedParticleAnalysisReports();  //creates an array of particle analysis reports

            filteredImage.free();  //delete all images used above
            convexHullImage.free();
            bigObjectsImage.free();
            thresholdImage.free();
            image.free();

//          double x1 = reportArray[1].center_mass_x_normalized; //return center of mass of one bar
//          double x2 = reportArray[2].center_mass_x_normalized; //return center of mass of the other
            x = reportArray[1].center_mass_x;  //take the average of both

        } catch (NIVisionException e) {

            e.printStackTrace();

        } catch (AxisCameraException e) {
{'fraction_non_alphanumeric': 0.08153191489361702, 'fraction_numerical': 0.015148936170212766, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3397781', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1556, 'n_words': 519}