Compare commits
2 commits
d5f78f8031
...
ceb28187ca
Author | SHA1 | Date | |
---|---|---|---|
|
ceb28187ca | ||
|
ea58055ab1 |
1 changed files with 157 additions and 113 deletions
72
src/main.zig
72
src/main.zig
|
@ -22,9 +22,15 @@ const max_edge_layers = 32;
|
||||||
|
|
||||||
var exit_loop: bool = false;
|
var exit_loop: bool = false;
|
||||||
|
|
||||||
|
const CliArgs = struct {
|
||||||
|
hef_file_path: []const u8,
|
||||||
|
gst_source_path: []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|
||||||
|
var args: CliArgs = .{ .hef_file_path = undefined, .gst_source_path = undefined };
|
||||||
|
|
||||||
std.posix.sigaction(std.posix.SIG.INT, &std.posix.Sigaction {
|
std.posix.sigaction(std.posix.SIG.INT, &std.posix.Sigaction {
|
||||||
.handler = .{
|
.handler = .{
|
||||||
.handler = struct {
|
.handler = struct {
|
||||||
|
@ -50,8 +56,45 @@ pub fn main() !void {
|
||||||
|
|
||||||
const alloc = arena.allocator();
|
const alloc = arena.allocator();
|
||||||
|
|
||||||
|
|
||||||
|
var arg_source = try std.process.argsWithAllocator(alloc);
|
||||||
|
_ = arg_source.skip();
|
||||||
|
|
||||||
|
var hef_set = false;
|
||||||
|
var gst_set = false;
|
||||||
|
|
||||||
|
|
||||||
|
while (arg_source.next()) |cur_arg| {
|
||||||
|
if (std.mem.eql(u8, cur_arg, "--hef")) {
|
||||||
|
|
||||||
|
if (arg_source.next()) |x| {
|
||||||
|
args.hef_file_path = x;
|
||||||
|
hef_set = true;
|
||||||
|
} else {
|
||||||
|
std.process.fatal("--hef flag specified, but no value provided!\n", .{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (std.mem.eql(u8, cur_arg, "--gst-source")) {
|
||||||
|
if (arg_source.next()) |x| {
|
||||||
|
args.gst_source_path = x;
|
||||||
|
gst_set = true;
|
||||||
|
} else {
|
||||||
|
std.process.fatal("--gst-source flag specified, but no value provided!\n", .{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_set) {
|
||||||
|
std.process.fatal("Invalid usage. --gst-source value is required\n", .{});
|
||||||
|
}
|
||||||
|
if (!hef_set) {
|
||||||
|
std.process.fatal("Invalid usage. --hef value is required\n", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std.debug.print("Using hardcoded hef file path :P\n", .{});
|
||||||
std.fs.cwd().access(hef_file, .{ }) catch |e| {
|
std.fs.cwd().access(hef_file, .{ }) catch |e| {
|
||||||
std.debug.panic("Could not open hef file! '{any}'", .{ e });
|
std.process.fatal("Could not open hef file! '{any}'", .{ e });
|
||||||
};
|
};
|
||||||
|
|
||||||
var status: hlo.hailo_status = undefined;
|
var status: hlo.hailo_status = undefined;
|
||||||
|
@ -119,6 +162,7 @@ pub fn main() !void {
|
||||||
std.debug.print("HailoRT init completed\nGstreamer Init starting", .{});
|
std.debug.print("HailoRT init completed\nGstreamer Init starting", .{});
|
||||||
|
|
||||||
|
|
||||||
|
_ = gst_block: {
|
||||||
std.debug.print("Gstreamer Initialized\n", .{});
|
std.debug.print("Gstreamer Initialized\n", .{});
|
||||||
|
|
||||||
const source: *gst.Element = gst.ElementFactory.make("v4l2src", "source") orelse unreachable;
|
const source: *gst.Element = gst.ElementFactory.make("v4l2src", "source") orelse unreachable;
|
||||||
|
@ -158,7 +202,8 @@ pub fn main() !void {
|
||||||
// the failure return code is -1 I believe
|
// the failure return code is -1 I believe
|
||||||
if (gst.Element.linkMany(source, scale, format, sink_el) < 0) {
|
if (gst.Element.linkMany(source, scale, format, sink_el) < 0) {
|
||||||
pipeline.unref();
|
pipeline.unref();
|
||||||
std.debug.panic("Elements could not be linked\n", .{});
|
std.debug.print("Elements could not be linked! Aborting!\n", .{});
|
||||||
|
break :gst_block;
|
||||||
}
|
}
|
||||||
std.debug.print("Elements linked\n", .{});
|
std.debug.print("Elements linked\n", .{});
|
||||||
|
|
||||||
|
@ -169,13 +214,13 @@ pub fn main() !void {
|
||||||
const ret = pipeline.as(gst.Element).setState(gst.State.playing);
|
const ret = pipeline.as(gst.Element).setState(gst.State.playing);
|
||||||
if (ret == gst.StateChangeReturn.failure) {
|
if (ret == gst.StateChangeReturn.failure) {
|
||||||
pipeline.unref();
|
pipeline.unref();
|
||||||
std.debug.panic("Could not start pipeline", .{});
|
std.debug.print("Could not start pipeline! Aborting\n", .{});
|
||||||
|
break :gst_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bus: *gst.Bus = pipeline.getBus();
|
const bus: *gst.Bus = pipeline.getBus();
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("Getting vstream info\n", .{});
|
|
||||||
var stream_info: hlo.hailo_vstream_info_t = undefined;
|
var stream_info: hlo.hailo_vstream_info_t = undefined;
|
||||||
status = hlo.hailo_get_input_vstream_info(input_vstreams[0], &stream_info);
|
status = hlo.hailo_get_input_vstream_info(input_vstreams[0], &stream_info);
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
|
@ -183,7 +228,6 @@ pub fn main() !void {
|
||||||
var output_info: hlo.hailo_vstream_info_t = undefined;
|
var output_info: hlo.hailo_vstream_info_t = undefined;
|
||||||
status = hlo.hailo_get_output_vstream_info(output_vstreams[0], &output_info);
|
status = hlo.hailo_get_output_vstream_info(output_vstreams[0], &output_info);
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
std.debug.print("\nOutput info: {any}\n\n", .{ output_info });
|
|
||||||
|
|
||||||
|
|
||||||
var input_frame_size: usize = 0;
|
var input_frame_size: usize = 0;
|
||||||
|
@ -198,11 +242,13 @@ pub fn main() !void {
|
||||||
var output_frame_size: usize = 0;
|
var output_frame_size: usize = 0;
|
||||||
status = hlo.hailo_get_output_vstream_frame_size(output_vstreams[0], &output_frame_size);
|
status = hlo.hailo_get_output_vstream_frame_size(output_vstreams[0], &output_frame_size);
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
std.debug.print("output frame size is: {d}\n", .{ output_frame_size });
|
|
||||||
|
|
||||||
const output_frame_count = output_frame_size / @sizeOf(f32);
|
const output_frame_count = output_frame_size / @sizeOf(f32);
|
||||||
const output_data: [:0]f32 = try alloc.allocSentinel(f32, output_frame_count, 0);
|
const output_data: [:0]f32 = try alloc.allocSentinel(f32, output_frame_count, 0);
|
||||||
|
|
||||||
|
defer pipeline.unref();
|
||||||
|
defer _ = pipeline.as(gst.Element).setState(gst.State.null);
|
||||||
|
defer bus.unref();
|
||||||
|
|
||||||
var run_count: u8 = 0;
|
var run_count: u8 = 0;
|
||||||
|
|
||||||
|
@ -220,10 +266,12 @@ pub fn main() !void {
|
||||||
|
|
||||||
status = hlo.hailo_vstream_read_raw_buffer(output_vstreams[0], output_data.ptr, output_frame_size);
|
status = hlo.hailo_vstream_read_raw_buffer(output_vstreams[0], output_data.ptr, output_frame_size);
|
||||||
if (status == hlo.HAILO_SUCCESS) {
|
if (status == hlo.HAILO_SUCCESS) {
|
||||||
for (0..50) |x| {
|
for (0..(output_data.len / 5)) |x| {
|
||||||
std.debug.print(" {d} ", .{output_data[x]});
|
if (output_data[x] == 1.0) {
|
||||||
|
|
||||||
|
std.debug.print("Person found! Confidence: {d}, {d}:{d}, {d}, {d}\n", .{ output_data[x + 1], output_data[x + 2], output_data[x + 3], output_data[x + 4], output_data[x + 5] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std.debug.print("\n", .{});
|
|
||||||
|
|
||||||
run_count += 1;
|
run_count += 1;
|
||||||
if (run_count > 20) {
|
if (run_count > 20) {
|
||||||
|
@ -237,11 +285,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
std.debug.print("Staring shutdown\n", .{ });
|
std.debug.print("Staring shutdown\n", .{ });
|
||||||
|
|
||||||
|
};
|
||||||
bus.unref();
|
|
||||||
_ = pipeline.as(gst.Element).setState(gst.State.null);
|
|
||||||
pipeline.unref();
|
|
||||||
// const bus: *gst.Bus = pipeline.getBus();
|
|
||||||
|
|
||||||
|
|
||||||
_ = hlo.hailo_release_output_vstreams(&output_vstreams, output_vstream_size);
|
_ = hlo.hailo_release_output_vstreams(&output_vstreams, output_vstream_size);
|
||||||
|
|
Loading…
Reference in a new issue