From b554137a6f12206b75506c09c1f68fccc568fc8a Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Thu, 16 Apr 2020 10:56:05 +0200 Subject: [PATCH 1/4] WIP: JPEG still image encoding --- shared/depthai_constants.hpp | 4 +++- shared/xlink/xlink_wrapper.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/depthai_constants.hpp b/shared/depthai_constants.hpp index b6ab3dc88..9ebd51774 100644 --- a/shared/depthai_constants.hpp +++ b/shared/depthai_constants.hpp @@ -31,5 +31,7 @@ std::unordered_map c_streams_myriad_to_pc = {"metaout", StreamInfo("metaout", 2*2816)}, // 1408 {"previewout", StreamInfo("previewout", 1920256)}, - {"meta_d2h", StreamInfo("meta_d2h", 1024*1024)} + {"meta_d2h", StreamInfo("meta_d2h", 1024*1024)}, + {"jpegout", StreamInfo("jpegout", 1024*1024)} + }; diff --git a/shared/xlink/xlink_wrapper.cpp b/shared/xlink/xlink_wrapper.cpp index 03b3820c3..6dfbfbb76 100644 --- a/shared/xlink/xlink_wrapper.cpp +++ b/shared/xlink/xlink_wrapper.cpp @@ -535,7 +535,7 @@ bool XLinkWrapper::writeToStream( } else { -#if defined(__PC__) || 1 // Set to 0 if too verbose on device... +#if defined(__PC__) || 0 // Set to 0 if too verbose on device... printf("!!! XLink write successful: %s (%d)\n", stream.name, int(write_data_size)); #endif From 4bd4cb88e425f965e74e06c84fa91506af6619d7 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Mon, 20 Apr 2020 18:27:15 +0200 Subject: [PATCH 2/4] JPEG request command --- host/core/host_capture_command.cpp | 18 ++++++++++++++++++ host/core/host_capture_command.hpp | 20 ++++++++++++++++++++ host/py_module/CMakeLists.txt | 1 + host/py_module/py_bindings.cpp | 23 ++++++++++++++++++++++- shared/depthai_constants.hpp | 3 ++- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 host/core/host_capture_command.cpp create mode 100644 host/core/host_capture_command.hpp diff --git a/host/core/host_capture_command.cpp b/host/core/host_capture_command.cpp new file mode 100644 index 000000000..23cc06f77 --- /dev/null +++ b/host/core/host_capture_command.cpp @@ -0,0 +1,18 @@ +#include "host_capture_command.hpp" + +HostCaptureCommand::HostCaptureCommand(const StreamInfo& streamToSendCommand) : stream(streamToSendCommand){ + +} + +void HostCaptureCommand::capture() +{ + command = 1; + + StreamData captureCommand; + captureCommand.packet_number = 0; + captureCommand.data = &command; + captureCommand.size = 4; + + notifyObservers(stream, captureCommand); +} + diff --git a/host/core/host_capture_command.hpp b/host/core/host_capture_command.hpp new file mode 100644 index 000000000..b3ff9ff21 --- /dev/null +++ b/host/core/host_capture_command.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "stream/stream_info.hpp" +#include "general/data_subject.hpp" +#include "stream/stream_data.hpp" + +class HostCaptureCommand + : public DataSubject +{ +public: + HostCaptureCommand(const StreamInfo& streamToSendCommand); + void capture(); + +private: + StreamInfo stream; + + uint32_t command; + + +}; diff --git a/host/py_module/CMakeLists.txt b/host/py_module/CMakeLists.txt index 96566a487..e8d338e2b 100644 --- a/host/py_module/CMakeLists.txt +++ b/host/py_module/CMakeLists.txt @@ -55,6 +55,7 @@ pybind11_add_module( ../../shared/stream/stream_info.cpp ../../shared/xlink/xlink_wrapper.cpp ../../shared/disparity_luts.cpp + ../core/host_capture_command.cpp ${XLINK_SOURCES} ) diff --git a/host/py_module/py_bindings.cpp b/host/py_module/py_bindings.cpp index 7c6b28da5..3a42fb429 100644 --- a/host/py_module/py_bindings.cpp +++ b/host/py_module/py_bindings.cpp @@ -30,6 +30,7 @@ #include "../../shared/version.hpp" #include "../../shared/xlink/xlink_wrapper.hpp" #include "../core/host_json_helper.hpp" +#include "host_capture_command.hpp" namespace py = pybind11; @@ -142,7 +143,7 @@ json g_config_d2h; std::unique_ptr g_disparity_post_proc; std::unique_ptr g_device_support_listener; - +std::unique_ptr g_host_caputure_command; bool init_device( @@ -248,6 +249,7 @@ bool deinit_device() g_xlink = nullptr; g_disparity_post_proc = nullptr; g_device_support_listener = nullptr; + g_host_caputure_command = nullptr; return true; } @@ -269,6 +271,12 @@ std::vector get_available_steams() return result; } +void request_jpeg(){ + if(g_host_caputure_command != nullptr){ + g_host_caputure_command->capture(); + } +} + std::shared_ptr create_pipeline( const std::string &config_json_str @@ -422,6 +430,11 @@ std::shared_ptr create_pipeline( break; } + // host -> "host_capture" -> device + auto stream = g_streams_pc_to_myriad.at("host_capture"); + g_host_caputure_command = std::unique_ptr(new HostCaptureCommand((stream))); + g_xlink->observe(*g_host_caputure_command, stream); + // read & pass blob file if (config.ai.blob_file.empty()) @@ -700,6 +713,14 @@ PYBIND11_MODULE(depthai, m) py::arg("config") = py::dict() ); + + // depthai.request_jpeg() + m.def( + "request_jpeg", + &request_jpeg, + "Function to request a still JPEG encoded image ('jpeg' stream must be enabled)" + ); + // for PACKET in data_packets: py::class_>(m, "DataPacket") diff --git a/shared/depthai_constants.hpp b/shared/depthai_constants.hpp index 9ebd51774..40e9d9afe 100644 --- a/shared/depthai_constants.hpp +++ b/shared/depthai_constants.hpp @@ -13,7 +13,8 @@ // TODO: remove next constant std::unordered_map g_streams_pc_to_myriad = { - {"config_h2d", StreamInfo("config_h2d", 1000)} + {"config_h2d", StreamInfo("config_h2d", 1000)}, + {"host_capture", StreamInfo("host_capture", 4)} }; From 43b4f41cbea2d2cabc7a2b1ea3cd668a551ed3cc Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Tue, 21 Apr 2020 12:26:34 +0200 Subject: [PATCH 3/4] Added video stream --- shared/depthai_constants.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared/depthai_constants.hpp b/shared/depthai_constants.hpp index 40e9d9afe..b254774ba 100644 --- a/shared/depthai_constants.hpp +++ b/shared/depthai_constants.hpp @@ -33,6 +33,7 @@ std::unordered_map c_streams_myriad_to_pc = {"previewout", StreamInfo("previewout", 1920256)}, {"meta_d2h", StreamInfo("meta_d2h", 1024*1024)}, - {"jpegout", StreamInfo("jpegout", 1024*1024)} + {"jpegout", StreamInfo("jpegout", 1*1024*1024)}, + {"video", StreamInfo("video", 2*1024*1024)} }; From 9a739f480431b5fee669743c3f395a13f830eddc Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 22 Apr 2020 12:10:02 +0200 Subject: [PATCH 4/4] Increased watchdog timeout --- host/py_module/.gitignore | 1 + host/py_module/py_bindings.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/host/py_module/.gitignore b/host/py_module/.gitignore index 567609b12..3243616db 100644 --- a/host/py_module/.gitignore +++ b/host/py_module/.gitignore @@ -1 +1,2 @@ build/ +build_armv7/ diff --git a/host/py_module/py_bindings.cpp b/host/py_module/py_bindings.cpp index 300b4b4ee..77dcdd1cf 100644 --- a/host/py_module/py_bindings.cpp +++ b/host/py_module/py_bindings.cpp @@ -83,7 +83,7 @@ void wdog_thread(int& wd_timeout_ms) } static std::thread wd_thread; -static int wd_timeout_ms = 1000; +static int wd_timeout_ms = 3000; int wdog_start(void) { static int once = 1;