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

import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.NIVisionException;

public class ImageProcess extends CommandBase {

    private boolean finished = false;
    private ColorImage currentImage;
    private BinaryImage currentBImage;

    public ImageProcess() {
        requires(mainCamera);
    }

    protected void initialize() {
    }

    protected void execute() {
        calculate();
        finished = true;
    }

    protected boolean isFinished() {
        return finished;
    }

    protected void end() {
        freeColorImage();
        freeBImage();
    }

    protected void interrupted() {
        end();
    }

    private void calculate() {
        getColorImage();
        if (currentImage != null) {
            getBImage();
            if (currentBImage != null) {
                freeColorImage();
            }
        }
    }

    private void getColorImage() {
        freeColorImage();
        currentImage = mainCamera.takePicture();
        if (currentImage == null) {
            System.err.println("ImageProcess getColorImage(): mainCamera gave null image.");
        }
    }
    private static final int HUE_LOW = 50;
    private static final int HUE_HIGH = 155;
    private static final int SAT_LOW = 60;
    private static final int SAT_HIGH = 255;
    private static final int LUM_LOW = 60;
    private static final int LUM_HIGH = 255;

    private void getBImage() {
        if (currentImage == null) {
            System.err.println("ImageProcess getBImage(): currentImage is NULL!");
            return;
        }
        freeBImage();
        try {
            currentBImage = currentImage.thresholdHSL(HUE_LOW, HUE_HIGH, SAT_LOW, SAT_HIGH, LUM_LOW, LUM_HIGH);
        } catch (NIVisionException ex) {
            System.err.println("ImageProcess getBImage(): Error While Getting currentImage's Threshold: " + ex + " " + ex.getMessage());
        }
    }

    private void freeColorImage() {
        if (currentImage != null) {
            try {
                currentImage.free();
            } catch (Exception ex) {
                System.err.println("ImageProcess freeColorImage(): Failed to free image with Exception: " + ex + " " + ex.getMessage());
            }
        }
    }

    private void freeBImage() {
        if (currentBImage != null) {
            try {
                currentBImage.free();
            } catch (Exception ex) {
                System.err.println("ImageProcess freeBImage(): Failed to free image with Exception: " + ex + " " + ex.getMessage());
            }
        }
    }
}
<commit_msg>Added a function to get a list of reports from the Binary image<commit_after>package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;

public class ImageProcess extends CommandBase {

    private boolean finished = false;
    private ColorImage currentImage;
    private BinaryImage currentBImage;
    private ParticleAnalysisReport[] particleAnalysisReportList;

    public ImageProcess() {
        requires(mainCamera);
    }

    protected void initialize() {
    }

    protected void execute() {
        calculate();
        finished = true;
    }

    protected boolean isFinished() {
        return finished;
    }

    protected void end() {
        freeColorImage();
        freeBImage();
    }

    protected void interrupted() {
        end();
    }

    private void calculate() {
        getColorImage();
        if (currentImage != null) {
            getBImage();
            if (currentBImage != null) {
                freeColorImage();
                if (getReportList()) {
                }
            }
        }
    }

    private void getColorImage() {
        freeColorImage();
        currentImage = mainCamera.takePicture();
        if (currentImage == null) {
            System.err.println("ImageProcess getColorImage(): mainCamera gave null image.");
        }
    }
    private static final int HUE_LOW = 50;
    private static final int HUE_HIGH = 155;
    private static final int SAT_LOW = 60;
    private static final int SAT_HIGH = 255;
    private static final int LUM_LOW = 60;
    private static final int LUM_HIGH = 255;

    private void getBImage() {
        if (currentImage == null) {
            System.err.println("ImageProcess getBImage(): currentImage is NULL!");
            return;
        }
        freeBImage();
        try {
            currentBImage = currentImage.thresholdHSL(HUE_LOW, HUE_HIGH, SAT_LOW, SAT_HIGH, LUM_LOW, LUM_HIGH);
        } catch (NIVisionException ex) {
            System.err.println("ImageProcess getBImage(): Error While Getting currentImage's Threshold: " + ex + " " + ex.getMessage());
        }
    }

    private void freeColorImage() {
        if (currentImage != null) {
            try {
                currentImage.free();
            } catch (Exception ex) {
                System.err.println("ImageProcess freeColorImage(): Failed to free image with Exception: " + ex + " " + ex.getMessage());
            }
        }
    }

    private void freeBImage() {
        if (currentBImage != null) {
            try {
                currentBImage.free();
            } catch (Exception ex) {
                System.err.println("ImageProcess freeBImage(): Failed to free image with Exception: " + ex + " " + ex.getMessage());
            }
        }
    }

    /**
     * Sets the variable particleAnalysisReportList from currentBImage.
     *
     * @return True if successful, False otherwise.
     */
    private boolean getReportList() {
        if (currentBImage == null) {
            System.err.println("ImageProcess getReportList(): currentBImage is NULL!");
            return false;
        }
        try {
            particleAnalysisReportList = currentBImage.getOrderedParticleAnalysisReports();
        } catch (Exception ex) {
            System.err.println("ImageProcess getReportList(): Exception getting OrderedParticleAnalysisReports from currentBImage: " + ex + " " + ex.getMessage());
            return false;
        }
        if (particleAnalysisReportList == null) {
            System.err.println("ImageProcess getReportList(): particleAnalysisReportList is NULL!");
            return false;
        }
        return true;
    }
}

{'fraction_non_alphanumeric': 0.10044200579180003, 'fraction_numerical': 0.004572473708276178, 'mean_word_length': 2.1188212927756656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2559853', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1744, 'n_words': 447}