What is wrong here? I have my pipeline running but my convexHullsOutput returns false?

public void view(Mat input) {
CvSink gripInput = CameraServer.getInstance().getVideo();
System.out.println(“video sunk”);
while(!Thread.interrupted()) {
if (gripInput.grabFrame(Robot.source) == 0) {


    // GripWhiteLine pipeline = new GripWhiteLine();

    // pipeline.process(input);

    // Robot.convexHullsOutput = pipeline.convexHullsOutput();
    VisionThread visionThread;
    visionThread = new VisionThread(camera, new GripWhiteLine(), pipeline -> {
        if (!pipeline.convexHullsOutput().isEmpty()) {
            // Imgproc Imgproc = new Imgproc();
            Rect r = Imgproc.boundingRect(pipeline.convexHullsOutput().get(0));
            synchronized (imgLock) {
                centerX = r.x + (r.width / 2);
                System.out.println("centerX updated " + centerX);
        } else { 
            System.out.println("FilterContoursOutput is empty");
    System.out.println("vision Thread Started");


I have tested the pipeline too

I’m using a raspberry pi as a coprocessor and this is running on roboImage on frcvision.local (the pi address)

Would be easier to help you seeing the actual pipeline code, but I assume that you know the convexHullsOutput is empty because you’re seeing “FilterContoursOutput is empty” in the console.

Knowing why it’s empty would require knowing what your filter criterion are.

sure here it is:

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.HashMap;

import edu.wpi.first.vision.VisionPipeline;

import org.opencv.core.;
import org.opencv.core.Core.
import org.opencv.features2d.FeatureDetector;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.;
import org.opencv.objdetect.


  • WhiteLineGrip class.

  • An OpenCV pipeline generated by GRIP.

  • @author GRIP
    public class WhiteLineForPI implements VisionPipeline {

    private Mat cvResizeOutput = new Mat();
    private Mat hslThresholdOutput = new Mat();
    private ArrayList findContoursOutput = new ArrayList();
    private ArrayList filterContoursOutput = new ArrayList();
    private ArrayList convexHullsOutput = new ArrayList();

    static {


    • This is the primary method that runs the entire pipeline and updates the outputs.
      @Override public void process(Mat source0) {
      // Step CV_resize0:
      Mat cvResizeSrc = source0;
      Size cvResizeDsize = new Size(0, 0);
      double cvResizeFx = 0.25;
      double cvResizeFy = 0.25;
      int cvResizeInterpolation = Imgproc.INTER_LINEAR;
      cvResize(cvResizeSrc, cvResizeDsize, cvResizeFx, cvResizeFy, cvResizeInterpolation, cvResizeOutput);

      // Step HSL_Threshold0:
      Mat hslThresholdInput = cvResizeOutput;
      double[] hslThresholdHue = {0,0, 66.0};
      double[] hslThresholdSaturation = {0.0, 255.0};
      double[] hslThresholdLuminance = {250.0, 255.0};
      hslThreshold(hslThresholdInput, hslThresholdHue, hslThresholdSaturation, hslThresholdLuminance, hslThresholdOutput);

      // Step Find_Contours0:
      Mat findContoursInput = hslThresholdOutput;
      boolean findContoursExternalOnly = false;
      findContours(findContoursInput, findContoursExternalOnly, findContoursOutput);

      // Step Filter_Contours0:
      ArrayList filterContoursContours = findContoursOutput;
      double filterContoursMinArea = 20.0;
      double filterContoursMinPerimeter = 0.0;
      double filterContoursMinWidth = 0.0;
      double filterContoursMaxWidth = 1000.0;
      double filterContoursMinHeight = 0.0;
      double filterContoursMaxHeight = 1000.0;
      double[] filterContoursSolidity = {0, 100};
      double filterContoursMaxVertices = 1000000.0;
      double filterContoursMinVertices = 0.0;
      double filterContoursMinRatio = 0.0;
      double filterContoursMaxRatio = 1000.0;
      filterContours(filterContoursContours, filterContoursMinArea, filterContoursMinPerimeter, filterContoursMinWidth, filterContoursMaxWidth, filterContoursMinHeight, filterContoursMaxHeight, filterContoursSolidity, filterContoursMaxVertices, filterContoursMinVertices, filterContoursMinRatio, filterContoursMaxRatio, filterContoursOutput);

      // Step Convex_Hulls0:
      ArrayList convexHullsContours = filterContoursOutput;
      convexHulls(convexHullsContours, convexHullsOutput);

      System.out.println(“pipeline ran”);



    • This method is a generated getter for the output of a CV_resize.
    • @return Mat output from CV_resize.
      public Mat cvResizeOutput() {
      return cvResizeOutput;


    • This method is a generated getter for the output of a HSL_Threshold.
    • @return Mat output from HSL_Threshold.
      public Mat hslThresholdOutput() {
      return hslThresholdOutput;


    • This method is a generated getter for the output of a Find_Contours.
    • @return ArrayList output from Find_Contours.
      public ArrayList findContoursOutput() {
      return findContoursOutput;


    • This method is a generated getter for the output of a Filter_Contours.
    • @return ArrayList output from Filter_Contours.
      public ArrayList filterContoursOutput() {
      return filterContoursOutput;


    • This method is a generated getter for the output of a Convex_Hulls.
    • @return ArrayList output from Convex_Hulls.
      public ArrayList convexHullsOutput() {
      return convexHullsOutput;


    • Resizes an image.
    • @param src The image to resize.
    • @param dSize size to set the image.
    • @param fx scale factor along X axis.
    • @param fy scale factor along Y axis.
    • @param interpolation type of interpolation to use.
    • @param dst output image.
      private void cvResize(Mat src, Size dSize, double fx, double fy, int interpolation,
      Mat dst) {
      if (dSize==null) {
      dSize = new Size(0,0);
      Imgproc.resize(src, dst, dSize, fx, fy, interpolation);


    • Segment an image based on hue, saturation, and luminance ranges.
    • @param input The image on which to perform the HSL threshold.
    • @param hue The min and max hue
    • @param sat The min and max saturation
    • @param lum The min and max luminance
    • @param output The image in which to store the output.
      private void hslThreshold(Mat input, double[] hue, double[] sat, double[] lum,
      Mat out) {
      Imgproc.cvtColor(input, out, Imgproc.COLOR_BGR2HLS);
      Core.inRange(out, new Scalar(hue[0], lum[0], sat[0]),
      new Scalar(hue[1], lum[1], sat[1]), out);


    • Sets the values of pixels in a binary image to their distance to the nearest black pixel.
    • @param input The image on which to perform the Distance Transform.
    • @param type The Transform.
    • @param maskSize the size of the mask.
    • @param output The image in which to store the output.
      private void findContours(Mat input, boolean externalOnly,
      List contours) {
      Mat hierarchy = new Mat();
      int mode;
      if (externalOnly) {
      mode = Imgproc.RETR_EXTERNAL;
      else {
      mode = Imgproc.RETR_LIST;
      int method = Imgproc.CHAIN_APPROX_SIMPLE;
      Imgproc.findContours(input, contours, hierarchy, mode, method);


    • Filters out contours that do not meet certain criteria.
    • @param inputContours is the input list of contours
    • @param output is the the output list of contours
    • @param minArea is the minimum area of a contour that will be kept
    • @param minPerimeter is the minimum perimeter of a contour that will be kept
    • @param minWidth minimum width of a contour
    • @param maxWidth maximum width
    • @param minHeight minimum height
    • @param maxHeight maximimum height
    • @param Solidity the minimum and maximum solidity of a contour
    • @param minVertexCount minimum vertex Count of the contours
    • @param maxVertexCount maximum vertex Count
    • @param minRatio minimum ratio of width to height
    • @param maxRatio maximum ratio of width to height
      private void filterContours(List inputContours, double minArea,
      double minPerimeter, double minWidth, double maxWidth, double minHeight, double
      maxHeight, double[] solidity, double maxVertexCount, double minVertexCount, double
      minRatio, double maxRatio, List output) {
      final MatOfInt hull = new MatOfInt();
      for (int i = 0; i < inputContours.size(); i++) {
      final MatOfPoint contour = inputContours.get(i);
      final Rect bb = Imgproc.boundingRect(contour);
      if (bb.width < minWidth || bb.width > maxWidth) continue;
      if (bb.height < minHeight || bb.height > maxHeight) continue;
      final double area = Imgproc.contourArea(contour);
      if (area < minArea) continue;
      if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter) continue;
      Imgproc.convexHull(contour, hull);
      MatOfPoint mopHull = new MatOfPoint();
      mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
      for (int j = 0; j < hull.size().height; j++) {
      int index = (int)hull.get(j, 0)[0];
      double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1]};
      mopHull.put(j, 0, point);
      final double solid = 100 * area / Imgproc.contourArea(mopHull);
      if (solid < solidity[0] || solid > solidity[1]) continue;
      if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount) continue;
      final double ratio = bb.width / (double)bb.height;
      if (ratio < minRatio || ratio > maxRatio) continue;


    • Compute the convex hulls of contours.
    • @param inputContours The contours on which to perform the operation.
    • @param outputContours The contours where the output will be stored.
      private void convexHulls(List inputContours,
      ArrayList outputContours) {
      final MatOfInt hull = new MatOfInt();
      for (int i = 0; i < inputContours.size(); i++) {
      final MatOfPoint contour = inputContours.get(i);
      final MatOfPoint mopHull = new MatOfPoint();
      Imgproc.convexHull(contour, hull);
      mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
      for (int j = 0; j < hull.size().height; j++) {
      int index = (int) hull.get(j, 0)[0];
      double[] point = new double[] {contour.get(index, 0)[0], contour.get(index, 0)[1]};
      mopHull.put(j, 0, point);


oof it didnt auto format as code
i have no idea how to use this site really

the code auto generated with that as the print string haven’t bothered to change it its not a problem

the problem is in the pipeline somewhere but i cannot imagine where it is simply returning an empty arrayList for the convexHullsOutput

if anyone could help that would be great

Does the GRIP pipeline work as you expect when you run it in the Grip program? If it does, the camera setting’s may act differently when plugged into the raspberry pi. Try changing properties using code like camera.setResolution(IMG_WIDTH,IMG_HEIGHT); camera.setBrightness(50); camera.setExposureManual(50)

Yes I finally figured it out by printing all of the pipeline steps to the console until one of them didn’t return and then edited it until it did so it’s fixed now thank you all for the help