OrbbecSDK 2.6.3
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
Filter.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
9#pragma once
10
11#include "Types.hpp"
12#include "Error.hpp"
13#include "Frame.hpp"
15#include "libobsensor/h/Frame.h"
16#include <functional>
17#include <memory>
18#include <map>
19#include <string>
20#include <iostream>
21#include <vector>
22#include <typeinfo>
23#include <typeindex>
24#include <unordered_map>
25#include <cstring>
26
27namespace ob {
28
32typedef std::function<void(std::shared_ptr<Frame>)> FilterCallback;
33
37template <typename T> struct RangeTraits {
38 using valueType = void;
39};
40
41template <> struct RangeTraits<OBUint8PropertyRange> {
42 using valueType = uint8_t;
43};
44
46 using valueType = uint16_t;
47};
48
49template <> struct RangeTraits<OBIntPropertyRange> {
50 using valueType = uint32_t;
51};
52
53template <> struct RangeTraits<OBFloatPropertyRange> {
54 using valueType = float;
55};
56
60template <typename T> T getPropertyRange(const OBFilterConfigSchemaItem &item, const double cur) {
61 // If T type is illegal, T will be void
62 using valueType = typename RangeTraits<T>::valueType;
63 T range{};
64 // Compilate error will be reported here if T is void
65 range.cur = static_cast<valueType>(cur);
66 range.def = static_cast<valueType>(item.def);
67 range.max = static_cast<valueType>(item.max);
68 range.min = static_cast<valueType>(item.min);
69 range.step = static_cast<valueType>(item.step);
70 return range;
71}
72
76class Filter : public std::enable_shared_from_this<Filter> {
77protected:
78 ob_filter *impl_ = nullptr;
79 std::string name_;
81 std::vector<OBFilterConfigSchemaItem> configSchemaVec_;
82
83protected:
87 Filter() = default;
88
89 virtual void init(ob_filter *impl) {
90 impl_ = impl;
91 ob_error *error = nullptr;
93 Error::handle(&error);
94
95 auto configSchemaList = ob_filter_get_config_schema_list(impl_, &error);
96 Error::handle(&error);
97
98 auto count = ob_filter_config_schema_list_get_count(configSchemaList, &error);
99 Error::handle(&error);
100
101 for(uint32_t i = 0; i < count; i++) {
102 auto item = ob_filter_config_schema_list_get_item(configSchemaList, i, &error);
103 Error::handle(&error);
104 configSchemaVec_.emplace_back(item);
105 }
106
107 ob_delete_filter_config_schema_list(configSchemaList, &error);
108 Error::handle(&error);
109 }
110
111public:
112 explicit Filter(ob_filter *impl) {
113 init(impl);
114 }
115
116 virtual ~Filter() noexcept {
117 if(impl_ != nullptr) {
118 ob_error *error = nullptr;
119 ob_delete_filter(impl_, &error);
120 Error::handle(&error, false);
121 }
122 }
123
130 return impl_;
131 }
132
138 virtual const std::string &getName() const {
139 return name_;
140 }
141
146 virtual void reset() const {
147 ob_error *error = nullptr;
148 ob_filter_reset(impl_, &error);
149 Error::handle(&error);
150 }
151
155 virtual void enable(bool enable) const {
156 ob_error *error = nullptr;
157 ob_filter_enable(impl_, enable, &error);
158 Error::handle(&error);
159 }
160
164 virtual bool isEnabled() const {
165 ob_error *error = nullptr;
166 bool enable = ob_filter_is_enabled(impl_, &error);
167 Error::handle(&error);
168 return enable;
169 }
170
178 virtual std::shared_ptr<Frame> process(std::shared_ptr<const Frame> frame) const {
179 ob_error *error = nullptr;
180 auto result = ob_filter_process(impl_, frame->getImpl(), &error);
181 Error::handle(&error);
182 if(!result) {
183 return nullptr;
184 }
185 return std::make_shared<Frame>(result);
186 }
187
193 virtual void pushFrame(std::shared_ptr<Frame> frame) const {
194 ob_error *error = nullptr;
195 ob_filter_push_frame(impl_, frame->getImpl(), &error);
196 Error::handle(&error);
197 }
198
204 virtual void setCallBack(FilterCallback callback) {
205 callback_ = callback;
206 ob_error *error = nullptr;
207 ob_filter_set_callback(impl_, &Filter::filterCallback, this, &error);
208 Error::handle(&error);
209 }
210
219 virtual std::string getConfigSchema() const {
220 ob_error *error = nullptr;
221 auto schema = ob_filter_get_config_schema(impl_, &error);
222 Error::handle(&error);
223 return schema;
224 }
225
232 virtual std::vector<OBFilterConfigSchemaItem> getConfigSchemaVec() const {
233 return configSchemaVec_;
234 }
235
245 virtual void setConfigValue(const std::string &configName, double value) const {
246 ob_error *error = nullptr;
247 ob_filter_set_config_value(impl_, configName.c_str(), value, &error);
248 Error::handle(&error);
249 }
250
261 virtual double getConfigValue(const std::string &configName) const {
262 ob_error *error = nullptr;
263 double value = ob_filter_get_config_value(impl_, configName.c_str(), &error);
264 Error::handle(&error);
265 return value;
266 }
267
268private:
269 static void filterCallback(ob_frame *frame, void *userData) {
270 auto filter = static_cast<Filter *>(userData);
271 filter->callback_(std::make_shared<Frame>(frame));
272 }
273
274public:
275 // The following interfaces are deprecated and are retained here for compatibility purposes.
276 virtual const char *type() {
277 return getName().c_str();
278 }
279
287 template <typename T> bool is();
288
289 template <typename T> std::shared_ptr<T> as() {
290 if(!is<T>()) {
291 throw std::runtime_error("unsupported operation, object's type is not require type");
292 }
293
294 return std::static_pointer_cast<T>(shared_from_this());
295 }
296};
297
302public:
306 static std::shared_ptr<Filter> createFilter(const std::string &name) {
307 ob_error *error = nullptr;
308 auto impl = ob_create_filter(name.c_str(), &error);
309 Error::handle(&error);
310 return std::make_shared<Filter>(impl);
311 }
312
320 static std::shared_ptr<Filter> createPrivateFilter(const std::string &name, const std::string &activationKey) {
321 ob_error *error = nullptr;
322 auto impl = ob_create_private_filter(name.c_str(), activationKey.c_str(), &error);
323 Error::handle(&error);
324 return std::make_shared<Filter>(impl);
325 }
326
335 static std::string getFilterVendorSpecificCode(const std::string &name) {
336 ob_error *error = nullptr;
337 auto code = ob_filter_get_vendor_specific_code(name.c_str(), &error);
338 Error::handle(&error);
339 return code;
340 }
341};
342
346class PointCloudFilter : public Filter {
347public:
349 ob_error *error = nullptr;
350 auto impl = ob_create_filter("PointCloudFilter", &error);
351 Error::handle(&error);
352 init(impl);
353 }
354
355 virtual ~PointCloudFilter() noexcept override = default;
356
363 setConfigValue("pointFormat", static_cast<double>(format));
364 }
365
374 void setCoordinateDataScaled(float factor) {
375 setConfigValue("coordinateDataScale", factor);
376 }
377
386 void setColorDataNormalization(bool state) {
387 setConfigValue("colorDataNormalization", state);
388 }
389
396 setConfigValue("coordinateSystemType", static_cast<double>(type));
397 }
398
405 void setDecimationFactor(int value) {
406 setConfigValue("decimate", value);
407 }
408
413 OBIntPropertyRange scaleRange{};
414 if(configSchemaVec_.size() != 0) {
415 const auto &item = configSchemaVec_[5];
416 scaleRange = getPropertyRange<OBIntPropertyRange>(item, getConfigValue("decimate"));
417 }
418 return scaleRange;
419 }
420
421public:
422 // The following interfaces are deprecated and are retained here for compatibility purposes.
423 void setPositionDataScaled(float scale) {
425 }
426
427 // The following interfaces are deprecated and are retained here for compatibility purposes.
428 void setFrameAlignState(bool state) {
429 (void)state; // to complie
430 }
431 // The following interfaces are deprecated and are retained here for compatibility purposes.
433 (void)param;
434 }
435};
436
440class Align : public Filter {
441public:
442 Align(OBStreamType alignToStreamType) {
443 ob_error *error = nullptr;
444 auto impl = ob_create_filter("Align", &error);
445 Error::handle(&error);
446 init(impl);
447
448 setConfigValue("AlignType", static_cast<double>(alignToStreamType));
449 }
450
451 virtual ~Align() noexcept override = default;
452
454 return static_cast<OBStreamType>(static_cast<int>(getConfigValue("AlignType")));
455 }
456
467 void setMatchTargetResolution(bool state) {
468 setConfigValue("MatchTargetRes", state);
469 }
470
477 void setAlignToStreamProfile(std::shared_ptr<const StreamProfile> profile) {
478 ob_error *error = nullptr;
479 ob_align_filter_set_align_to_stream_profile(impl_, profile->getImpl(), &error);
480 Error::handle(&error);
481 }
482};
483
488public:
490 ob_error *error = nullptr;
491 auto impl = ob_create_filter("FormatConverter", &error);
492 Error::handle(&error);
493 init(impl);
494 }
495
496 virtual ~FormatConvertFilter() noexcept override = default;
497
504 setConfigValue("convertType", static_cast<double>(type));
505 }
506};
507
513class HdrMerge : public Filter {
514public:
516 ob_error *error = nullptr;
517 auto impl = ob_create_filter("HDRMerge", &error);
518 Error::handle(&error);
519 init(impl);
520 }
521
522 virtual ~HdrMerge() noexcept override = default;
523};
524
528class SequenceIdFilter : public Filter {
529private:
530 std::map<float, std::string> sequenceIdList_{ { 0.f, "all" }, { 1.f, "1" } };
531 OBSequenceIdItem *outputSequenceIdList_ = nullptr;
532
533 void initSequenceIdList() {
534 outputSequenceIdList_ = new OBSequenceIdItem[sequenceIdList_.size()];
535
536 int i = 0;
537 for(const auto &pair: sequenceIdList_) {
538 outputSequenceIdList_[i].sequenceSelectId = static_cast<int>(pair.first);
539 strncpy(outputSequenceIdList_[i].name, pair.second.c_str(), sizeof(outputSequenceIdList_[i].name) - 1);
540 outputSequenceIdList_[i].name[sizeof(outputSequenceIdList_[i].name) - 1] = '\0';
541 ++i;
542 }
543 }
544
545public:
547 ob_error *error = nullptr;
548 auto impl = ob_create_filter("SequenceIdFilter", &error);
549 Error::handle(&error);
550 init(impl);
551 initSequenceIdList();
552 }
553
554 virtual ~SequenceIdFilter() noexcept override {
555 if(outputSequenceIdList_) {
556 delete[] outputSequenceIdList_;
557 outputSequenceIdList_ = nullptr;
558 }
559 }
560
566 void selectSequenceId(int sequence_id) {
567 setConfigValue("sequenceid", static_cast<double>(sequence_id));
568 }
569
576 return static_cast<int>(getConfigValue("sequenceid"));
577 }
578
580 return outputSequenceIdList_;
581 }
582
589 return static_cast<int>(sequenceIdList_.size());
590 }
591};
592
596class DecimationFilter : public Filter {
597public:
599 ob_error *error = nullptr;
600 auto impl = ob_create_filter("DecimationFilter", &error);
601 Error::handle(&error);
602 init(impl);
603 }
604
605 virtual ~DecimationFilter() noexcept override = default;
606
612 void setScaleValue(uint8_t value) {
613 setConfigValue("decimate", static_cast<double>(value));
614 }
615
619 uint8_t getScaleValue() {
620 return static_cast<uint8_t>(getConfigValue("decimate"));
621 }
622
627 OBUint8PropertyRange scaleRange{};
628 if(configSchemaVec_.size() != 0) {
629 const auto &item = configSchemaVec_[0];
630 scaleRange = getPropertyRange<OBUint8PropertyRange>(item, getConfigValue("decimate"));
631 }
632 return scaleRange;
633 }
634};
635
640class ThresholdFilter : public Filter {
641public:
643 ob_error *error = nullptr;
644 auto impl = ob_create_filter("ThresholdFilter", &error);
645 Error::handle(&error);
646 init(impl);
647 }
648
649 virtual ~ThresholdFilter() noexcept override = default;
650
657 OBIntPropertyRange range{};
658 const auto &schemaVec = getConfigSchemaVec();
659 for(const auto &item: schemaVec) {
660 if(strcmp(item.name, "min") == 0) {
662 break;
663 }
664 }
665 return range;
666 }
667
674 OBIntPropertyRange range{};
675 const auto &schemaVec = getConfigSchemaVec();
676 for(const auto &item: schemaVec) {
677 if(strcmp(item.name, "max") == 0) {
679 break;
680 }
681 }
682 return range;
683 }
684
688 bool setValueRange(uint16_t min, uint16_t max) {
689 if(min >= max) {
690 return false;
691 }
692 setConfigValue("min", min);
693 setConfigValue("max", max);
694 return true;
695 }
696};
697
704public:
705 SpatialAdvancedFilter(const std::string &activationKey = "") {
706 ob_error *error = nullptr;
707 auto impl = ob_create_private_filter("SpatialAdvancedFilter", activationKey.c_str(), &error);
708 Error::handle(&error);
709 init(impl);
710 }
711
712 virtual ~SpatialAdvancedFilter() noexcept override = default;
713
720 OBFloatPropertyRange range{};
721 const auto &schemaVec = getConfigSchemaVec();
722 for(const auto &item: schemaVec) {
723 if(strcmp(item.name, "alpha") == 0) {
725 break;
726 }
727 }
728 return range;
729 }
730
737 OBUint16PropertyRange range{};
738 const auto &schemaVec = getConfigSchemaVec();
739 for(const auto &item: schemaVec) {
740 if(strcmp(item.name, "disp_diff") == 0) {
742 break;
743 }
744 }
745 return range;
746 }
747
754 OBUint16PropertyRange range{};
755 const auto &schemaVec = getConfigSchemaVec();
756 for(const auto &item: schemaVec) {
757 if(strcmp(item.name, "radius") == 0) {
759 break;
760 }
761 }
762 return range;
763 }
764
771 OBIntPropertyRange range{};
772 const auto &schemaVec = getConfigSchemaVec();
773 for(const auto &item: schemaVec) {
774 if(strcmp(item.name, "magnitude") == 0) {
775 range = getPropertyRange<OBIntPropertyRange>(item, getConfigValue("magnitude"));
776 break;
777 }
778 }
779 return range;
780 }
781
789 params.alpha = static_cast<float>(getConfigValue("alpha"));
790 params.disp_diff = static_cast<uint16_t>(getConfigValue("disp_diff"));
791 params.magnitude = static_cast<uint8_t>(getConfigValue("magnitude"));
792 params.radius = static_cast<uint16_t>(getConfigValue("radius"));
793 return params;
794 }
795
802 setConfigValue("alpha", params.alpha);
803 setConfigValue("disp_diff", params.disp_diff);
804 setConfigValue("magnitude", params.magnitude);
805 setConfigValue("radius", params.radius);
806 }
807};
808
813class SpatialFastFilter : public Filter {
814public:
815 SpatialFastFilter(const std::string &activationKey = "") {
816 ob_error *error = nullptr;
817 auto impl = ob_create_private_filter("SpatialFastFilter", activationKey.c_str(), &error);
818 Error::handle(&error);
819 init(impl);
820 }
821
822 virtual ~SpatialFastFilter() noexcept override = default;
823
830 OBIntPropertyRange range{};
831 const auto &schemaVec = getConfigSchemaVec();
832 for(const auto &item: schemaVec) {
833 if(strcmp(item.name, "radius") == 0) {
835 break;
836 }
837 }
838 return range;
839 }
840
848 params.radius = static_cast<uint8_t>(getConfigValue("radius"));
849 return params;
850 }
851
858 setConfigValue("radius", params.radius);
859 }
860};
861
867public:
868 SpatialModerateFilter(const std::string &activationKey = "") {
869 ob_error *error = nullptr;
870 auto impl = ob_create_private_filter("SpatialModerateFilter", activationKey.c_str(), &error);
871 Error::handle(&error);
872 init(impl);
873 }
874
875 virtual ~SpatialModerateFilter() noexcept override = default;
876
883 OBIntPropertyRange range{};
884 const auto &schemaVec = getConfigSchemaVec();
885 for(const auto &item: schemaVec) {
886 if(strcmp(item.name, "magnitude") == 0) {
887 range = getPropertyRange<OBIntPropertyRange>(item, getConfigValue("magnitude"));
888 break;
889 }
890 }
891 return range;
892 }
893
900 OBIntPropertyRange range{};
901 const auto &schemaVec = getConfigSchemaVec();
902 for(const auto &item: schemaVec) {
903 if(strcmp(item.name, "radius") == 0) {
905 break;
906 }
907 }
908 return range;
909 }
910
917 OBIntPropertyRange range{};
918 const auto &schemaVec = getConfigSchemaVec();
919 for(const auto &item: schemaVec) {
920 if(strcmp(item.name, "disp_diff") == 0) {
921 range = getPropertyRange<OBIntPropertyRange>(item, getConfigValue("disp_diff"));
922 break;
923 }
924 }
925 return range;
926 }
927
935 params.magnitude = static_cast<uint8_t>(getConfigValue("magnitude"));
936 params.radius = static_cast<uint8_t>(getConfigValue("radius"));
937 params.disp_diff = static_cast<uint16_t>(getConfigValue("disp_diff"));
938 return params;
939 }
940
947 setConfigValue("magnitude", params.magnitude);
948 setConfigValue("radius", params.radius);
949 setConfigValue("disp_diff", params.disp_diff);
950 }
951};
952
956class HoleFillingFilter : public Filter {
957public:
958 HoleFillingFilter(const std::string &activationKey = "") {
959 ob_error *error = nullptr;
960 auto impl = ob_create_private_filter("HoleFillingFilter", activationKey.c_str(), &error);
961 Error::handle(&error);
962 init(impl);
963 }
964
965 ~HoleFillingFilter() noexcept override = default;
966
973 setConfigValue("hole_filling_mode", static_cast<double>(mode));
974 }
975
982 return static_cast<OBHoleFillingMode>(static_cast<int>(getConfigValue("hole_filling_mode")));
983 }
984};
985
990public:
991 NoiseRemovalFilter(const std::string &activationKey = "") {
992 ob_error *error = nullptr;
993 auto impl = ob_create_private_filter("NoiseRemovalFilter", activationKey.c_str(), &error);
994 Error::handle(&error);
995 init(impl);
996 }
997
998 ~NoiseRemovalFilter() noexcept override = default;
999
1006 setConfigValue("max_size", static_cast<double>(filterParams.max_size));
1007 setConfigValue("min_diff", static_cast<double>(filterParams.disp_diff));
1008 // todo:set noise remove type
1009 }
1010
1018 param.max_size = static_cast<uint16_t>(getConfigValue("max_size"));
1019 param.disp_diff = static_cast<uint16_t>(getConfigValue("min_diff"));
1020 // todo: type is not set
1021 return param;
1022 }
1023
1029 OBUint16PropertyRange range{};
1030 const auto &schemaVec = getConfigSchemaVec();
1031 for(const auto &item: schemaVec) {
1032 if(strcmp(item.name, "min_diff") == 0) {
1034 break;
1035 }
1036 }
1037 return range;
1038 }
1039
1045 OBUint16PropertyRange range{};
1046 const auto &schemaVec = getConfigSchemaVec();
1047 for(const auto &item: schemaVec) {
1048 if(strcmp(item.name, "max_size") == 0) {
1050 break;
1051 }
1052 }
1053 return range;
1054 }
1055};
1056
1060class TemporalFilter : public Filter {
1061public:
1062 TemporalFilter(const std::string &activationKey = "") {
1063 ob_error *error = nullptr;
1064 auto impl = ob_create_private_filter("TemporalFilter", activationKey.c_str(), &error);
1065 Error::handle(&error);
1066 init(impl);
1067 }
1068
1069 ~TemporalFilter() noexcept override = default;
1070
1077 OBFloatPropertyRange range{};
1078 const auto &schemaVec = getConfigSchemaVec();
1079 for(const auto &item: schemaVec) {
1080 if(strcmp(item.name, "diff_scale") == 0) {
1081 range = getPropertyRange<OBFloatPropertyRange>(item, getConfigValue("diff_scale"));
1082 break;
1083 }
1084 }
1085 return range;
1086 }
1087
1093 void setDiffScale(float value) {
1094 setConfigValue("diff_scale", static_cast<double>(value));
1095 }
1096
1103 OBFloatPropertyRange range{};
1104 const auto &schemaVec = getConfigSchemaVec();
1105 for(const auto &item: schemaVec) {
1106 if(strcmp(item.name, "weight") == 0) {
1108 break;
1109 }
1110 }
1111 return range;
1112 }
1113
1119 void setWeight(float value) {
1120 setConfigValue("weight", static_cast<double>(value));
1121 }
1122};
1123
1128public:
1129 DisparityTransform(const std::string &activationKey = "") {
1130 ob_error *error = nullptr;
1131 auto impl = ob_create_private_filter("DisparityTransform", activationKey.c_str(), &error);
1132 Error::handle(&error);
1133 init(impl);
1134 }
1135
1136 ~DisparityTransform() noexcept override = default;
1137};
1138
1140private:
1141 ob_filter_list_t *impl_;
1142
1143public:
1144 explicit OBFilterList(ob_filter_list_t *impl) : impl_(impl) {}
1145
1146 ~OBFilterList() noexcept {
1147 ob_error *error = nullptr;
1148 ob_delete_filter_list(impl_, &error);
1149 Error::handle(&error, false);
1150 }
1151
1157 uint32_t getCount() const {
1158 ob_error *error = nullptr;
1159 auto count = ob_filter_list_get_count(impl_, &error);
1160 Error::handle(&error);
1161 return count;
1162 }
1163
1171 std::shared_ptr<Filter> getFilter(uint32_t index) {
1172 ob_error *error = nullptr;
1173 auto filter = ob_filter_list_get_filter(impl_, index, &error);
1174 Error::handle(&error);
1175 return std::make_shared<Filter>(filter);
1176 }
1177
1178public:
1179 // The following interfaces are deprecated and are retained here for compatibility purposes.
1180 uint32_t count() const {
1181 return getCount();
1182 }
1183};
1184
1188inline const std::unordered_map<std::string, std::type_index> &getFilterTypeMap() {
1189 static const std::unordered_map<std::string, std::type_index> filterTypeMap = {
1190 { "PointCloudFilter", typeid(PointCloudFilter) }, { "Align", typeid(Align) },
1191 { "FormatConverter", typeid(FormatConvertFilter) }, { "HDRMerge", typeid(HdrMerge) },
1192 { "SequenceIdFilter", typeid(SequenceIdFilter) }, { "DecimationFilter", typeid(DecimationFilter) },
1193 { "ThresholdFilter", typeid(ThresholdFilter) }, { "SpatialAdvancedFilter", typeid(SpatialAdvancedFilter) },
1194 { "HoleFillingFilter", typeid(HoleFillingFilter) }, { "NoiseRemovalFilter", typeid(NoiseRemovalFilter) },
1195 { "TemporalFilter", typeid(TemporalFilter) }, { "DisparityTransform", typeid(DisparityTransform) },
1196 { "SpatialFastFilter", typeid(SpatialFastFilter) }, { "SpatialModerateFilter", typeid(SpatialModerateFilter) },
1197 };
1198 return filterTypeMap;
1199}
1200
1207template <typename T> bool Filter::is() {
1208 std::string name = type();
1209
1210 const auto &filterTypeMap = getFilterTypeMap();
1211 auto it = filterTypeMap.find(name);
1212 if(it != filterTypeMap.end()) {
1213 return std::type_index(typeid(T)) == it->second;
1214 }
1215 return false;
1216}
1217
1218} // namespace ob
This file defines the Error class, which describes abnormal errors within the SDK....
The processing unit of the SDK can perform point cloud generation, format conversion and other functi...
OB_EXPORT const char * ob_filter_get_vendor_specific_code(const char *name, ob_error **error)
Get the vendor specific code of a filter by filter name.
OB_EXPORT void ob_align_filter_set_align_to_stream_profile(ob_filter *filter, const ob_stream_profile *align_to_stream_profile, ob_error **error)
Set the align to stream profile for the align filter.
OB_EXPORT void ob_delete_filter_list(ob_filter_list *filter_list, ob_error **error)
Delete a list of ob_filter objects.
OB_EXPORT void ob_filter_push_frame(ob_filter *filter, const ob_frame *frame, ob_error **error)
Push the frame into the pending cache for the filter (asynchronous callback interface).
OB_EXPORT ob_frame * ob_filter_process(ob_filter *filter, const ob_frame *frame, ob_error **error)
Process the frame (synchronous interface).
OB_EXPORT ob_filter_config_schema_item ob_filter_config_schema_list_get_item(const ob_filter_config_schema_list *config_schema_list, uint32_t index, ob_error **error)
Get the config schema item by index.
OB_EXPORT void ob_filter_reset(ob_filter *filter, ob_error **error)
Reset the filter, clears the cache, and resets the state. If the asynchronous interface is used,...
OB_EXPORT const char * ob_filter_get_config_schema(const ob_filter *filter, ob_error **error)
Get config schema of the filter.
OB_EXPORT ob_filter * ob_create_private_filter(const char *name, const char *activation_key, ob_error **error)
Create a private Filter object with activation key.
OB_EXPORT void ob_filter_set_callback(ob_filter *filter, ob_filter_callback callback, void *user_data, ob_error **error)
Set the processing result callback function for the filter (asynchronous callback interface).
OB_EXPORT bool ob_filter_is_enabled(const ob_filter *filter, ob_error **error)
Get the enable status of the frame post processing.
OB_EXPORT uint32_t ob_filter_config_schema_list_get_count(const ob_filter_config_schema_list *config_schema_list, ob_error **error)
Get the number of config schema items in the config schema list.
OB_EXPORT const char * ob_filter_get_name(const ob_filter *filter, ob_error **error)
Get the name of ob_filter.
OB_EXPORT void ob_delete_filter(ob_filter *filter, ob_error **error)
Delete the filter.
OB_EXPORT double ob_filter_get_config_value(const ob_filter *filter, const char *config_name, ob_error **error)
Get the filter config value by name and cast to double.
OB_EXPORT ob_filter * ob_filter_list_get_filter(const ob_filter_list *filter_list, uint32_t index, ob_error **error)
Get the filter by index.
OB_EXPORT ob_filter * ob_create_filter(const char *name, ob_error **error)
Create a Filter object.
OB_EXPORT uint32_t ob_filter_list_get_count(const ob_filter_list *filter_list, ob_error **error)
Get the number of filter in the list.
OB_EXPORT void ob_filter_set_config_value(ob_filter *filter, const char *config_name, double value, ob_error **error)
Set the filter config value by name.
OB_EXPORT void ob_filter_enable(ob_filter *filter, bool enable, ob_error **error)
Enable the frame post processing.
OB_EXPORT ob_filter_config_schema_list * ob_filter_get_config_schema_list(const ob_filter *filter, ob_error **error)
Get the filter config schema list of the filter.
OB_EXPORT void ob_delete_filter_config_schema_list(ob_filter_config_schema_list *config_schema_list, ob_error **error)
Delete a list of filter config schema items.
Frame related function is mainly used to obtain frame data and frame information.
Frame related type, which is mainly used to obtain frame data and frame information.
struct ob_frame_t ob_frame
Definition ObTypes.h:33
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:204
OBStreamType
Enumeration value describing the type of data stream.
Definition ObTypes.h:149
struct ob_filter_t ob_filter
Definition ObTypes.h:34
enum OB_COORDINATE_SYSTEM_TYPE OBCoordinateSystemType
OBHoleFillingMode
Hole fillig mode.
Definition ObTypes.h:1064
OBConvertFormat
Enumeration of format conversion types.
Definition ObTypes.h:547
Align for depth to other or other to depth.
Definition Filter.hpp:440
Align(OBStreamType alignToStreamType)
Definition Filter.hpp:442
virtual ~Align() noexcept override=default
OBStreamType getAlignToStreamType()
Definition Filter.hpp:453
void setMatchTargetResolution(bool state)
Sets whether the output frame resolution should match the target resolution. When enabled,...
Definition Filter.hpp:467
void setAlignToStreamProfile(std::shared_ptr< const StreamProfile > profile)
Set the Align To Stream Profile.
Definition Filter.hpp:477
Decimation filter, reducing complexity by subsampling depth maps and losing depth details.
Definition Filter.hpp:596
virtual ~DecimationFilter() noexcept override=default
OBUint8PropertyRange getScaleRange()
Get the property range of the decimation filter scale value.
Definition Filter.hpp:626
uint8_t getScaleValue()
Get the decimation filter scale value.
Definition Filter.hpp:619
void setScaleValue(uint8_t value)
Set the decimation filter scale value.
Definition Filter.hpp:612
Depth to disparity or disparity to depth.
Definition Filter.hpp:1127
DisparityTransform(const std::string &activationKey="")
Definition Filter.hpp:1129
~DisparityTransform() noexcept override=default
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
Definition Error.hpp:38
A factory class for creating filters.
Definition Filter.hpp:301
static std::string getFilterVendorSpecificCode(const std::string &name)
Get the vendor specific code of a filter by filter name.
Definition Filter.hpp:335
static std::shared_ptr< Filter > createFilter(const std::string &name)
Create a filter by name.
Definition Filter.hpp:306
static std::shared_ptr< Filter > createPrivateFilter(const std::string &name, const std::string &activationKey)
Create a private filter by name and activation key.
Definition Filter.hpp:320
The Filter class is the base class for all filters in the SDK.
Definition Filter.hpp:76
FilterCallback callback_
Definition Filter.hpp:80
bool is()
Check if the runtime type of the filter object is compatible with a given type.
Definition Filter.hpp:1207
virtual void init(ob_filter *impl)
Definition Filter.hpp:89
std::shared_ptr< T > as()
Definition Filter.hpp:289
virtual const std::string & getName() const
Get the type of filter.
Definition Filter.hpp:138
virtual std::vector< OBFilterConfigSchemaItem > getConfigSchemaVec() const
Get the Config Schema Vec object.
Definition Filter.hpp:232
virtual void enable(bool enable) const
enable the filter
Definition Filter.hpp:155
std::string name_
Definition Filter.hpp:79
virtual void setConfigValue(const std::string &configName, double value) const
Set the filter config value by name.
Definition Filter.hpp:245
virtual std::string getConfigSchema() const
Get config schema of the filter.
Definition Filter.hpp:219
std::vector< OBFilterConfigSchemaItem > configSchemaVec_
Definition Filter.hpp:81
virtual bool isEnabled() const
Return Enable State.
Definition Filter.hpp:164
Filter()=default
Default constructor with nullptr impl, used for derived classes only.
virtual void pushFrame(std::shared_ptr< Frame > frame) const
Pushes the pending frame into the cache for asynchronous processing.
Definition Filter.hpp:193
virtual std::shared_ptr< Frame > process(std::shared_ptr< const Frame > frame) const
Processes a frame synchronously.
Definition Filter.hpp:178
ob_filter * getImpl() const
Get the Impl object of the filter.
Definition Filter.hpp:129
virtual void reset() const
Reset the filter, freeing the internal cache, stopping the processing thread, and clearing the pendin...
Definition Filter.hpp:146
ob_filter * impl_
Definition Filter.hpp:78
virtual const char * type()
Definition Filter.hpp:276
virtual double getConfigValue(const std::string &configName) const
Get the Config Value object by name.
Definition Filter.hpp:261
virtual void setCallBack(FilterCallback callback)
Set the callback function for asynchronous processing.
Definition Filter.hpp:204
Filter(ob_filter *impl)
Definition Filter.hpp:112
virtual ~Filter() noexcept
Definition Filter.hpp:116
The FormatConvertFilter class is a subclass of Filter that performs format conversion.
Definition Filter.hpp:487
virtual ~FormatConvertFilter() noexcept override=default
void setFormatConvertType(OBConvertFormat type)
Set the format conversion type.
Definition Filter.hpp:503
HdrMerge processing block, the processing merges between depth frames with different sub-preset seque...
Definition Filter.hpp:513
virtual ~HdrMerge() noexcept override=default
Hole filling filter,the processing performed depends on the selected hole filling mode.
Definition Filter.hpp:956
void setFilterMode(OBHoleFillingMode mode)
Set the HoleFillingFilter mode.
Definition Filter.hpp:972
HoleFillingFilter(const std::string &activationKey="")
Definition Filter.hpp:958
OBHoleFillingMode getFilterMode()
Get the HoleFillingFilter mode.
Definition Filter.hpp:981
~HoleFillingFilter() noexcept override=default
The noise removal filter,removing scattering depth pixels.
Definition Filter.hpp:989
OBUint16PropertyRange getDispDiffRange()
Get the noise removal filter disp diff range.
Definition Filter.hpp:1028
void setFilterParams(OBNoiseRemovalFilterParams filterParams)
Set the noise removal filter params.
Definition Filter.hpp:1005
NoiseRemovalFilter(const std::string &activationKey="")
Definition Filter.hpp:991
~NoiseRemovalFilter() noexcept override=default
OBUint16PropertyRange getMaxSizeRange()
Get the noise removal filter max size range.
Definition Filter.hpp:1044
OBNoiseRemovalFilterParams getFilterParams()
Get the noise removal filter params.
Definition Filter.hpp:1016
~OBFilterList() noexcept
Definition Filter.hpp:1146
uint32_t getCount() const
Get the number of filters.
Definition Filter.hpp:1157
uint32_t count() const
Definition Filter.hpp:1180
std::shared_ptr< Filter > getFilter(uint32_t index)
Get the Filter object at the specified index.
Definition Filter.hpp:1171
OBFilterList(ob_filter_list_t *impl)
Definition Filter.hpp:1144
The PointCloudFilter class is a subclass of Filter that generates point clouds.
Definition Filter.hpp:346
void setCoordinateSystem(OBCoordinateSystemType type)
Set the point cloud coordinate system.
Definition Filter.hpp:395
void setCoordinateDataScaled(float factor)
Set the point cloud coordinate data zoom factor.
Definition Filter.hpp:374
void setCameraParam(OBCameraParam param)
Definition Filter.hpp:432
void setPositionDataScaled(float scale)
Definition Filter.hpp:423
void setCreatePointFormat(OBFormat format)
Set the output pointcloud frame format.
Definition Filter.hpp:362
virtual ~PointCloudFilter() noexcept override=default
void setFrameAlignState(bool state)
Definition Filter.hpp:428
OBIntPropertyRange getDecimationFactorRange()
Get the property range of the decimation factor range.
Definition Filter.hpp:412
void setDecimationFactor(int value)
Set the point cloud decimation factor. Calling this function to decimation factor will output thedown...
Definition Filter.hpp:405
void setColorDataNormalization(bool state)
Set point cloud color data normalization.
Definition Filter.hpp:386
Create SequenceIdFilter processing block.
Definition Filter.hpp:528
int getSelectSequenceId()
Get the current sequence id.
Definition Filter.hpp:575
void selectSequenceId(int sequence_id)
Set the sequenceId filter params.
Definition Filter.hpp:566
virtual ~SequenceIdFilter() noexcept override
Definition Filter.hpp:554
OBSequenceIdItem * getSequenceIdList()
Definition Filter.hpp:579
int getSequenceIdListSize()
Get the sequenceId list size.
Definition Filter.hpp:588
Spatial advanced filte smooths the image by calculating frame with alpha and delta settings alpha def...
Definition Filter.hpp:703
void setFilterParams(OBSpatialAdvancedFilterParams params)
Set the spatial advanced filter params.
Definition Filter.hpp:801
OBSpatialAdvancedFilterParams getFilterParams()
Get the spatial advanced filter params.
Definition Filter.hpp:787
OBUint16PropertyRange getRadiusRange()
Get the spatial advanced filter radius range.
Definition Filter.hpp:753
SpatialAdvancedFilter(const std::string &activationKey="")
Definition Filter.hpp:705
OBFloatPropertyRange getAlphaRange()
Get the spatial advanced filter alpha range.
Definition Filter.hpp:719
OBUint16PropertyRange getDispDiffRange()
Get the spatial advanced filter dispdiff range.
Definition Filter.hpp:736
virtual ~SpatialAdvancedFilter() noexcept override=default
OBIntPropertyRange getMagnitudeRange()
Get the spatial advanced filter magnitude range.
Definition Filter.hpp:770
The Spatial Fast Filter utilizes an enhanced median smoothing algorithm, designed to significantly re...
Definition Filter.hpp:813
virtual ~SpatialFastFilter() noexcept override=default
SpatialFastFilter(const std::string &activationKey="")
Definition Filter.hpp:815
void setFilterParams(OBSpatialFastFilterParams params)
Set the spatial fast filter params.
Definition Filter.hpp:857
OBSpatialFastFilterParams getFilterParams()
Get the spatial fast filter params.
Definition Filter.hpp:846
OBIntPropertyRange getRadiusRange()
Get the spatial fast filter radius range.
Definition Filter.hpp:829
The Spatial Moderate Filter utilizes an optimized average smoothing algorithm, to achieve a balance b...
Definition Filter.hpp:866
SpatialModerateFilter(const std::string &activationKey="")
Definition Filter.hpp:868
OBIntPropertyRange getRadiusRange()
Get the spatial moderate filter radius range.
Definition Filter.hpp:899
virtual ~SpatialModerateFilter() noexcept override=default
void setFilterParams(OBSpatialModerateFilterParams params)
Set the spatial moderate filter params.
Definition Filter.hpp:946
OBSpatialModerateFilterParams getFilterParams()
Get the spatial moderate filter params.
Definition Filter.hpp:933
OBIntPropertyRange getMagnitudeRange()
Get the spatial moderate filter magnitude range.
Definition Filter.hpp:882
OBIntPropertyRange getDispDiffRange()
Get the spatial moderate filter disp diff range.
Definition Filter.hpp:916
Temporal filter.
Definition Filter.hpp:1060
OBFloatPropertyRange getWeightRange()
Get the TemporalFilter weight range.
Definition Filter.hpp:1102
void setDiffScale(float value)
Set the TemporalFilter diffscale value.
Definition Filter.hpp:1093
~TemporalFilter() noexcept override=default
OBFloatPropertyRange getDiffScaleRange()
Get the TemporalFilter diffscale range.
Definition Filter.hpp:1076
void setWeight(float value)
Set the TemporalFilter weight value.
Definition Filter.hpp:1119
TemporalFilter(const std::string &activationKey="")
Definition Filter.hpp:1062
Creates depth Thresholding filter By controlling min and max options on the block.
Definition Filter.hpp:640
bool setValueRange(uint16_t min, uint16_t max)
Set the threshold filter max and min range.
Definition Filter.hpp:688
OBIntPropertyRange getMinRange()
Get the threshold filter min range.
Definition Filter.hpp:656
virtual ~ThresholdFilter() noexcept override=default
OBIntPropertyRange getMaxRange()
Get the threshold filter max range.
Definition Filter.hpp:673
Definition Context.hpp:22
const std::unordered_map< std::string, std::type_index > & getFilterTypeMap()
Returns the mapping of filter type names to their corresponding type_index.
Definition Filter.hpp:1188
std::function< void(std::shared_ptr< Frame >)> FilterCallback
A callback function that takes a shared pointer to a Frame object as its argument.
Definition Filter.hpp:32
T getPropertyRange(const OBFilterConfigSchemaItem &item, const double cur)
Get T Property Range.
Definition Filter.hpp:60
Structure for camera parameters.
Definition ObTypes.h:460
Configuration Item for the filter.
Definition ObTypes.h:1527
double min
Minimum value casted to double.
Definition ObTypes.h:1530
double max
Maximum value casted to double.
Definition ObTypes.h:1531
double def
Default value casted to double.
Definition ObTypes.h:1533
double step
Step value casted to double.
Definition ObTypes.h:1532
Structure for float range.
Definition ObTypes.h:344
Structure for integer range.
Definition ObTypes.h:333
SequenceId fliter list item.
Definition ObTypes.h:1056
Structure for float range.
Definition ObTypes.h:355
Structure for float range.
Definition ObTypes.h:366
Get the type of a PropertyRange member.
Definition Filter.hpp:37
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:119