视频连续推理
定拍工位连续取图,4 路工人并发推理,队列满就丢当前帧,采集不停。
- C
- C++
- C#
- Python
- Java
- Rust
#include "darra_model.h"
darra_model* m = NULL; uint64_t t[64]; int n = 0; darra_image_desc d = {.size = sizeof(d), .format = DARRA_IMAGE_AUTO};
darra_model_create("line.darmodel", NULL, &m); darra_model_set_workers(m, 4); darra_model_open(m, NULL);
while (grab_frame(&buf, &len) && n < 64) {
if (darra_model_submit(m, buf, len, &d, &t[n]) == DARRA_OK) n++; else drop_frame();
}
for (int i = 0; i < n; i++) { char* j = NULL; if (darra_model_wait(m, t[i], &j) == DARRA_OK) { on_result(j); darra_string_free(j); } }
darra_model_close(m);
#include "darra_ai_model.hpp"
Darra::AI::Model m("line.darmodel"); m.config().workers(4).queue(64); std::vector<uint64_t> tickets;
if (!m.Open().is_success) return 1;
while (grab_frame(frame)) {
auto t = m.submit(frame, Darra::AI::ImageDesc::Auto());
if (t.is_success) tickets.push_back(t.content); else drop_frame();
}
for (uint64_t t : tickets) if (auto r = m.wait(t); r.is_success) on_result(r.content);
using var m = new Darra.AI.Runtime.Model("line.darmodel"); m.Config.Workers = 4; m.Config.Queue = 64; var tickets = new System.Collections.Generic.List<ulong>(); if (!m.Open().IsSuccess) return;
while (TryGrab(out byte[] frame)) {
var t = m.Submit(frame, Darra.AI.Runtime.ImageDesc.Auto());
if (t.IsSuccess) tickets.Add(t.Content); else DropFrame();
}
foreach (var t in tickets) { var r = m.Wait(t); if (r.IsSuccess) Handle(r.Content); }
from darra_ai import Model
with Model("line.darmodel") as m:
m.config.workers = 4; m.config.queue = 64; assert m.open().ok
for frame in camera_frames():
t = m.submit(frame)
if (r := m.wait(t)).ok: on_result(r.content)
import xyz.darra.ai.*;
Model m = new Model("line.darmodel"); m.getConfig().setWorkers(4).setQueue(64);
if (!m.open().isSuccess()) return;
for (byte[] frame : cameraFrames()) {
var r = submitOrDrop(m, frame);
if (r != null && r.isSuccess()) handle(r.getContent());
} m.close();
use darra_ai::{ImageDesc, InferPool, InferPoolOptions};
fn main() -> Result<(), darra_ai::Error> { let pool = InferPool::open_plain("line.darmodel", None, Some(&InferPoolOptions::new().max_workers(4).queue_capacity(64)))?;
for frame in camera_frames() {
if let Ok(t) = pool.submit(&frame, &ImageDesc::auto()) { if let Ok(j) = pool.wait(t) { handle(&j); } } else { drop_frame(); }
}
Ok(())
}
票号按提交顺序取回;提交失败即丢帧,results[] 只来自成功帧。