detect method

List<ResultPoint> detect()

Detects a rectangular region of black and white -- mostly black -- with a region of mostly white, in an image.

@return ResultPoint describing the corners of the rectangular region. The first and last points are opposed on the diagonal, as are the second and third. The first point will be the topmost point and the last, the bottommost. The second point will be leftmost and the third, the rightmost @throws NotFoundException if no Data Matrix Code can be found

Implementation

List<ResultPoint> detect() {
  final height = _image.height;
  final width = _image.width;
  final halfHeight = height ~/ 2;
  final halfWidth = width ~/ 2;
  final deltaY = math.max(1, height ~/ (_maxModules * 8));
  final deltaX = math.max(1, width ~/ (_maxModules * 8));

  int top = 0;
  int bottom = height;
  int left = 0;
  int right = width;
  ResultPoint pointA = findCornerFromCenter(
    halfWidth,
    0,
    left,
    right,
    halfHeight,
    -deltaY,
    top,
    bottom,
    halfWidth ~/ 2,
  );
  top = pointA.y.toInt() - 1;
  final pointB = findCornerFromCenter(
    halfWidth,
    -deltaX,
    left,
    right,
    halfHeight,
    0,
    top,
    bottom,
    halfHeight ~/ 2,
  );
  left = pointB.x.toInt() - 1;
  final pointC = findCornerFromCenter(
    halfWidth,
    deltaX,
    left,
    right,
    halfHeight,
    0,
    top,
    bottom,
    halfHeight ~/ 2,
  );
  right = pointC.x.toInt() + 1;
  final pointD = findCornerFromCenter(
    halfWidth,
    0,
    left,
    right,
    halfHeight,
    deltaY,
    top,
    bottom,
    halfWidth ~/ 2,
  );
  bottom = pointD.y.toInt() + 1;

  // Go try to find point A again with better information -- might have been off at first.
  pointA = findCornerFromCenter(
    halfWidth,
    0,
    left,
    right,
    halfHeight,
    -deltaY,
    top,
    bottom,
    halfWidth ~/ 4,
  );

  return [pointA, pointB, pointC, pointD];
}