add update_vocabulary dora input for runtime label changes
The open_vocab engine now accepts an update_vocabulary input event carrying a UTF-8 comma-separated label string. Labels are re-encoded immediately via the CLIP text encoder; the next tick uses the new vocabulary. ZedNative ignores the input via a no-op base class method.
This commit is contained in:
@@ -20,6 +20,7 @@ public:
|
||||
|
||||
virtual void enable(sl::Camera& camera) = 0;
|
||||
virtual void detect(sl::Camera& camera) = 0;
|
||||
virtual void set_labels(const std::string& /*labels*/) {}
|
||||
virtual const std::vector<DetectedObject>& objects() const = 0;
|
||||
virtual std::string label_names() const = 0;
|
||||
};
|
||||
|
||||
@@ -576,6 +576,11 @@ void OpenVocab::detect(const cv::Mat& image_bgr) {
|
||||
}
|
||||
}
|
||||
|
||||
void OpenVocab::set_labels(const std::string& labels) {
|
||||
config_.labels = labels;
|
||||
encode_labels(labels);
|
||||
}
|
||||
|
||||
const std::vector<DetectedObject>& OpenVocab::objects() const {
|
||||
return detected_;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ public:
|
||||
|
||||
void enable(sl::Camera& camera) override;
|
||||
void detect(sl::Camera& camera) override;
|
||||
void detect(const cv::Mat& image_bgr); // image-only; no 3D fusion
|
||||
void detect(const cv::Mat& image_bgr); // image-only; no 3D fusion
|
||||
void set_labels(const std::string& labels) override;
|
||||
const std::vector<DetectedObject>& objects() const override;
|
||||
std::string label_names() const override;
|
||||
|
||||
|
||||
+12
-1
@@ -95,7 +95,18 @@ int main() {
|
||||
}
|
||||
|
||||
auto input = event_as_input(std::move(event));
|
||||
(void)input;
|
||||
std::string input_id = std::string(input.id);
|
||||
|
||||
if (input_id == "update_vocabulary") {
|
||||
if (!input.data.empty()) {
|
||||
std::string labels(
|
||||
reinterpret_cast<const char*>(input.data.data()),
|
||||
input.data.size());
|
||||
detector->set_labels(labels);
|
||||
std::cout << "Vocabulary updated: " << labels << std::endl;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!camera.grab()) {
|
||||
std::cerr << "Grab failed; attempting to reconnect..." << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user