findNearestAsync method

Future<(Mat, Mat, Mat)> findNearestAsync(
  1. Mat samples,
  2. int k
)

Implementation

Future<(Mat results, Mat neighborResponses, Mat dist)> findNearestAsync(Mat samples, int k) async {
  final p = calloc<ffi.Float>();
  final results = Mat.empty();
  final neighborResponses = Mat.empty();
  final dist = Mat.empty();
  try {
    return await cvRunAsync0<(Mat, Mat, Mat)>(
      (callback) => cml.cv_ml_KNearest_findNearest(
        ref,
        samples.ref,
        k,
        results.ref,
        neighborResponses.ref,
        dist.ref,
        p,
        callback,
      ),
      (c) => c.complete((results, neighborResponses, dist)),
    );
  } catch (_) {
    results.dispose();
    neighborResponses.dispose();
    dist.dispose();
    rethrow;
  } finally {
    calloc.free(p);
  }
}