Class ECoCheckUtils


public class ECoCheckUtils
extends Object

Common functions that are needed for encoding, decoding, and detecting. Terminology can be found in ECoCheckGenerator.

  • Field Details

    • dataBitWidthFraction

      public double dataBitWidthFraction
      Fraction of a bit-cell's length that the black square is drawn in
    • dataBorderFraction

      public double dataBorderFraction
      Fraction length of the quite-zone around data bits
    • markers

      public final List<GridShape> markers
      Shape of all possible markers
    • bitSampleGridSize

      public int bitSampleGridSize
      Length of the row/column in the grid it will sample when determining a cell's bit value
    • bitSampleCount

      protected int bitSampleCount
      Number of samples it will do for each bit. Each sample is one vote. Dynamically computed from bitSampleGridSize
    • codec

      public final ECoCheckCodec codec
      Used to encode and decode bit streams with coordinate information
    • bitOrder

      public final DogArray_I32 bitOrder
      How bits are ordered. This is done to make bits which are in the same word spatially close to each other
  • Constructor Details

    • ECoCheckUtils

      public ECoCheckUtils()
  • Method Details

    • setParametersFromConfig

      public void setParametersFromConfig​(ConfigECoCheckMarkers config)
      Assign all parameters from a config class as possible
    • addMarker

      public void addMarker​(int squareRows, int squareCols)
      Adds a new marker to the list
      squareRows - Number of square rows in the chessboard pattern
      squareCols - Number of square columns in the chessboard pattern
    • fixate

      public void fixate()
      Call after its done being configured so that it can precompute everything that's needed
    • checkFixate

      public void checkFixate()
    • bitRect

      public void bitRect​(int row, int col, Rectangle2D_F64 rect)
      Returns the rectangle in which a data-bit will be written to. The rectangle will be in data-region coordinates.
      row - Bit's row
      col - Bit's column
      rect - (Output) Rectangle containing the bit
    • computeGridToImage

      public boolean computeGridToImage​(Point2D_F64 a, Point2D_F64 b, Point2D_F64 c, Point2D_F64 d)
      Finds the correspondence from data-region coordinates to image pixels
      a - Pixel corresponding to (0,0)
      b - Pixel corresponding to (w,0)
      c - Pixel corresponding to (w,w)
      d - Pixel corresponding to (0,w)
    • otsuThreshold

      public float otsuThreshold​(DogArray_F32 values)
      Computes a threshold using Otsu. Assumes that there are two clear peaks in the data.
    • gridToPixel

      public void gridToPixel​(double x, double y, Point2D_F64 pixel)
      Convenience function to go from a point in grid coordinates to image pixels
    • selectPixelsToSample

      public void selectPixelsToSample​(DogArray<Point2D_F64> pixels)
      Selects pixels that it should sample for each bit. The number of pixels per bit is specified by pixelsPerBit. The order of bits is in row-major format with a block of size bitSampleCount. Points are sampled in a grid pattern with one point in the center. This means there will be an odd number of points preventing a tie.
      pixels - (Output) Image pixels that correspond pixels in binary version of grid
    • cellIdToCornerCoordinate

      public void cellIdToCornerCoordinate​(int markerID, int cellID, GridCoordinate coordinate)
      Given the markerID and cellID, compute the coordinate of the top left corner.
      markerID - (Input) Marker
      cellID - (Input) Encoded cell ID
      coordinate - (Output) Corner coordinate in corner grid of TL corner
    • adjustTopLeft

      public static void adjustTopLeft​(int orientation, GridCoordinate coordinate)
      Adjust the top left corner based on orientation
    • countEncodedSquaresInMarker

      public int countEncodedSquaresInMarker​(int markerID)
      Returns the number of encoded cells in the chessboard
      markerID - (Input) which marker
    • cornerToMarker3D

      public void cornerToMarker3D​(int markerID, int cornerID, Point3D_F64 coordinate)
      Converts a corner ID into a marker ID. The origin of the marker's coordinate system will be the marker's center. Coordinates will range from -0.5 to 0.5. The length of the longest side will be 1.0.
      markerID - Which marker
      cornerID - Which corner
      coordinate - (Output) Coordinate in the coordinate system described above
    • cornerToMarker3D

      public void cornerToMarker3D​(int markerID, int cornerID, double squareLength, Point3D_F64 coordinate)
    • createCornerList

      public List<Point2D_F64> createCornerList​(int markerID, double squareLength)
      Creates a list of corners coordinates on the specified marker given the size of a full square
      markerID - Which marker
      squareLength - Size of a full square
      Location of corners in standard order
    • maxCorners

      public static int maxCorners​(int rows, int cols)
    • isLegalCornerIds

      public boolean isLegalCornerIds​(ECoCheckFound found)
    • mergeAndRemoveUnknown

      public List<ECoCheckFound> mergeAndRemoveUnknown​(List<ECoCheckFound> found)
      Merges detections with the same marker ID into a single detection and removes unknown markers. A naive algorithm is used to merge markers together. First it checks to see if there's a conflict between two markers by them having the same cornerID. If that's good it will select the existing marker with the most corners. If there is no matching marker then a new marker is created.
      found - Original list of found markers.
      New list of markers.