Skip to content

Commit f1faf48

Browse files
Params updated, documentation updated
1 parent 86dd6de commit f1faf48

File tree

6 files changed

+171
-57
lines changed

6 files changed

+171
-57
lines changed

ObjectDetector_interface_class.pdf

256 KB
Binary file not shown.

README.md

Lines changed: 143 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
2+
13
![logo](_static/object_detector_logo.png)
24

5+
6+
37
# **ObjectDetector interface C++ library**
48

59
**v1.0.0**
@@ -31,16 +35,16 @@
3135
- [Object structure](#Object-structure)
3236
- [ObjectDetectorParams class description](#ObjectDetectorParams-class-description)
3337
- [ObjectDetectorParams class declaration](#ObjectDetectorParams-class-declaration)
34-
- [Serialize video source params](#Serialize-video-source-params)
35-
- [Deserialize video source params](#Deserialize-video-source-params)
38+
- [Serialize object detector params](#Serialize-object-detector-params)
39+
- [Deserialize object detector params](#Deserialize-object-detector-params)
3640
- [Read params from JSON file and write to JSON file](#Read-params-from-JSON-file-and-write-to-JSON-file)
3741
- [Build and connect to your project](#Build-and-connect-to-your-project)
3842

3943

4044

4145
# Overview
4246

43-
**ObjectDetector** C++ library provides standard interface as well defines data structures and rules for different object detectors (motion detectors, events detectors, neural networks etc.). **ObjectDetector** interface class doesn't do anything, just provides interface and defines data structures. Different object detector classes inherit interface form **ObjectDetector** C++ class. **ObjectDetector.h** file contains **ObjectDetectorParams** class, **ObjectDetectorCommand** enum, **ObjectDetectorParam** enum and includes **ObjectDetector** class declaration. **ObjectDetectorParams** class contains object detector params, list of detected objects and includes methods to encode and decode video source params. **ObjectDetectorCommand** enum contains IDs of commands. **ObjectDetectorParam** enum contains IDs of params. All object detectors should include params and commands listed in **ObjectDetector.h** file. ObjectDetector class dependency: [**Frame**](https://github.com/ConstantRobotics-Ltd/Frame) class which describes video frame structure and pixel formats, [**ConfigReader**](https://github.com/ConstantRobotics-Ltd/ConfigReader) class which provides methods to work with JSON structures (read/write).
47+
**ObjectDetector** C++ library provides standard interface as well defines data structures and rules for different object detectors (motion detectors, events detectors, neural networks etc.). **ObjectDetector** interface class doesn't do anything, just provides interface and defines data structures. Different object detector classes inherit interface form **ObjectDetector** C++ class. **ObjectDetector.h** file contains **ObjectDetectorParams** class, **ObjectDetectorCommand** enum, **ObjectDetectorParam** enum and includes **ObjectDetector** class declaration. **ObjectDetectorParams** class contains object detector params, list of detected objects and includes methods to encode and decode params. **ObjectDetectorCommand** enum contains IDs of commands. **ObjectDetectorParam** enum contains IDs of params. All object detectors should include params and commands listed in **ObjectDetector.h** file. ObjectDetector class dependency: [**Frame**](https://github.com/ConstantRobotics-Ltd/Frame) class which describes video frame structure and pixel formats, [**ConfigReader**](https://github.com/ConstantRobotics-Ltd/ConfigReader) class which provides methods to work with JSON structures (read/write).
4448

4549

4650

@@ -347,7 +351,7 @@ static void encodeCommand(uint8_t* data, int& size, ObjectDetectorCommand id);
347351
| 5 | id | Command ID **int32_t** in Little-endian format. |
348352
| 6 | id | Command ID **int32_t** in Little-endian format. |
349353
350-
**encodeCommand(...)** is static and used without **VSource** class instance. This method used on client side (control system). Command encoding example:
354+
**encodeCommand(...)** is static and used without **ObjectDetector** class instance. This method used on client side (control system). Command encoding example:
351355
352356
```cpp
353357
// Buffer for encoded data.
@@ -484,7 +488,7 @@ enum class ObjectDetectorParam
484488
};
485489
```
486490

487-
**Table 3** - Video source params description. Some params maybe unsupported by particular video source class.
491+
**Table 3** - Object detector params description. Some params maybe unsupported by particular object detector class.
488492

489493
| Parameter | Access | Description |
490494
| ------------------------- | ------------ | ------------------------------------------------------------ |
@@ -570,6 +574,8 @@ typedef struct Object
570574
class ObjectDetectorParams
571575
{
572576
public:
577+
/// Init string. Depends on implementation.
578+
std::string initString{""};
573579
/// Logging mode. Values: 0 - Disable, 1 - Only file,
574580
/// 2 - Only terminal (console), 3 - File and terminal (console).
575581
int logMode{0};
@@ -635,29 +641,27 @@ public:
635641
/// List of detected objects.
636642
std::vector<Object> objects;
637643

638-
JSON_READABLE(ObjectDetectorParams, logMode, frameBufferSize, minObjectWidth,
639-
maxObjectWidth, minObjectHeight, maxObjectHeight, minXSpeed,
640-
maxXSpeed, minYSpeed, maxYSpeed, minDetectionProbability,
641-
xDetectionCriteria, yDetectionCriteria, resetCriteria,
642-
sensitivity, scaleFactor, numThreads, type, enable,
643-
custom1, custom2, custom3);
644-
644+
JSON_READABLE(ObjectDetectorParams, initString, logMode, frameBufferSize,
645+
minObjectWidth, maxObjectWidth, minObjectHeight, maxObjectHeight,
646+
minXSpeed, maxXSpeed, minYSpeed, maxYSpeed, minDetectionProbability,
647+
xDetectionCriteria, yDetectionCriteria, resetCriteria, sensitivity,
648+
scaleFactor, numThreads, type, enable, custom1, custom2, custom3);
645649
/**
646650
* @brief operator =
647651
* @param src Source object.
648652
* @return ObjectDetectorParams object.
649653
*/
650654
ObjectDetectorParams& operator= (const ObjectDetectorParams& src);
651655
/**
652-
* @brief Encode params.
656+
* @brief Encode params. Method doesn't encode initString.
653657
* @param data Pointer to data buffer.
654658
* @param size Size of data.
655659
* @param mask Pointer to parameters mask.
656660
*/
657661
void encode(uint8_t* data, int& size,
658662
ObjectDetectorParamsMask* mask = nullptr);
659663
/**
660-
* @brief Decode params.
664+
* @brief Decode params. Method doesn't decode initString;
661665
* @param data Pointer to data.
662666
* @return TRUE is params decoded or FALSE if not.
663667
*/
@@ -669,6 +673,7 @@ public:
669673
670674
| Field | Type | Description |
671675
| ----------------------- | ----------- | ------------------------------------------------------------ |
676+
| initString | string | Init string. Depends on implementation. |
672677
| logMode | int | Logging mode. Values: 0 - Disable, 1 - Only file, 2 - Only terminal, 3 - File and terminal. |
673678
| frameBufferSize | int | Frame buffer size. Depends on implementation. It can be buffer size for image filtering or can be buffer size to collect frames for processing. |
674679
| minObjectWidth | int | Minimum object width to be detected, pixels. To be detected object's width must be >= minObjectWidth. |
@@ -700,7 +705,7 @@ public:
700705
701706
## Serialize object detector params
702707
703-
**ObjectDetectorParams** class provides method **encode(...)** to serialize object detector params (fields of ObjectDetectorParams class, see Table 5). Serialization of object detector params necessary in case when you need to send video source params via communication channels. Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask (3 bytes) where each bit represents particular parameter and **decode(...)** method recognizes it. Method declaration:
708+
**ObjectDetectorParams** class provides method **encode(...)** to serialize object detector params (fields of ObjectDetectorParams class, see Table 5). Serialization of object detector params necessary in case when you need to send params via communication channels. Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask (3 bytes) where each bit represents particular parameter and **decode(...)** method recognizes it. Method doesn't encode initString. Method declaration:
704709
705710
```cpp
706711
void encode(uint8_t* data, int& size, ObjectDetectorParamsMask* mask = nullptr);
@@ -748,9 +753,23 @@ Example without parameters mask:
748753

749754
```cpp
750755
// Prepare random params.
751-
VSourceParams in;
752-
in.initString = "alsfghljb";
753-
in.logLevel = 0;
756+
ObjectDetectorParams in;
757+
in.logMode = rand() % 255;
758+
in.objects.clear();
759+
for (int i = 0; i < 5; ++i)
760+
{
761+
Object obj;
762+
obj.id = rand() % 255;
763+
obj.type = rand() % 255;
764+
obj.width = rand() % 255;
765+
obj.height = rand() % 255;
766+
obj.x = rand() % 255;
767+
obj.y = rand() % 255;
768+
obj.vX = rand() % 255;
769+
obj.vY = rand() % 255;
770+
obj.p = rand() % 255;
771+
in.objects.push_back(obj);
772+
}
754773

755774
// Encode data.
756775
uint8_t data[1024];
@@ -759,97 +778,166 @@ in.encode(data, size);
759778
cout << "Encoded data size: " << size << " bytes" << endl;
760779
```
761780

762-
Example without parameters mask:
781+
Example with parameters mask:
763782

764783
```cpp
765784
// Prepare random params.
766-
VSourceParams in;
767-
in.initString = "alsfghljb";
768-
in.logLevel = 0;
785+
ObjectDetectorParams in;
786+
in.logMode = rand() % 255;
787+
in.objects.clear();
788+
for (int i = 0; i < 5; ++i)
789+
{
790+
Object obj;
791+
obj.id = rand() % 255;
792+
obj.type = rand() % 255;
793+
obj.width = rand() % 255;
794+
obj.height = rand() % 255;
795+
obj.x = rand() % 255;
796+
obj.y = rand() % 255;
797+
obj.vX = rand() % 255;
798+
obj.vY = rand() % 255;
799+
obj.p = rand() % 255;
800+
in.objects.push_back(obj);
801+
}
769802

770-
// Prepare params mask.
771-
VSourceParamsMask mask;
772-
mask.logLevel = false; // Exclude logLevel. Others by default.
803+
// Prepare mask.
804+
ObjectDetectorParamsMask mask;
805+
mask.logMode = false;
773806

774807
// Encode data.
775808
uint8_t data[1024];
776809
int size = 0;
777-
in.encode(data, size, &mask);
810+
in.encode(data, size, &mask)
778811
cout << "Encoded data size: " << size << " bytes" << endl;
779812
```
780813

781814

782815

783-
## Deserialize video source params
816+
## Deserialize object detector params
784817

785-
**VSourceParams** class provides method **decode(...)** to deserialize video source params (fields of VSourceParams class, see Table 4). Deserialization of video source params necessary in case when you need to receive video source params via communication channels. Method doesn't decode fields: **initString** and **fourcc**. Method automatically recognizes which parameters were serialized by **encode(...)** method. Method declaration:
818+
**ObjectDetectorParams** class provides method **decode(...)** to deserialize params (fields of ObjectDetectorParams class, see Table 5). Deserialization of params necessary in case when you need to receive params via communication channels. Method automatically recognizes which parameters were serialized by **encode(...)** method. Method doesn't decode initString. Method declaration:
786819

787820
```cpp
788821
bool decode(uint8_t* data);
789822
```
790823
791-
| Parameter | Value |
792-
| --------- | ------------------------------------------------------------ |
793-
| data | Pointer to encode data buffer. Data size should be at least **43** bytes. |
824+
| Parameter | Value |
825+
| --------- | ------------------------------ |
826+
| data | Pointer to encode data buffer. |
794827
795828
**Returns:** TRUE if data decoded (deserialized) or FALSE if not.
796829
797830
Example:
798831
799832
```cpp
833+
// Prepare random params.
834+
ObjectDetectorParams in;
835+
in.logMode = rand() % 255;
836+
for (int i = 0; i < 5; ++i)
837+
{
838+
Object obj;
839+
obj.id = rand() % 255;
840+
obj.type = rand() % 255;
841+
obj.width = rand() % 255;
842+
obj.height = rand() % 255;
843+
obj.x = rand() % 255;
844+
obj.y = rand() % 255;
845+
obj.vX = rand() % 255;
846+
obj.vY = rand() % 255;
847+
obj.p = rand() % 255;
848+
in.objects.push_back(obj);
849+
}
850+
800851
// Encode data.
801-
VSourceParams in;
802852
uint8_t data[1024];
803853
int size = 0;
804854
in.encode(data, size);
805-
806855
cout << "Encoded data size: " << size << " bytes" << endl;
807856
808857
// Decode data.
809-
VSourceParams out;
858+
ObjectDetectorParams out;
810859
if (!out.decode(data))
860+
{
811861
cout << "Can't decode data" << endl;
862+
return false;
863+
}
812864
```
813865

814866

815867

816868
## Read params from JSON file and write to JSON file
817869

818-
**VSource** library depends on **ConfigReader** library which provides method to read params from JSON file and to write params to JSON file. Example of writing and reading params to JSON file:
870+
**ObjectDetector** library depends on **ConfigReader** library which provides method to read params from JSON file and to write params to JSON file. Example of writing and reading params to JSON file:
819871

820872
```cpp
873+
// Prepare random params.
874+
ObjectDetectorParams in;
875+
in.logMode = rand() % 255;
876+
in.objects.clear();
877+
for (int i = 0; i < 5; ++i)
878+
{
879+
Object obj;
880+
obj.id = rand() % 255;
881+
obj.type = rand() % 255;
882+
obj.width = rand() % 255;
883+
obj.height = rand() % 255;
884+
obj.x = rand() % 255;
885+
obj.y = rand() % 255;
886+
obj.vX = rand() % 255;
887+
obj.vY = rand() % 255;
888+
obj.p = rand() % 255;
889+
in.objects.push_back(obj);
890+
}
891+
821892
// Write params to file.
822-
VSurceParams in;
823893
cr::utils::ConfigReader inConfig;
824-
inConfig.set(in, "vSourceParams");
825-
inConfig.writeToFile("TestVSourceParams.json");
894+
inConfig.set(in, "ObjectDetectorParams");
895+
inConfig.writeToFile("ObjectDetectorParams.json");
826896

827897
// Read params from file.
828898
cr::utils::ConfigReader outConfig;
829-
if(!outConfig.readFromFile("TestVSourceParams.json"))
899+
if(!outConfig.readFromFile("ObjectDetectorParams.json"))
830900
{
831901
cout << "Can't open config file" << endl;
832902
return false;
833903
}
904+
905+
ObjectDetectorParams out;
906+
if(!outConfig.get(out, "ObjectDetectorParams"))
907+
{
908+
cout << "Can't read params from file" << endl;
909+
return false;
910+
}
834911
```
835912

836-
**TestVSourceParams.json** will look like:
913+
**ObjectDetectorParams.json** will look like:
837914

838915
```json
839916
{
840-
"vSourceParams": {
841-
"custom1": 96.0,
842-
"custom2": 212.0,
843-
"custom3": 243.0,
844-
"exposureMode": 63,
845-
"focusMode": 167,
846-
"fourcc": "skdfjhvk",
847-
"fps": 205.0,
848-
"gainMode": 84,
849-
"height": 143,
850-
"logLevel": 92,
851-
"source": "alsfghljb",
852-
"width": 204
917+
"ObjectDetectorParams": {
918+
"custom1": 57.0,
919+
"custom2": 244.0,
920+
"custom3": 68.0,
921+
"enable": false,
922+
"frameBufferSize": 200,
923+
"initString": "sfsfsfsfsf",
924+
"logMode": 111,
925+
"maxObjectHeight": 103,
926+
"maxObjectWidth": 199,
927+
"maxXSpeed": 104.0,
928+
"maxYSpeed": 234.0,
929+
"minDetectionProbability": 53.0,
930+
"minObjectHeight": 191,
931+
"minObjectWidth": 149,
932+
"minXSpeed": 213.0,
933+
"minYSpeed": 43.0,
934+
"numThreads": 33,
935+
"resetCriteria": 62,
936+
"scaleFactor": 85,
937+
"sensitivity": 135.0,
938+
"type": 178,
939+
"xDetectionCriteria": 224,
940+
"yDetectionCriteria": 199
853941
}
854942
}
855943
```
@@ -939,7 +1027,7 @@ if (${PARENT}_SUBMODULE_OBJECT_DETECTOR)
9391027
endif()
9401028
```
9411029

942-
File **3rdparty/CMakeLists.txt** adds folder **VSource** to your project and excludes test application (VSource class test applications) from compiling. Your repository new structure will be:
1030+
File **3rdparty/CMakeLists.txt** adds folder **ObjectDetector** to your project and excludes test application (ObjectDetector class test applications) from compiling. Your repository new structure will be:
9431031

9441032
```bash
9451033
CMakeLists.txt
@@ -949,7 +1037,7 @@ src
9491037
yourLib.cpp
9501038
3rdparty
9511039
CMakeLists.txt
952-
VSource
1040+
ObjectDetector
9531041
```
9541042

9551043
Next you need include folder 3rdparty in main **CMakeLists.txt** file of your repository. Add string at the end of your main **CMakeLists.txt**:

README.pdf

-237 KB
Binary file not shown.

src/ObjectDetector.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ cr::detector::ObjectDetectorParams &cr::detector::ObjectDetectorParams::operator
4040
custom2 = src.custom2;
4141
custom3 = src.custom3;
4242
objects = src.objects;
43+
minDetectionProbability = src.minDetectionProbability;
44+
initString = src.initString;
4345

4446
return *this;
4547
}
@@ -491,6 +493,8 @@ bool cr::detector::ObjectDetectorParams::decode(uint8_t* data)
491493
objects.clear();
492494
}
493495

496+
initString = "";
497+
494498
return true;
495499
}
496500

0 commit comments

Comments
 (0)