Skip to content

Commit 4f2fa15

Browse files
Merge pull request #4 from ConstantRobotics-Ltd/add-roi-params
Add roi params
2 parents c08bae7 + 41da0c0 commit 4f2fa15

File tree

10 files changed

+490
-109
lines changed

10 files changed

+490
-109
lines changed

README.md

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# **VSource interface C++ library**
66

7-
**v1.7.1**
7+
**v1.8.0**
88

99

1010

@@ -68,6 +68,7 @@
6868
| 1.6.0 | 26.09.2023 | - Signature of getParams(...) method changed. |
6969
| 1.6.1 | 13.11.2023 | - Frame class updated. |
7070
| 1.7.1 | 14.12.2023 | - Virtual destructor added.<br />- Frame class updated. |
71+
| 1.8.0 | 18.12.2023 | - Region of intrest params included. |
7172

7273

7374

@@ -185,7 +186,7 @@ std::cout << "VSource class version: " << VSource::getVersion() << std::endl;
185186
Console output:
186187

187188
```bash
188-
VSource class version: 1.7.1
189+
VSource class version: 1.8.0
189190
```
190191

191192

@@ -515,6 +516,14 @@ enum class VSourceParam
515516
FPS,
516517
/// [read only] Open flag. 0 - not open, 1 - open.
517518
IS_OPEN,
519+
/// Region of intrest upper left corner x coordinate.
520+
ROI_X,
521+
/// Region of intrest upper left corner x coordinate.
522+
ROI_Y,
523+
/// Region of intrest upper left corner x coordinate.
524+
ROI_WIDTH,
525+
/// Region of intrest upper left corner x coordinate.
526+
ROI_HEIGHT,
518527
/// [read/write] Custom parameter. Depends on implementation.
519528
CUSTOM_1,
520529
/// [read/write] Custom parameter. Depends on implementation.
@@ -540,6 +549,10 @@ enum class VSourceParam
540549
| CYCLE_TIME_MKS | read only | Video capture cycle time. **VSource** class sets this value automatically. This parameter means time interval between two captured video frame. |
541550
| FPS | read / write | FPS. User can set frame FPS before initialization or after. Some video source classes may set FPS automatically. |
542551
| IS_OPEN | read only | Open flag. 0 - not open, 1 - open. |
552+
| ROI_X | read / write | Region of intrest x coordinate. |
553+
| ROI_Y | read / write | Region of intrest y coordinate. |
554+
| ROI_WIDTH | read / write | Region of intrest width. |
555+
| ROI_HEIGHT | read / write | Region of intrest heigth. |
543556
| CUSTOM_1 | read / write | Custom parameter. Depends on implementation. |
544557
| CUSTOM_2 | read / write | Custom parameter. Depends on implementation. |
545558
| CUSTOM_3 | read / write | Custom parameter. Depends on implementation. |
@@ -601,6 +614,14 @@ public:
601614
float fps{0};
602615
/// Open flag. 0 - not open, 1 - open.
603616
bool isOpen{false};
617+
/// Region of intrest upper left corner x coordinate.
618+
int roiX{0};
619+
/// Region of intrest upper left corner y coordinate.
620+
int roiY{0};
621+
/// Region of intrest width.
622+
int roiWidth{0};
623+
/// Region of intrest heigth.
624+
int roiHeight{0};
604625
/// Custom parameter. Depends on implementation.
605626
float custom1{0.0f};
606627
/// Custom parameter. Depends on implementation.
@@ -642,6 +663,10 @@ public:
642663
| cycleTimeMks | int | Video capture cycle time. **VSource** class sets this value automatically. This parameter means time interval between two captured video frame. |
643664
| fps | float | FPS. User can set frame FPS before initialization or after. Some video source classes may set FPS automatically. |
644665
| isOpen | bool | Open flag. false - not open, true - open. |
666+
| roiX | int | Region of intrest x coordinate. |
667+
| roiY | int | Region of intrest y coordinate. |
668+
| roiWidth | int | Region of intrest width. |
669+
| roiHeight | int | Region of intrest heigth. |
645670
| custom1 | float | Custom parameter. Depends on implementation. |
646671
| custom2 | float | Custom parameter. Depends on implementation. |
647672
| custom3 | float | Custom parameter. Depends on implementation. |
@@ -660,15 +685,15 @@ bool encode(uint8_t* data, int bufferSize, int& size, VSourceParamsMask* mask =
660685

661686
| Parameter | Value |
662687
| ---------- | ------------------------------------------------------------ |
663-
| data | Pointer to data buffer. Buffer size should be at least **62** bytes. |
664-
| size | Size of encoded data. 62 bytes by default. |
665-
| bufferSize | Data buffer size. Buffer size must be >= 62 bytes. |
688+
| data | Pointer to data buffer. |
689+
| size | Size of encoded data. 78 bytes by default. |
690+
| bufferSize | Data buffer size. If buffer size smaller than required, buffer will be filled with fewer parameters. |
666691
| mask | Parameters mask - pointer to **VSourceParamsMask** structure. **VSourceParamsMask** (declared in VSource.h file) determines flags for each field (parameter) declared in **VSourceParams** class. If the user wants to exclude any parameters from serialization, he can put a pointer to the mask. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the VSourceParamsMask structure. |
667692

668693
**VSourceParamsMask** structure declaration:
669694

670695
```cpp
671-
typedef struct VSourceParamsMask
696+
struct VSourceParamsMask
672697
{
673698
bool logLevel{true};
674699
bool width{true};
@@ -682,10 +707,14 @@ typedef struct VSourceParamsMask
682707
bool cycleTimeMks{true};
683708
bool fps{true};
684709
bool isOpen{true};
710+
bool roiX{true};
711+
bool roiY{true};
712+
bool roiWidth{true};
713+
bool roiHeight{true};
685714
bool custom1{true};
686715
bool custom2{true};
687716
bool custom3{true};
688-
} VSourceParamsMask;
717+
};
689718
```
690719

691720
Example without parameters mask:
@@ -783,18 +812,22 @@ if(!outConfig.readFromFile("TestVSourceParams.json"))
783812
```json
784813
{
785814
"vSourceParams": {
786-
"custom1": 96.0,
787-
"custom2": 212.0,
788-
"custom3": 243.0,
789-
"exposureMode": 63,
790-
"focusMode": 167,
815+
"custom1": 150.0,
816+
"custom2": 252.0,
817+
"custom3": 30.0,
818+
"exposureMode": 226,
819+
"focusMode": 89,
791820
"fourcc": "skdfjhvk",
792-
"fps": 205.0,
793-
"gainMode": 84,
794-
"height": 143,
795-
"logLevel": 92,
821+
"fps": 206.0,
822+
"gainMode": 180,
823+
"height": 61,
824+
"logLevel": 17,
825+
"roiHeight": 249,
826+
"roiWidth": 167,
827+
"roiX": 39,
828+
"roiY": 223,
796829
"source": "alsfghljb",
797-
"width": 204
830+
"width": 35
798831
}
799832
}
800833
```
@@ -969,5 +1002,4 @@ private:
9691002
/// Output frame.
9701003
Frame m_outputFrame;
9711004
};
972-
```
973-
1005+
```

