Skip to content

Commit

Permalink
Add new action command. Change signature of methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstantRobotics committed Sep 29, 2024
1 parent 3578055 commit f39d7e8
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 167 deletions.
252 changes: 139 additions & 113 deletions README.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion example/CustomVStabiliser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void cr::vstab::CustomVStabiliser::getParams(cr::vstab::VStabiliserParams& param



bool cr::vstab::CustomVStabiliser::executeCommand(VStabiliserCommand id)
bool cr::vstab::CustomVStabiliser::executeCommand(VStabiliserCommand id, float value)
{
// Check command ID.
switch (id)
Expand All @@ -270,6 +270,10 @@ bool cr::vstab::CustomVStabiliser::executeCommand(VStabiliserCommand id)
{
return true;
}
case cr::vstab::VStabiliserCommand::HOLD_MSEC:
{
return true;
}
default:
{
return false;
Expand Down
7 changes: 2 additions & 5 deletions example/CustomVStabiliser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CustomVStabiliser: public VStabiliser
void getParams(VStabiliserParams& params);

/// Execute command.
bool executeCommand(VStabiliserCommand id);
bool executeCommand(VStabiliserCommand id, float value = 0.0f);

/// Stabilise video frame.
bool stabilise(cr::video::Frame& src, cr::video::Frame& dst);
Expand All @@ -55,7 +55,4 @@ class CustomVStabiliser: public VStabiliser
VStabiliserParams m_params;
};
}
}



}
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13)
## LIBRARY-PROJECT
## name and version
################################################################################
project(VStabiliser VERSION 2.4.4 LANGUAGES CXX)
project(VStabiliser VERSION 2.5.0 LANGUAGES CXX)



Expand Down
24 changes: 6 additions & 18 deletions src/VStabiliser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void cr::vstab::VStabiliser::encodeSetParamCommand(


void cr::vstab::VStabiliser::encodeCommand(
uint8_t* data, int& size, cr::vstab::VStabiliserCommand id)
uint8_t* data, int& size, cr::vstab::VStabiliserCommand id, float value)
{
// Fill header.
data[0] = 0x00;
Expand All @@ -468,7 +468,8 @@ void cr::vstab::VStabiliser::encodeCommand(
// Fill data.
int commandId = (int)id;
memcpy(&data[3], &commandId, 4);
size = 7;
memcpy(&data[7], &value, 4);
size = 11;
}


Expand All @@ -478,7 +479,7 @@ int cr::vstab::VStabiliser::decodeCommand(
cr::vstab::VStabiliserCommand& commandId, float& value)
{
// Check size.
if (size < 7)
if (size < 11)
return -1;

// Check version.
Expand All @@ -489,7 +490,7 @@ int cr::vstab::VStabiliser::decodeCommand(
// Extract data.
int id = 0;
memcpy(&id, &data[3], 4);
value = 0.0f;
memcpy(&value, &data[7], 4);

// Check command type.
if (data[0] == 0x00)
Expand All @@ -504,21 +505,8 @@ int cr::vstab::VStabiliser::decodeCommand(
return false;

paramId = (VStabiliserParam)id;
memcpy(&value, &data[7], 4);
return 1;
}

return -1;
}












}
33 changes: 17 additions & 16 deletions src/VStabiliser.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class VStabiliserParams
/// bigger than this limit the library should compensate only yOffsetLimit
/// shift.
int yOffsetLimit{150};
/// Maximum rotational image angle in readians per video frame. If image
/// Maximum rotational image angle in radians per video frame. If image
/// absolute rotational angle bigger than this limit the library should
/// compensate only aOffsetLimit angle.
float aOffsetLimit{10.0f};
Expand All @@ -86,7 +86,7 @@ class VStabiliserParams
float aFilterCoeff{0.9f};
/// Enable/disable stabilisation.
bool enable{true};
/// Enable/disable trasparent borders.
/// Enable/disable transparent borders.
bool transparentBorder{true};
/// Constant horizontal image offset in pixels. The library should add this
/// offset to each processed video frame.
Expand Down Expand Up @@ -144,7 +144,7 @@ class VStabiliserParams
/**
* @brief operator =
* @param src Source object.
* @return VStabiliserParams obect.
* @return VStabiliserParams object.
*/
VStabiliserParams& operator= (const VStabiliserParams& src);

Expand Down Expand Up @@ -218,7 +218,7 @@ enum class VStabiliserParam
MODE,
/// Transparent border mode:
/// 0 - Not transparent borders (black borders).
/// 1 - Trasparent borders (parts of previous images).
/// 1 - Transparent borders (parts of previous images).
/// Particular implementation can have additional modes.
TRANSPARENT_BORDER,
/// Constant horizontal image offset in pixels. The library should add this
Expand Down Expand Up @@ -264,12 +264,14 @@ enum class VStabiliserParam
*/
enum class VStabiliserCommand
{
/// Reset stabilisation algorithm.
/// Reset stabilisation algorithm. No params.
RESET = 1,
/// Enable stabilisation. After execution parameter MODE must be set to 1.
/// Enable stabilisation. After execution parameter MODE must be set to 1. No params.
ON,
/// Disable stabilisation. After execution parameter MODE must be set to 0.
OFF
/// Disable stabilisation. After execution parameter MODE must be set to 0. No params.
OFF,
/// Hold processing for some time. Parameter - time in milliseconds.
HOLD_MSEC
};


Expand Down Expand Up @@ -323,20 +325,21 @@ class VStabiliser
/**
* @brief Execute command.
* @param id Command ID.
* @param value Command argument.
* @return TRUE if the command executed or FALSE if not.
*/
virtual bool executeCommand(VStabiliserCommand id) = 0;
virtual bool executeCommand(VStabiliserCommand id, float value = 0.0f) = 0;

/**
* @brief Stabilise video frame.
* @param src Source vidoe frame.
* @param src Source video frame.
* @param dst Result video frame.
* @return TRUE if video frame processed or FALSE in case any errors.
*/
virtual bool stabilise(cr::video::Frame& src, cr::video::Frame& dst) = 0;

/**
* @brief Get offsets: horithontal, vertical and rotation. The method must
* @brief Get offsets: horizontal, vertical and rotation. The method must
* return current offsets which implemented to last processed video frame.
* @param dX Horizontal offset.
* @param dY Vertical offset.
Expand All @@ -358,10 +361,11 @@ class VStabiliser
* @brief Encode command.
* @param data Pointer to data buffer. Must have size >= 11.
* @param size Size of encoded data.
* @param value Parameter value.
* @param id Command ID.
*/
static void encodeCommand(
uint8_t* data, int& size, VStabiliserCommand id);
uint8_t* data, int& size, VStabiliserCommand id, float value = 0.0f);

