Skip to content

Commit

Permalink
fix cameraN
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyuli1204 committed Nov 30, 2023
1 parent 1b7962e commit 554ed8b
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions src/bb/image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,82 +321,82 @@ class Camera2 : public ion::BuildingBlock<Camera2> {


class CameraN : public ion::BuildingBlock<CameraN> {
public:
GeneratorParam<int32_t> num_devices{"num_devices", 2};
GeneratorParam<std::string> gc_title{"gc_title", "USBCamera"};
GeneratorParam<std::string> gc_description{"gc_description", "This captures USB camera image."};
GeneratorParam<std::string> gc_tags{"gc_tags", "input,sensor"};
GeneratorParam<std::string> gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height), 3] }}))"};
GeneratorParam<std::string> gc_mandatory{"gc_mandatory", "width,height"};
GeneratorParam<std::string> gc_strategy{"gc_strategy", "self"};
GeneratorParam<std::string> gc_prefix{"gc_prefix", ""};

GeneratorParam<int32_t> fps{"fps", 30};
GeneratorParam<int32_t> width{"width", 0};
GeneratorParam<int32_t> height{"height", 0};
GeneratorParam<int32_t> index{"index", 0};
GeneratorParam<std::string> urls{"urls", ""};

// GeneratorInput<Buffer<uint8_t>[]> urls{"urls"};
GeneratorOutput<Halide::Func[]> output{"output", Halide::type_of<uint8_t>(), 3};


void generate() {

std::stringstream urls_stream(urls);
std::string url;
std::vector<std::string> url_list;
while(std::getline(urls_stream, url, ';'))
{
url_list.push_back(url);
}
public:
GeneratorParam<int32_t> num_devices{"num_devices", 2};
GeneratorParam<std::string> gc_title{"gc_title", "USBCamera"};
GeneratorParam<std::string> gc_description{"gc_description", "This captures USB camera image."};
GeneratorParam<std::string> gc_tags{"gc_tags", "input,sensor"};
GeneratorParam<std::string> gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height), 3] }}))"};
GeneratorParam<std::string> gc_mandatory{"gc_mandatory", "width,height"};
GeneratorParam<std::string> gc_strategy{"gc_strategy", "self"};
GeneratorParam<std::string> gc_prefix{"gc_prefix", ""};

GeneratorParam<int32_t> fps{"fps", 30};
GeneratorParam<int32_t> width{"width", 0};
GeneratorParam<int32_t> height{"height", 0};
GeneratorParam<int32_t> index{"index", 0};
GeneratorParam<std::string> urls{"urls", ""};

using namespace Halide;
// GeneratorInput<Buffer<uint8_t>[]> urls{"urls"};
GeneratorOutput<Halide::Func[]> output{"output", Halide::type_of<uint8_t>(), 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<std::string> url_list;
while(std::getline(urls_stream, url, ';'))
{
url_list.push_back(url);
}


Halide::Buffer<uint8_t> 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<ExternFuncArgument> params = {instance_id++, cast<int32_t>(index), cast<int32_t>(fps), cast<int32_t>(width), cast<int32_t>(height), url_buf};
Func camera(static_cast<std::string>(gc_prefix) + "camera");
camera.define_extern("ion_bb_image_io_camera", params, Halide::type_of<uint8_t>(), 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<float>(camera_(2 * x, y));
Expr uv = cast<float>(camera_(select((x & 1) == 0, 2 * x + 1, 2 * x - 1), y));
Expr vv = cast<float>(camera_(select((x & 1) == 0, 2 * x + 3, 2 * x + 1), y));

Expr f128 = cast<float>(128);
Expr r = saturating_cast<uint8_t>(yv + cast<float>(1.403f) * (vv - f128));
Expr g = saturating_cast<uint8_t>(yv - cast<float>(0.344f) * (uv - f128) - (cast<float>(0.714f) * (vv - f128)));
Expr b = saturating_cast<uint8_t>(yv + cast<float>(1.773f) * (uv - f128));
Halide::Buffer<uint8_t> url_buf(url_str.size() + 1);
url_buf.fill(0);
std::memcpy(url_buf.data(), url_str.c_str(), url_str.size());

std::vector<ExternFuncArgument> params = {instance_id++, cast<int32_t>(index), cast<int32_t>(fps), cast<int32_t>(width), cast<int32_t>(height), url_buf};
Func camera(static_cast<std::string>(gc_prefix) + "camera");
camera.define_extern("ion_bb_image_io_camera", params, Halide::type_of<uint8_t>(), 2);
camera.compute_root();

Func f(static_cast<std::string>(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<float>(camera_(2 * x, y));
Expr uv = cast<float>(camera_(select((x & 1) == 0, 2 * x + 1, 2 * x - 1), y));
Expr vv = cast<float>(camera_(select((x & 1) == 0, 2 * x + 3, 2 * x + 1), y));

Expr f128 = cast<float>(128);
Expr r = saturating_cast<uint8_t>(yv + cast<float>(1.403f) * (vv - f128));
Expr g = saturating_cast<uint8_t>(yv - cast<float>(0.344f) * (uv - f128) - (cast<float>(0.714f) * (vv - f128)));
Expr b = saturating_cast<uint8_t>(yv + cast<float>(1.773f) * (uv - f128));


Func f(static_cast<std::string>(gc_prefix) + "output" + std::to_string(i));
f(x, y, c) = mux(c, {r, g, b});

output[i](_) = f(_);
}

}
};


Expand Down

0 comments on commit 554ed8b

Please sign in to comment.