unsigned int z {};
};
+struct Pointi {
+ int x {};
+ int y {};
+ int z {};
+};
+
using VecRect = std::vector<Rect>;
enum class DataType { NONE, FILE, IMAGE, RAW };
smart_pointer/src/PointerFactory.cpp
smart_pointer/src/TizenPointer.cpp
smart_pointer/src/DisplayInfo.cpp
+ smart_pointer/src/VelociMeter.cpp
)
LIST(APPEND SERVICE_LIBRARY_LIST singleo_inference)
\ No newline at end of file
class DisplayInfo
{
private:
- int _physicalWidth;
- int _physicalHeight;
+ float _physicalWidth;
+ float _physicalHeight;
int _resolutionWidth;
int _resolutionHeight;
+ float _pixelWPerInch;
+ float _pixelHPerInch;
+
public:
DisplayInfo();
- std::tuple<int, int> getPhysicalSize();
+ std::tuple<float, float> getPhysicalSize();
std::tuple<int, int> getResolutionSize();
+ std::tuple<float, float> getPixelPerInch();
};
} // smartpointer
} // services
#include "SmartPointerDataType.h"
#include "IPointer.h"
#include "DisplayInfo.h"
+#include "VelociMeter.h"
namespace singleo
{
PoseVector _head_pose;
PointerPosition _pointerPosition;
std::unique_ptr<IPointer> _pointer;
- Point _cursor;
+ Pointi _cursor;
+ Pointi _resetCursorPosition;
DisplayInfo _displayInfo;
+ VelociMeter _velocimeter;
std::map<std::string, PoseAngle> _result_keys = { { "PITCH", PoseAngle::PITCH },
{ "YAW", PoseAngle::YAW },
{ "ROLL", PoseAngle::ROLL } };
--- /dev/null
+/**
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef __SMART_POINTER_VELOCIMETER_H__
+#define __SMART_POINTER_VELOCIMETER_H__
+
+#include <queue>
+#include <tuple>
+
+namespace singleo
+{
+namespace services
+{
+namespace smartpointer
+{
+class VelociMeter
+{
+private:
+ float _radiusXmm;
+ float _radiusYmm;
+ int _maxCapacity;
+ std::queue<std::tuple<float, float>> _measuredValue;
+
+public:
+ VelociMeter();
+ ~VelociMeter() = default;
+ std::tuple<float, float> measure(float valueX, float valueY);
+};
+} // smartpointer
+} // services
+} // singleo
+#endif
\ No newline at end of file
{
namespace smartpointer
{
-DisplayInfo::DisplayInfo() : _physicalWidth(510),
- _physicalHeight(290),
+DisplayInfo::DisplayInfo() : _physicalWidth(510.f),
+ _physicalHeight(290.f),
_resolutionWidth(1920),
_resolutionHeight(1080)
{
-
+ // TODO: read display information file
+ _pixelWPerInch = _resolutionWidth/ _physicalWidth;
+ _pixelHPerInch = _physicalHeight/ _physicalHeight;
}
-tuple<int, int> DisplayInfo::getPhysicalSize()
+tuple<float, float> DisplayInfo::getPhysicalSize()
{
return {_physicalWidth, _physicalHeight};
}
{
return {_resolutionWidth, _resolutionHeight};
}
+
+std::tuple<float, float> DisplayInfo::getPixelPerInch()
+{
+ return {_pixelWPerInch, _pixelHPerInch};
+}
}
}
}
\ No newline at end of file
timer.reset();
cv::solvePnPRansac(_landmarks_3d, _landmarks_2d,
_camera_matrix, _camera_dist_coeff,
- _rotation_vector, _translation_vector, false, 100, 8.0F, 0.99, cv::noArray(), cv::SOLVEPNP_EPNP);
+ _rotation_vector, _translation_vector, false, 100, 3.0F, 0.99, cv::noArray(), cv::SOLVEPNP_EPNP);
SINGLEO_LOGI("1st solvePnP takes %d ms", timer.check_ms());
timer.reset();
#include <memory>
#include <variant>
+#include <algorithm>
#include "ServiceFactory.h"
#include "SingleoLog.h"
#include "SingleoException.h"
_pointer = PointerFactory::createTizenPointer();
- _cursor.x = get<0>(_displayInfo.getResolutionSize());
- _cursor.y = get<1>(_displayInfo.getResolutionSize());
+ _resetCursorPosition.x = get<0>(_displayInfo.getResolutionSize()) >> 1;
+ _resetCursorPosition.y = get<1>(_displayInfo.getResolutionSize()) >> 1;
+ _cursor.x = _resetCursorPosition.x;
+ _cursor.y = _resetCursorPosition.y;
}
SmartPointer::~SmartPointer()
// auto gestureResult = _gesture_recognizer->recognizeGesture(preprocessor.getData());
updateResult(_head_pose);
- _cursor.x = ++_cursor.x % get<0>(_displayInfo.getResolutionSize());
- _cursor.y = ++_cursor.y % get<1>(_displayInfo.getResolutionSize());
+
+ auto velocity = _velocimeter.measure(_pointerPosition.pose._rot_vec.y,
+ _pointerPosition.pose._rot_vec.x);
+
+ SINGLEO_LOGD("(CurX, CurY): (%4d, %4d) - Angular Velocity: %.4f, %.4f"
+ , _cursor.x, _cursor.y
+ , get<0>(velocity), get<1>(velocity));
+ auto deltaX = get<0>(velocity) * get<0>(_displayInfo.getPixelPerInch());
+ auto deltaY = get<1>(velocity) * get<1>(_displayInfo.getPixelPerInch());
+
+ _cursor.x = static_cast<int>(static_cast<float>(_cursor.x) + deltaX);
+ _cursor.x = min(max(_cursor.x, 0), get<0>(_displayInfo.getResolutionSize()));
+
+ _cursor.y = static_cast<int>(static_cast<float>(_cursor.y) + 3.f * deltaY);
+ _cursor.y = min(max(_cursor.y, 0), get<1>(_displayInfo.getResolutionSize()));
+ SINGLEO_LOGD("(CurX, CurY): (%4d, %4d)", _cursor.x, _cursor.y);
_pointer->sendMouseEvent(_cursor.x, _cursor.y, ActionType::POINTER_MOVE);
--- /dev/null
+
+#include "cmath"
+#include "VelociMeter.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace services
+{
+namespace smartpointer
+{
+VelociMeter::VelociMeter()
+{
+ _maxCapacity = 10;
+ _radiusXmm = 400.f;
+ _radiusYmm = 400.f;
+}
+
+tuple<float, float> VelociMeter::measure(float valueX, float valueY)
+{
+ _measuredValue.push( {valueX, valueY} );
+ if (_measuredValue.size() < _maxCapacity)
+ return { 0.0f, 0.0f };
+
+ auto diffX = fabs(get<0>(_measuredValue.back()) - get<0>(_measuredValue.front()));
+ auto diffY = fabs(get<1>(_measuredValue.back()) - get<1>(_measuredValue.front()));
+
+ auto velocityX = diffX < 0.02f ? 0.0f : (get<0>(_measuredValue.back()) - get<0>(_measuredValue.front())) / static_cast<float>(_maxCapacity);
+ auto velocityY = diffY < 0.02f ? 0.0f : (get<1>(_measuredValue.back()) - get<1>(_measuredValue.front())) / static_cast<float>(_maxCapacity);
+ _measuredValue.pop();
+
+ return { -velocityX * _radiusXmm, velocityY * _radiusYmm };
+}
+} // smartpointer
+} // services
+} // singleo
\ No newline at end of file