Add IPointer and its tizen implementation to control mouse cursor
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 24 Jun 2024 08:26:58 +0000 (17:26 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Mon, 24 Jun 2024 08:26:58 +0000 (17:26 +0900)
Change-Id: I4ec65cb90282a18bf051c64af46aa86ec2a2a520
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
13 files changed:
.vscode/settings.json [new file with mode: 0644]
packaging/singleo.spec
services/CMakeLists.txt
services/smart_pointer/CMakeLists.txt
services/smart_pointer/include/IPointer.h [new file with mode: 0644]
services/smart_pointer/include/PointerActionType.h [new file with mode: 0644]
services/smart_pointer/include/PointerFactory.h [new file with mode: 0644]
services/smart_pointer/include/SmartPointer.h
services/smart_pointer/include/TizenPointer.h [new file with mode: 0644]
services/smart_pointer/src/PointerFactory.cpp [new file with mode: 0644]
services/smart_pointer/src/SmartPointer.cpp
services/smart_pointer/src/TizenPointer.cpp [new file with mode: 0644]
test/services/smartpointer.cpp

diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644 (file)
index 0000000..0dd6678
--- /dev/null
@@ -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
index a08a3acbc4c4160852886ebd5af1a372f3fabf7c..2c447ab11e357a4eeeed53c0ff1238cb869dc2a2 100644 (file)
@@ -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
index c2b3e90e946ab91d119f5aa1589cd07f7cd5e91d..2e2b55771b02cd79bdc5b0d034983d242dfbab88 100644 (file)
@@ -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})
 
index c96f09b758d4dee2753520172b1d264984126691..6171b232c4d71d1dc2948794b8ddc096ea879a2e 100644 (file)
@@ -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 (file)
index 0000000..39e20fe
--- /dev/null
@@ -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 <memory>
+#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 (file)
index 0000000..82326ee
--- /dev/null
@@ -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 (file)
index 0000000..846cf29
--- /dev/null
@@ -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 <memory>
+#include "IPointer.h"
+
+namespace singleo
+{
+namespace services
+{
+namespace smartpointer
+{
+
+class PointerFactory
+{
+public:
+       static std::unique_ptr<IPointer> createTizenPointer();
+};
+} // smartpointer
+} // services
+} // singleo
+
+#endif
\ No newline at end of file
index a9c5a7ee116f01c3cbc022c8976dcb9decdcbe4f..e333a88f33ab9ebd9ee3b37092dc1f02aad7ecaf 100644 (file)
@@ -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<IPointer> _pointer;
+       Point _cursor;
        std::map<std::string, PoseAngle> _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 (file)
index 0000000..255402c
--- /dev/null
@@ -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 <memory>
+#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 (file)
index 0000000..4a282cc
--- /dev/null
@@ -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 <memory>
+#include "PointerFactory.h"
+#include "TizenPointer.h"
+
+using namespace std;
+
+
+namespace singleo
+{
+namespace services
+{
+namespace smartpointer
+{
+unique_ptr<IPointer> PointerFactory::createTizenPointer()
+{
+    return make_unique<TizenPointer>();
+}
+}
+}
+}
\ No newline at end of file
index 2a19011a44077e777a1ed15bea1aa910f037c821..078b7c26047a5c064036e6efc201c400c73c0e5d 100644 (file)
@@ -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<void *>(&(_pointerPosition.pose._rot_vec)),
-                       static_cast<void *>(&gestureResult));
+                       nullptr /*static_cast<void *>(&gestureResult)*/);
                }
        }
 
diff --git a/services/smart_pointer/src/TizenPointer.cpp b/services/smart_pointer/src/TizenPointer.cpp
new file mode 100644 (file)
index 0000000..09e47b1
--- /dev/null
@@ -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
index 81c88e40b1295deb5a91ddf9bc33d4ae0f982e29..47245e7c8f8c97dc6c8108ebdd5c81fd66a2e335 100644 (file)
@@ -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<string *>(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<Point3f *>(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<string *>(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);
 }