added a test mode
This commit is contained in:
parent
ceb28187ca
commit
1dd31f984b
1 changed files with 22 additions and 5 deletions
27
src/main.zig
27
src/main.zig
|
@ -25,11 +25,12 @@ var exit_loop: bool = false;
|
||||||
const CliArgs = struct {
|
const CliArgs = struct {
|
||||||
hef_file_path: []const u8,
|
hef_file_path: []const u8,
|
||||||
gst_source_path: []const u8,
|
gst_source_path: []const u8,
|
||||||
|
test_mode: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|
||||||
var args: CliArgs = .{ .hef_file_path = undefined, .gst_source_path = undefined };
|
var args: CliArgs = .{ .hef_file_path = undefined, .gst_source_path = undefined, .test_mode = false };
|
||||||
|
|
||||||
std.posix.sigaction(std.posix.SIG.INT, &std.posix.Sigaction {
|
std.posix.sigaction(std.posix.SIG.INT, &std.posix.Sigaction {
|
||||||
.handler = .{
|
.handler = .{
|
||||||
|
@ -48,8 +49,6 @@ pub fn main() !void {
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("Program started\n", .{});
|
std.debug.print("Program started\n", .{});
|
||||||
// This allows me to utilize the same command line args and gstreamer
|
|
||||||
gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr));
|
|
||||||
|
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
@ -65,6 +64,10 @@ pub fn main() !void {
|
||||||
|
|
||||||
|
|
||||||
while (arg_source.next()) |cur_arg| {
|
while (arg_source.next()) |cur_arg| {
|
||||||
|
if (std.mem.eql(u8, cur_arg, "--help") or std.mem.eql(u8, cur_arg, "-h")) {
|
||||||
|
std.debug.print("Expected usage: \n`--hef <path to the hef file> --gst-source <path to shared gstreamer memory space>`\n`--test-mode`\n", .{});
|
||||||
|
std.process.exit(0);
|
||||||
|
}
|
||||||
if (std.mem.eql(u8, cur_arg, "--hef")) {
|
if (std.mem.eql(u8, cur_arg, "--hef")) {
|
||||||
|
|
||||||
if (arg_source.next()) |x| {
|
if (arg_source.next()) |x| {
|
||||||
|
@ -82,6 +85,18 @@ pub fn main() !void {
|
||||||
std.process.fatal("--gst-source flag specified, but no value provided!\n", .{});
|
std.process.fatal("--gst-source flag specified, but no value provided!\n", .{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (std.mem.eql(u8, cur_arg, "--test-mode")) {
|
||||||
|
args.test_mode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.test_mode) {
|
||||||
|
std.debug.print("Entering test mode!\n", .{});
|
||||||
|
while (!exit_loop) {
|
||||||
|
std.time.sleep(1 * 1000 * 1000); // sleep for 1 second
|
||||||
|
std.debug.print("Person found! Confidence: 0.8, 0.4:0.2, 0.6:0.8\n", .{}); // x:y, to x:y
|
||||||
|
}
|
||||||
|
std.process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_set) {
|
if (!gst_set) {
|
||||||
|
@ -91,6 +106,9 @@ pub fn main() !void {
|
||||||
std.process.fatal("Invalid usage. --hef value is required\n", .{});
|
std.process.fatal("Invalid usage. --hef value is required\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This allows me to utilize the same command line args and gstreamer
|
||||||
|
gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr));
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("Using hardcoded hef file path :P\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| {
|
||||||
|
@ -268,8 +286,7 @@ pub fn main() !void {
|
||||||
if (status == hlo.HAILO_SUCCESS) {
|
if (status == hlo.HAILO_SUCCESS) {
|
||||||
for (0..(output_data.len / 5)) |x| {
|
for (0..(output_data.len / 5)) |x| {
|
||||||
if (output_data[x] == 1.0) {
|
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("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] });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue