detect method

DetectorResult detect()

Detects a Data Matrix Code in an image.

@return DetectorResult encapsulating results of detecting a Data Matrix Code @throws NotFoundException if no Data Matrix Code can be found

Implementation

DetectorResult detect() {
  final cornerPoints = _rectangleDetector.detect();

  List<ResultPoint> points = _detectSolid1(cornerPoints);
  points = _detectSolid2(points);
  points[3] = _correctTopRight(points)!;
  //if (points[3] == null) {
  //  throw NotFoundException.instance;
  //}
  points = _shiftToModuleCenter(points);

  final topLeft = points[0];
  final bottomLeft = points[1];
  final bottomRight = points[2];
  final topRight = points[3];

  int dimensionTop = _transitionsBetween(topLeft, topRight) + 1;
  int dimensionRight = _transitionsBetween(bottomRight, topRight) + 1;
  if ((dimensionTop & 0x01) == 1) {
    dimensionTop += 1;
  }
  if ((dimensionRight & 0x01) == 1) {
    dimensionRight += 1;
  }

  if (4 * dimensionTop < 6 * dimensionRight &&
      4 * dimensionRight < 6 * dimensionTop) {
    // The matrix is square
    dimensionTop = dimensionRight = math.max(dimensionTop, dimensionRight);
  }

  final bits = _sampleGrid(
    _image,
    topLeft,
    bottomLeft,
    bottomRight,
    topRight,
    dimensionTop,
    dimensionRight,
  );

  return DetectorResult(bits, [topLeft, bottomLeft, bottomRight, topRight]);
}