createVideoWorker method Null safety

VideoWorker createVideoWorker(
  1. VideoWorkerParams params
)

Creates a VideoWorker object

it is used to:

  • track faces on video stream
  • create templates
  • match templates with the database
  • estimate age, gender, and emotions
  • estimate liveness
  • match the faces detected in a specified period with each other.

Implementation

VideoWorker createVideoWorker(VideoWorkerParams params) {
  final vwConstructor = _dll_handle.lookupFunction<_VWConstructor_c, _VWConstructor_dart>(
      _c_namespace + 'FacerecService_createVideoWorker_sti_age_gender_emotions');
  final exception = _getException();

  Pointer<Int32> _emptyPointer = malloc.allocate(1);
  Pointer<Pointer<Utf8>> _emptyPointerStrList = malloc.allocate(1);
  Pointer<Double> _emptyPointerDouble = malloc.allocate(1);

  final vw_config = _facerecConfDir + params._video_worker_config._configFilepath;
  if (params._active_liveness_checks_order.isNotEmpty) {
    if ({...params._active_liveness_checks_order}.length != params._active_liveness_checks_order.length)
      throw ("Error 0x3302330e: Set a unique order of `active_liveness_checks_order` for Active Liveness.");
    for (int i = 0; i < params._active_liveness_checks_order.length; i++) {
      final check = params._active_liveness_checks_order[i];
      var check_str = "active_liveness.check_" + check.toString().split('.').last.toLowerCase();
      params._video_worker_config.overrideParameter(check_str, -(i + 1).toDouble());
    }
  }
  final res_vw = params._video_worker_config._prepare();

  final rec_config = _facerecConfDir + params._recognizer_ini_file;

  final vw_pointer = vwConstructor(
      _impl,
      // service

      _emptyPointer.cast(),
      // trackingCallback
      _emptyPointer.cast(),
      // templateCreatedCallback
      _emptyPointer.cast(),
      // matchFoundCallback
      _emptyPointer.cast(),
      // trackingLostCallback
      _emptyPointer.cast(),
      // stiPersonOutdatedCallback

      vw_config.toNativeUtf8(),
      // video_worker_ini_file
      res_vw.length,
      // vw_overridden_count
      res_vw.keys,
      // vw_overridden_keys
      res_vw.values,
      // vw_overridden_values

      rec_config.toNativeUtf8(),
      // recognizer_ini_file
      0,
      // rec_overridden_count
      _emptyPointerStrList,
      // rec_overridden_keys
      _emptyPointerDouble,
      // rec_overridden_values

      params._streams_count,
      // streams_count
      params._processing_threads_count,
      // processing_threads_count
      params._matching_threads_count,
      // matching_threads_count

      params._short_time_identification_enabled,
      // short_time_identification_enabled
      params._short_time_identification_distance_threshold,
      // short_time_identification_distance_threshold
      params._short_time_identification_outdate_time_seconds,
      // short_time_identification_outdate_time_seconds

      params._age_gender_estimation_threads_count,
      // age_gender_threads_count
      params._emotions_estimation_threads_count,
      // emotions_threads_count

      exception /*out_exception*/);
  checkException(exception, _dll_handle);

  return VideoWorker(_dll_handle, vw_pointer);
}