From: Tae-Young Chung Date: Mon, 24 Jun 2024 08:26:58 +0000 (+0900) Subject: Add IPointer and its tizen implementation to control mouse cursor X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef19fb9aade32b306856e61e60e1609fe432a594;p=platform%2Fcore%2Fapi%2Fsingleo.git Add IPointer and its tizen implementation to control mouse cursor Change-Id: I4ec65cb90282a18bf051c64af46aa86ec2a2a520 Signed-off-by: Tae-Young Chung --- diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0dd6678 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +{ + "files.associations": { + "*.tcc": "cpp", + "algorithm": "cpp", + "memory": "cpp", + "random": "cpp", + "fstream": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "streambuf": "cpp", + "numeric": "cpp", + "*.txx": "cpp" + } +} \ No newline at end of file diff --git a/packaging/singleo.spec b/packaging/singleo.spec index a08a3ac..2c447ab 100644 --- a/packaging/singleo.spec +++ b/packaging/singleo.spec @@ -20,6 +20,7 @@ BuildRequires: pkgconfig(re2) BuildRequires: pkgconfig(facedetection) BuildRequires: mediapipe-devel BuildRequires: mediapipe-handsolution +BuildRequires: pkgconfig(capi-ui-efl-util) %define enable_autozoom_api 0 %define enable_smartpointer 1 diff --git a/services/CMakeLists.txt b/services/CMakeLists.txt index c2b3e90..2e2b557 100644 --- a/services/CMakeLists.txt +++ b/services/CMakeLists.txt @@ -21,8 +21,13 @@ ENDIF() ADD_LIBRARY(${PROJECT_NAME} SHARED ${SINGLEO_SERVICE_SOURCE_FILES}) -TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include common/include ../capi/ ../input/include ../log/include ../inference/include ../common/include ${SERVICE_HEADER_LIST}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE opencv_imgcodecs opencv_calib3d singleo_log singleo_input ${SERVICE_LIBRARY_LIST}) +SET(dependents "capi-ui-efl-util") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED capi-ui-efl-util) + +TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include common/include ../capi/ ../input/include ../log/include ../inference/include ../common/include ${${PROJECT_NAME}_DEP_INCLUDE_DIRS} ${SERVICE_HEADER_LIST}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE opencv_imgcodecs opencv_calib3d singleo_log singleo_input ${${PROJECT_NAME}_DEP_LIBRARIES} ${SERVICE_LIBRARY_LIST} ) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/services/smart_pointer/CMakeLists.txt b/services/smart_pointer/CMakeLists.txt index c96f09b..6171b23 100644 --- a/services/smart_pointer/CMakeLists.txt +++ b/services/smart_pointer/CMakeLists.txt @@ -6,6 +6,8 @@ SET(SINGLEO_SERVICE_SOURCE_FILES smart_pointer/src/FaceShapeModelManager.cpp smart_pointer/src/HeadPoseEstimator.cpp smart_pointer/src/CameraParamManager.cpp + smart_pointer/src/PointerFactory.cpp + smart_pointer/src/TizenPointer.cpp ) LIST(APPEND SERVICE_LIBRARY_LIST singleo_inference) \ No newline at end of file diff --git a/services/smart_pointer/include/IPointer.h b/services/smart_pointer/include/IPointer.h new file mode 100644 index 0000000..39e20fe --- /dev/null +++ b/services/smart_pointer/include/IPointer.h @@ -0,0 +1,40 @@ +/** + * 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_INTERFACE_POINTER_H_ +#define __SMART_POINTER_INTERFACE_POINTER_H_ + +#include +#include "PointerActionType.h" + +namespace singleo +{ +namespace services +{ +namespace smartpointer +{ + +class IPointer +{ +public: + virtual ~IPointer() {}; + virtual int sendMouseEvent(int x, int y, ActionType type) = 0; +}; +} // smartpointer +} // services +} // singleo + +#endif \ No newline at end of file diff --git a/services/smart_pointer/include/PointerActionType.h b/services/smart_pointer/include/PointerActionType.h new file mode 100644 index 0000000..82326ee --- /dev/null +++ b/services/smart_pointer/include/PointerActionType.h @@ -0,0 +1,35 @@ +/** + * 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_POINTER_ACTION_TYPE_H_ +#define __SMART_POINTER_POINTER_ACTION_TYPE_H_ + +namespace singleo +{ +namespace services +{ +namespace smartpointer +{ + +enum class ActionType +{ + POINTER_MOVE = 0 +}; +} // smartpointer +} // services +} // singleo + +#endif \ No newline at end of file diff --git a/services/smart_pointer/include/PointerFactory.h b/services/smart_pointer/include/PointerFactory.h new file mode 100644 index 0000000..846cf29 --- /dev/null +++ b/services/smart_pointer/include/PointerFactory.h @@ -0,0 +1,39 @@ +/** + * 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_POINTER_FACTORY_H__ +#define __SMART_POINTER_POINTER_FACTORY_H__ + +#include +#include "IPointer.h" + +namespace singleo +{ +namespace services +{ +namespace smartpointer +{ + +class PointerFactory +{ +public: + static std::unique_ptr createTizenPointer(); +}; +} // smartpointer +} // services +} // singleo + +#endif \ No newline at end of file diff --git a/services/smart_pointer/include/SmartPointer.h b/services/smart_pointer/include/SmartPointer.h index a9c5a7e..e333a88 100644 --- a/services/smart_pointer/include/SmartPointer.h +++ b/services/smart_pointer/include/SmartPointer.h @@ -26,6 +26,7 @@ #include "InputCamera.h" #include "AsyncManager.h" #include "SmartPointerDataType.h" +#include "IPointer.h" namespace singleo { @@ -42,6 +43,8 @@ private: SingleoInputManager _input_image_data; PoseVector _head_pose; PointerPosition _pointerPosition; + std::unique_ptr _pointer; + Point _cursor; std::map _result_keys = { { "PITCH", PoseAngle::PITCH }, { "YAW", PoseAngle::YAW }, { "ROLL", PoseAngle::ROLL } }; diff --git a/services/smart_pointer/include/TizenPointer.h b/services/smart_pointer/include/TizenPointer.h new file mode 100644 index 0000000..255402c --- /dev/null +++ b/services/smart_pointer/include/TizenPointer.h @@ -0,0 +1,47 @@ +/** + * 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_TIZEN_POINTER_H_ +#define __SMART_POINTER_TIZEN_POINTER_H_ + +#include +#include "IPointer.h" +#include "PointerActionType.h" +#include "efl_util.h" + +namespace singleo +{ +namespace services +{ +namespace smartpointer +{ + +class TizenPointer: public IPointer +{ +private: + efl_util_inputgen_h _pointer; + +public: + TizenPointer(); + virtual ~TizenPointer(); + + int sendMouseEvent(int x, int y, ActionType type) override; +}; +} // smartpointer +} // services +} // singleo + +#endif \ No newline at end of file diff --git a/services/smart_pointer/src/PointerFactory.cpp b/services/smart_pointer/src/PointerFactory.cpp new file mode 100644 index 0000000..4a282cc --- /dev/null +++ b/services/smart_pointer/src/PointerFactory.cpp @@ -0,0 +1,36 @@ +/** + * 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. + */ + +#include +#include "PointerFactory.h" +#include "TizenPointer.h" + +using namespace std; + + +namespace singleo +{ +namespace services +{ +namespace smartpointer +{ +unique_ptr PointerFactory::createTizenPointer() +{ + return make_unique(); +} +} +} +} \ No newline at end of file diff --git a/services/smart_pointer/src/SmartPointer.cpp b/services/smart_pointer/src/SmartPointer.cpp index 2a19011..078b7c2 100644 --- a/services/smart_pointer/src/SmartPointer.cpp +++ b/services/smart_pointer/src/SmartPointer.cpp @@ -21,6 +21,7 @@ #include "ImagePreprocessor.h" #include "SmartPointer.h" #include "GazeEstimator.h" +#include "PointerFactory.h" using namespace std; using namespace singleo::input; @@ -49,6 +50,9 @@ SmartPointer::SmartPointer(InputConfigBase& config) _async_mode = false; + _pointer = PointerFactory::createTizenPointer(); + _cursor.x = 100; + _cursor.y = 100; } SmartPointer::~SmartPointer() @@ -112,14 +116,15 @@ void SmartPointer::perform() _data_feeder->capture(input_data); preprocessor.update(input_data); _head_pose = _gaze_estimator->estimateHeadpose(preprocessor.getData()); - auto gestureResult = _gesture_recognizer->recognizeGesture(preprocessor.getData()); + // auto gestureResult = _gesture_recognizer->recognizeGesture(preprocessor.getData()); + _pointer->sendMouseEvent(_cursor.x++ % 640, _cursor.y++ % 480, ActionType::POINTER_MOVE); updateResult(_head_pose); if (_user_cb) { SINGLEO_LOGD("user callback in perform()"); _user_cb(input_data.ptr, input_data.width, input_data.height, input_data.byte_per_pixel, static_cast(&(_pointerPosition.pose._rot_vec)), - static_cast(&gestureResult)); + nullptr /*static_cast(&gestureResult)*/); } } diff --git a/services/smart_pointer/src/TizenPointer.cpp b/services/smart_pointer/src/TizenPointer.cpp new file mode 100644 index 0000000..09e47b1 --- /dev/null +++ b/services/smart_pointer/src/TizenPointer.cpp @@ -0,0 +1,45 @@ +/** + * 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. + */ + +#include "TizenPointer.h" + +using namespace std; + +namespace singleo +{ +namespace services +{ +namespace smartpointer +{ +TizenPointer::TizenPointer() +{ + _pointer = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_POINTER); +} + +TizenPointer::~TizenPointer() +{ + efl_util_input_deinitialize_generator(_pointer); +} + +int TizenPointer::sendMouseEvent(int x, int y, ActionType type) +{ + if (type == ActionType::POINTER_MOVE) + efl_util_input_generate_pointer(_pointer, 1, EFL_UTIL_INPUT_POINTER_MOVE, x, y); + return 0; +} +} +} +} \ No newline at end of file diff --git a/test/services/smartpointer.cpp b/test/services/smartpointer.cpp index 81c88e4..47245e7 100644 --- a/test/services/smartpointer.cpp +++ b/test/services/smartpointer.cpp @@ -59,13 +59,15 @@ void data_feeder_cb(unsigned char *buffer, unsigned int width, unsigned int heig cv::Mat vizData; cv::cvtColor(result, vizData, cv::COLOR_BGR2RGBA); - string *gesture_str = static_cast(gesture); - cv::putText(vizData, *gesture_str, cv::Point(30, 30), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 0, 255), 2); - Point3f *dof3d = static_cast(headPose); - cout << "[Pitch, Yaw, Roll]: [ " << dof3d->x << ", " << dof3d->y << ", " << dof3d->z << " ]" << endl; - cout << "[Gesture Str]: " << *gesture_str << endl; + + if (gesture) { + string *gesture_str = static_cast(gesture); + cv::putText(vizData, *gesture_str, cv::Point(30, 30), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 0, 255), 2); + cout << "[Gesture Str]: " << *gesture_str << endl; + } + singleo_util_visualizer_2d(vizData, NULL); }