/**
* @brief Decode command.
Expand All @@ -387,7 +391,4 @@ class VStabiliser
virtual bool decodeAndExecuteCommand(uint8_t* data, int size) = 0;
};
}
}



}
6 changes: 3 additions & 3 deletions src/VStabiliserVersion.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define VSTABILISER_MAJOR_VERSION 2
#define VSTABILISER_MINOR_VERSION 4
#define VSTABILISER_PATCH_VERSION 4
#define VSTABILISER_MINOR_VERSION 5
#define VSTABILISER_PATCH_VERSION 0

#define VSTABILISER_VERSION "2.4.4"
#define VSTABILISER_VERSION "2.5.0"
20 changes: 10 additions & 10 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@



/// Link namesapces.
/// Link namespaces.
using namespace cr::vstab;
using namespace std;

Expand Down Expand Up @@ -148,7 +148,7 @@ bool copyTest()
}
if (in.transparentBorder != out.transparentBorder)
{
cout << "in.trasparentBorder" << endl;
cout << "in.transparentBorder" << endl;
return false;
}
if (in.constXOffset != out.constXOffset)
Expand Down Expand Up @@ -296,7 +296,7 @@ bool encodeDecodeTest()
}
if (in.transparentBorder != out.transparentBorder)
{
cout << "in.trasparentBorder" << endl;
cout << "in.transparentBorder" << endl;
return false;
}
if (in.constXOffset != out.constXOffset)
Expand Down Expand Up @@ -467,7 +467,7 @@ bool encodeDecodeWithMaskTest()
}
if (in.transparentBorder != out.transparentBorder)
{
cout << "in.trasparentBorder" << endl;
cout << "in.transparentBorder" << endl;
return false;
}
if (out.constXOffset != 0)
Expand Down Expand Up @@ -538,7 +538,7 @@ bool encodeDecodeCommandsTest()
uint8_t data[1024];
int size = 0;
float outValue = (float)(rand() % 20);
VStabiliser::encodeCommand(data, size, VStabiliserCommand::RESET);
VStabiliser::encodeCommand(data, size, VStabiliserCommand::HOLD_MSEC, 1000);

// Decode command.
VStabiliserCommand commandId;
Expand All @@ -550,10 +550,10 @@ bool encodeDecodeCommandsTest()
return false;
}

// Checkk ID and value.
if (commandId != VStabiliserCommand::RESET)
// Check ID and value.
if (commandId != VStabiliserCommand::HOLD_MSEC || (float)value != 1000)
{
cout << "not a VStabiliserCommand::RESER" << endl;
cout << "not a VStabiliserCommand::HOLD_MSEC" << endl;
return false;
}

Expand All @@ -570,7 +570,7 @@ bool encodeDecodeCommandsTest()
return false;
}

// Checkk ID and value.
// Check ID and value.
if (paramId != VStabiliserParam::X_OFFSET_LIMIT)
{
cout << "not a VStabiliserParam::X_OFFSET_LIMIT" << endl;
Expand Down Expand Up @@ -676,7 +676,7 @@ bool jsonReadWriteTest()
}
if (in.transparentBorder != out.transparentBorder)
{
cout << "in.trasparentBorder" << endl;
cout << "in.transparentBorder" << endl;
return false;
}
if (in.constXOffset != out.constXOffset)
Expand Down

0 comments on commit f39d7e8

Please sign in to comment.