SSCMEx.Examples.CameraInference (sscmex v0.3.6)

Copy Markdown

Full example: load model, configure camera to model input size, capture one frame, then run inference.

Run from IEx (from the sscmex or example project):

SSCMEx.load_nif()

# run_once returns {:ok, result} or {:error, reason} — handle both
case SSCMEx.Examples.CameraInference.run_once("/data/yolo11n_detection_cv181x_int8.cvimodel") do
  {:ok, result} -> IO.inspect(result.detections)
  {:error, reason} -> IO.puts("Failed: #{inspect(reason)}")
end

If you get {:error, ~c"retrieve_frame_failed"}: check dmesg. "vpss_get_chn_frame fail" or "vi err" means the camera/VI pipeline is not delivering frames (sensor or timing). Try preset_idx: 3 for a smaller resolution, or a longer warm-up. "ion allocated failed" means out of ION memory. This example reduces peak usage by configuring the camera output to the model input resolution before streaming.

Summary

Functions

One-shot example: load model, configure camera to model input size, then run inference.

Same as run_once/2 but raises on error so you get a clear exception instead of MatchError.

Step-by-step flow you can copy into your app.

Functions

run_once(model_path, opts \\ [])

One-shot example: load model, configure camera to model input size, then run inference.

Options

  • :model_path (required) - Path to the .cvimodel file
  • :preset_idx - Sensor preset index (default 3). Output size is still set from model input shape.
  • :camera_fps - Camera FPS for the RAW channel (default 3)
  • :threshold_score - Detection score threshold 0.0–1.0 (default 0.5)
  • :threshold_nms - NMS threshold 0.0–1.0 (default 0.45)
  • :warm_up_ms - Delay after start_stream before first retrieve (default 1500). Increase if dmesg shows "vi err".

Returns

  • {:ok, %{frame: image, detections: detections, perf: perf}} on success
  • {:error, reason} on failure

Example

case SSCMEx.Examples.CameraInference.run_once(
       "/data/yolo11n_detection_cv181x_int8.cvimodel",
       preset_idx: 3,
       threshold_score: 0.5
     ) do
  {:ok, result} ->
    IO.inspect(result.detections)
    IO.inspect(result.perf)
  {:error, reason} ->
    IO.puts("Error: #{inspect(reason)}")
end

Or use run_once!/2 to raise on failure (so you get a clear error instead of MatchError):

result = SSCMEx.Examples.CameraInference.run_once!(path, preset_idx: 3)

run_once!(model_path, opts \\ [])

Same as run_once/2 but raises on error so you get a clear exception instead of MatchError.

Use when you want to pattern-match only on success; on failure you get e.g.: raise SSCMEx.Examples.CameraInference.Error, "retrieve_frame_failed"

result = SSCMEx.Examples.CameraInference.run_once!(path, preset_idx: 3)

steps()

Step-by-step flow you can copy into your app.

This flow mirrors sscma-elixir: load model first, then configure camera output to model input dimensions before starting the stream.