From 554ed8b6309220013fa28899ad86a4f6a962ed13 Mon Sep 17 00:00:00 2001 From: xinyuli1204 Date: Thu, 30 Nov 2023 13:19:13 -0800 Subject: [PATCH] fix cameraN --- src/bb/image-io/bb.h | 118 +++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index fed6b9c2..5bd27ff2 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -321,82 +321,82 @@ class Camera2 : public ion::BuildingBlock { class CameraN : public ion::BuildingBlock { - public: - GeneratorParam num_devices{"num_devices", 2}; - GeneratorParam gc_title{"gc_title", "USBCamera"}; - GeneratorParam gc_description{"gc_description", "This captures USB camera image."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height), 3] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorParam fps{"fps", 30}; - GeneratorParam width{"width", 0}; - GeneratorParam height{"height", 0}; - GeneratorParam index{"index", 0}; - GeneratorParam urls{"urls", ""}; - -// GeneratorInput[]> urls{"urls"}; - GeneratorOutput output{"output", Halide::type_of(), 3}; - - - void generate() { - - std::stringstream urls_stream(urls); - std::string url; - std::vector url_list; - while(std::getline(urls_stream, url, ';')) - { - url_list.push_back(url); - } +public: + GeneratorParam num_devices{"num_devices", 2}; + GeneratorParam gc_title{"gc_title", "USBCamera"}; + GeneratorParam gc_description{"gc_description", "This captures USB camera image."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height), 3] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + GeneratorParam fps{"fps", 30}; + GeneratorParam width{"width", 0}; + GeneratorParam height{"height", 0}; + GeneratorParam index{"index", 0}; + GeneratorParam urls{"urls", ""}; - using namespace Halide; +// GeneratorInput[]> urls{"urls"}; + GeneratorOutput output{"output", Halide::type_of(), 3}; - output.resize(num_devices); - for (int i =0; i < num_devices; i++){ - std::string url_str; - if (url_list.size()!=0){ - url_str = url_list[i]; - } - else{ - url_str = ""; - } + void generate() { + std::stringstream urls_stream(urls); + std::string url; + std::vector url_list; + while(std::getline(urls_stream, url, ';')) + { + url_list.push_back(url); + } - Halide::Buffer url_buf(url_str.size() + 1); - url_buf.fill(0); - std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + using namespace Halide; - std::vector params = {instance_id++, cast(index), cast(fps), cast(width), cast(height), url_buf}; - Func camera(static_cast(gc_prefix) + "camera"); - camera.define_extern("ion_bb_image_io_camera", params, Halide::type_of(), 2); - camera.compute_root(); + output.resize(num_devices); - Func camera_ = BoundaryConditions::repeat_edge(camera, {{0, 2 * width}, {0, height}}); + for (int i =0; i < num_devices; i++){ + std::string url_str; + if (url_list.size()!=0){ + url_str = url_list[i]; + } + else{ + url_str = ""; + } - Var c, x, y; - Expr yv = cast(camera_(2 * x, y)); - Expr uv = cast(camera_(select((x & 1) == 0, 2 * x + 1, 2 * x - 1), y)); - Expr vv = cast(camera_(select((x & 1) == 0, 2 * x + 3, 2 * x + 1), y)); - Expr f128 = cast(128); - Expr r = saturating_cast(yv + cast(1.403f) * (vv - f128)); - Expr g = saturating_cast(yv - cast(0.344f) * (uv - f128) - (cast(0.714f) * (vv - f128))); - Expr b = saturating_cast(yv + cast(1.773f) * (uv - f128)); + Halide::Buffer url_buf(url_str.size() + 1); + url_buf.fill(0); + std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + std::vector params = {instance_id++, cast(index), cast(fps), cast(width), cast(height), url_buf}; + Func camera(static_cast(gc_prefix) + "camera"); + camera.define_extern("ion_bb_image_io_camera", params, Halide::type_of(), 2); + camera.compute_root(); - Func f(static_cast(gc_prefix) + "output" + std::to_string(i)); - f(x, y, c) = mux(c, {r, g, b}); + Func camera_ = BoundaryConditions::repeat_edge(camera, {{0, 2 * width}, {0, height}}); - output[i](_) = f(_); - } + Var c, x, y; + Expr yv = cast(camera_(2 * x, y)); + Expr uv = cast(camera_(select((x & 1) == 0, 2 * x + 1, 2 * x - 1), y)); + Expr vv = cast(camera_(select((x & 1) == 0, 2 * x + 3, 2 * x + 1), y)); + + Expr f128 = cast(128); + Expr r = saturating_cast(yv + cast(1.403f) * (vv - f128)); + Expr g = saturating_cast(yv - cast(0.344f) * (uv - f128) - (cast(0.714f) * (vv - f128))); + Expr b = saturating_cast(yv + cast(1.773f) * (uv - f128)); + + + Func f(static_cast(gc_prefix) + "output" + std::to_string(i)); + f(x, y, c) = mux(c, {r, g, b}); + + output[i](_) = f(_); } + + } };