VSource_C++_library_v1.7.1.pdf

-206 KB
Binary file not shown.

VSource_C++_library_v1.8.0.pdf

209 KB
Binary file not shown.

example/CustomVSource.cpp

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ bool cr::video::CustomVSource::setParam(VSourceParam id, float value)
144144
// Read only param.
145145
return false;
146146
}
147+
case cr::video::VSourceParam::ROI_X:
148+
{
149+
m_params.roiX = (int)value;
150+
return true;
151+
}
152+
case cr::video::VSourceParam::ROI_Y:
153+
{
154+
m_params.roiY = (int)value;
155+
return true;
156+
}
157+
case cr::video::VSourceParam::ROI_WIDTH:
158+
{
159+
m_params.roiWidth = (int)value;
160+
return true;
161+
}
162+
case cr::video::VSourceParam::ROI_HEIGHT:
163+
{
164+
m_params.roiHeight = (int)value;
165+
return true;
166+
}
147167
case cr::video::VSourceParam::CUSTOM_1:
148168
{
149169
m_params.custom1 = value;
@@ -223,6 +243,22 @@ float cr::video::CustomVSource::getParam(VSourceParam id)
223243
{
224244
return m_params.isOpen ? 1.0f : 0.0f;
225245
}
246+
case cr::video::VSourceParam::ROI_X:
247+
{
248+
return (float)m_params.roiX;
249+
}
250+
case cr::video::VSourceParam::ROI_Y:
251+
{
252+
return (float)m_params.roiY;
253+
}
254+
case cr::video::VSourceParam::ROI_WIDTH:
255+
{
256+
return (float)m_params.roiWidth;
257+
}
258+
case cr::video::VSourceParam::ROI_HEIGHT:
259+
{
260+
return (float)m_params.roiHeight;
261+
}
226262
case cr::video::VSourceParam::CUSTOM_1:
227263
{
228264
return m_params.custom1;
@@ -298,11 +334,4 @@ bool cr::video::CustomVSource::decodeAndExecuteCommand(uint8_t* data, int size)
298334
}
299335

300336
return false;
301-
}
302-
303-
304-
305-
306-
307-
308-
337+
}

example/CustomVSource.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,4 @@ class CustomVSource: public VSource
5959
Frame m_outputFrame;
6060
};
6161
}
62-
}
63-
64-
65-
66-
62+
}

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13)
66
## LIBRARY-PROJECT
77
## name and version
88
###############################################################################
9-
project(VSource VERSION 1.7.1 LANGUAGES CXX)
9+
project(VSource VERSION 1.8.0 LANGUAGES CXX)
1010

1111

1212

0 commit comments

Comments
 (0)