Add singleo_service_add_input_{image_file,rgb_data,raw_data} API support.
Singleo service API has to allow one more input data so add this API series
to add various types of data as input data. In addition, this patch
drops ISingleoCommon, SingleoImageData and SingleoRawData classes and,
introduces a new input manager, SingleoInputManager class which manages
input data queue.
Signed-off-by: Inki Dae <inki.dae@samsung.com>
/**
* @internal
- * @brief Performs the service with a given file name.
+ * @brief Adds a given image file name to the service as a input
*
* @since_tizen 9.0
- * @remarks With this function, the service will be performed with input source given by user as a file name.
+ * @remarks With this function, user can add input image file to the the service before invoking the service.
*
* @param[in] handle The handle to the service.
* @param[in] file_name A file name to be used as input data. It can become one of image files supported by OpenCV.
*
* @pre Create a source handle by calling singleo_service_create()
*/
-int singleo_service_perform_with_file(singleo_service_h handle, const char *file_name);
+int singleo_service_add_input_image_file(singleo_service_h handle, const char *file_name);
/**
* @internal
- * @brief Performs the service with image data information.
+ * @brief Adds a given image data to the service as a input
*
* @since_tizen 9.0
- * @remarks With this function, the service will be performed with raw image data information given by user.
+ * @remarks With this function, user can add input image data to the the service before invoking the service.
*
* @param[in] handle The handle to the service.
* @param[in] buffer A buffer pointer pointing to raw image data.
*
* @pre Create a source handle by calling singleo_service_create()
*/
-int singleo_service_perform_with_image_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
- unsigned int height, unsigned long byte_per_pixel);
+int singleo_service_add_input_image_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
+ unsigned int height, unsigned long byte_per_pixel);
/**
* @internal
- * @brief Performs the service with raw data information.
+ * @brief Adds a given raw data to the service as a input
*
* @since_tizen 9.0
- * @remarks With this function, the service will be performed with raw data information given by user.
+ * @remarks With this function, user can add input raw data to the the service before invoking the service.
*
* @param[in] handle The handle to the service.
* @param[in] buffer A buffer pointer pointing to raw data.
*
* @pre Create a source handle by calling singleo_service_create()
*/
-int singleo_service_perform_with_raw_data(singleo_service_h handle, const unsigned char *buffer,
- unsigned long buffer_size_in_bytes);
+int singleo_service_add_input_raw_data(singleo_service_h handle, const unsigned char *buffer,
+ unsigned long buffer_size_in_bytes);
/**
* @internal
+++ /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 __ISINGLEO_COMMON_DATA_H__
-#define __ISINGLEO_COMMON_DATA_H__
-
-#include "SingleoCommonTypes.h"
-
-namespace singleo
-{
-class ISingleoCommonData
-{
-public:
- virtual ~ISingleoCommonData() {};
-
- virtual void setData(BaseDataType &input_data) = 0;
- virtual BaseDataType &getData() = 0;
-};
-
-} // singleo
-
-#endif
\ No newline at end of file
#define __SINGLEO_COMMON_TYPES_H__
#include <vector>
-#include <string>
-#include <memory>
-#include <map>
namespace singleo
{
+++ /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 __SINGLEO_IMAGE_DATA_H__
-#define __SINGLEO_IMAGE_DATA_H__
-
-#include "ISingleoCommonData.h"
-
-namespace singleo
-{
-class SingleoImageData : public ISingleoCommonData
-{
-private:
- ImageDataType _data;
-
-public:
- SingleoImageData() = default;
- virtual ~SingleoImageData() = default;
-
- void setData(BaseDataType &input_data) override;
- BaseDataType &getData() override;
-};
-
-} // singleo
-
-#endif
--- /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 __SINGLEO_INPUT_MANAGER_H__
+#define __SINGLEO_INPUT_MANAGER_H__
+
+#include <queue>
+#include <mutex>
+#include <memory>
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+class SingleoInputManager
+{
+private:
+ std::queue<std::shared_ptr<BaseDataType> > _queue;
+ std::mutex _queue_mutex;
+
+public:
+ SingleoInputManager() = default;
+ virtual ~SingleoInputManager() = default;
+
+ void enqueue(std::shared_ptr<BaseDataType> input_data);
+ std::shared_ptr<BaseDataType> dequeue();
+ unsigned int size();
+};
+
+} // singleo
+
+#endif
+++ /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 __SINGLEO_RAW_DATA_H__
-#define __SINGLEO_RAW_DATA_H__
-
-#include "ISingleoCommonData.h"
-
-namespace singleo
-{
-class SingleoRawData : public ISingleoCommonData
-{
-private:
- RawDataType _data {};
-
-public:
- SingleoRawData() = default;
- virtual ~SingleoRawData() = default;
-
- void setData(BaseDataType &input_data) override;
- BaseDataType &getData() override;
-};
-
-} // singleo
-
-#endif
+++ /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.
- */
-
-#include "SingleoImageData.h"
-
-using namespace std;
-
-namespace singleo
-{
-void SingleoImageData::setData(BaseDataType &input_data)
-{
- auto image_data = dynamic_cast<ImageDataType &>(input_data);
- _data = image_data;
-}
-
-BaseDataType &SingleoImageData::getData()
-{
- return _data;
-}
-
-}
--- /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.
+ */
+
+#include "SingleoInputManager.h"
+
+using namespace std;
+
+namespace singleo
+{
+void SingleoInputManager::enqueue(shared_ptr<BaseDataType> input_data)
+{
+ std::lock_guard<std::mutex> lock(_queue_mutex);
+ _queue.push(input_data);
+}
+
+shared_ptr<BaseDataType> SingleoInputManager::dequeue()
+{
+ std::lock_guard<std::mutex> lock(_queue_mutex);
+ shared_ptr<BaseDataType> data = _queue.front();
+
+ _queue.pop();
+
+ return data;
+}
+
+unsigned int SingleoInputManager::size()
+{
+ return _queue.size();
+}
+
+}
+++ /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.
- */
-
-#include "SingleoRawData.h"
-
-using namespace std;
-
-namespace singleo
-{
-void SingleoRawData::setData(BaseDataType &input_data)
-{
- auto raw_data = dynamic_cast<RawDataType &>(input_data);
- _data = raw_data;
-}
-
-BaseDataType &SingleoRawData::getData()
-{
- return _data;
-}
-
-}
void configure() override;
void prepare() override;
- void invoke(ISingleoCommonData &input, bool async) override;
+ void invoke(BaseDataType &input, bool async) override;
const SingleoOutputData &result() override;
};
void configure() override;
void prepare() override;
- void invoke(ISingleoCommonData &input, bool async) override;
+ void invoke(BaseDataType &input, bool async) override;
const SingleoOutputData &result() override;
};
*/
#include <stdexcept>
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
#include "MvFaceDetection.h"
#include "SingleoLog.h"
throw runtime_error("Fail to prepare face detection.");
}
-void MvFaceDetection::invoke(ISingleoCommonData &input, bool async)
+void MvFaceDetection::invoke(BaseDataType &input, bool async)
{
- ImageDataType &data = dynamic_cast<ImageDataType &>(input.getData());
+ ImageDataType &data = dynamic_cast<ImageDataType &>(input);
if (data._data_type != DataType::IMAGE) {
SINGLEO_LOGE("Invalid input type.");
*/
#include <stdexcept>
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
#include "MvObjectDetection.h"
#include "SingleoLog.h"
throw runtime_error("Fail to prepare object detection.");
}
-void MvObjectDetection::invoke(ISingleoCommonData &input, bool async)
+void MvObjectDetection::invoke(BaseDataType &input, bool async)
{
- ImageDataType &data = dynamic_cast<ImageDataType &>(input.getData());
+ ImageDataType &data = dynamic_cast<ImageDataType &>(input);
if (data._data_type != DataType::IMAGE) {
SINGLEO_LOGE("Invalid input type.");
#ifndef __IINFERENCE_SERVICE_INTERFACE_H__
#define __IINFERENCE_SERVICE_INTERFACE_H__
-#include "ISingleoCommonData.h"
#include "IInferenceTaskInterface.h"
namespace singleo
virtual void configure() = 0;
virtual void prepare() = 0;
- virtual void invoke(ISingleoCommonData &input, bool async = false) = 0;
+ virtual void invoke(BaseDataType &input, bool async = false) = 0;
virtual const SingleoOutputData &result() = 0;
};
#ifndef __IINFERENCE_TASK_INTERFACE_H__
#define __IINFERENCE_TASK_INTERFACE_H__
-#include "ISingleoCommonData.h"
#include "SingleoOutputData.h"
namespace singleo
virtual void configure() = 0;
virtual void prepare() = 0;
- virtual void invoke(ISingleoCommonData &input, bool async = false) = 0;
+ virtual void invoke(BaseDataType &input, bool async = false) = 0;
virtual const SingleoOutputData &result() = 0;
};
void configure() override;
void prepare() override;
- void invoke(ISingleoCommonData &input, bool async = false) override;
+ void invoke(BaseDataType &input, bool async = false) override;
const SingleoOutputData &result() override;
};
void configure() override;
void prepare() override;
- void invoke(ISingleoCommonData &input, bool async = false) override;
+ void invoke(BaseDataType &input, bool async = false) override;
const SingleoOutputData &result() override;
};
_task->prepare();
}
-void InferenceServiceDefault::invoke(ISingleoCommonData &input, bool async)
+void InferenceServiceDefault::invoke(BaseDataType &input, bool async)
{
_task->invoke(input, async);
}
throw runtime_error("Not support yet.");
}
-void InferenceServiceExternal::invoke(ISingleoCommonData &input, bool async)
+void InferenceServiceExternal::invoke(BaseDataType &input, bool async)
{
throw runtime_error("Not support yet.");
}
#define __ICAMERA_BACKEND_H__
#include <functional>
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
namespace singleo
{
public:
virtual ~ICameraBackend() {};
- virtual void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
- void *user_data) = 0;
+ virtual void setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb, void *user_data) = 0;
virtual void configure() = 0;
- virtual void capture(SingleoImageData &out_data) = 0;
+ virtual void capture(BaseDataType &out_data) = 0;
virtual void streamOn() = 0;
virtual void streamOff() = 0;
};
#include <opencv2/opencv.hpp>
#include "ICameraBackend.h"
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
#include "InputTypes.h"
namespace singleo
void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
void configure() override;
- void capture(SingleoImageData &out_data) override;
+ void capture(BaseDataType &out_data) override;
void streamOn() override;
void streamOff() override;
};
}
}
-void OpencvBackend::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
- void *user_data)
+void OpencvBackend::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb, void *user_data)
{
_userCb = userCb;
_userData = user_data;
}
}
-void OpencvBackend::capture(SingleoImageData &out_data)
+void OpencvBackend::capture(BaseDataType &out_data)
{
+ if (out_data._data_type != DataType::IMAGE)
+ throw InvalidParameter("Invalid data type.");
+
*_video_capture >> _captured_image;
if (_captured_image.empty()) {
SINGLEO_LOGE("Captured frame is empty.");
throw InvalidOperation("Invalid image format.");
}
- ImageDataType image_data;
+ ImageDataType &image_data = dynamic_cast<ImageDataType &>(out_data);
image_data.width = _captured_image.cols;
image_data.height = _captured_image.rows;
image_data.byte_per_pixel = _captured_image.channels();
image_data.ptr = _captured_image.data;
-
- out_data.setData(image_data);
}
void OpencvBackend::threadLoop()
{
SINGLEO_LOGD("OpencvBackend: stream off.");
- SingleoImageData data;
+ ImageDataType data;
while (!_exit_thread) {
capture(data);
void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
void configure() override;
- void capture(ISingleoCommonData &data) override;
+ void capture(BaseDataType &data) override;
void streamOn() override;
void streamOff() override;
};
void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
void configure() override;
- void capture(ISingleoCommonData &data) override;
+ void capture(BaseDataType &data) override;
void streamOn() override;
void streamOff() override;
};
#ifndef __ICAMERA_SERVICE_H__
#define __ICAMERA_SERVICE_H__
-#include "ISingleoCommonData.h"
#include "InputTypes.h"
namespace singleo
virtual void setUserCb(const InputServiceCallbackType &userCb, void *user_data) = 0;
virtual void configure() = 0;
- virtual void capture(ISingleoCommonData &data) = 0;
+ virtual void capture(BaseDataType &data) = 0;
virtual void streamOn() = 0;
virtual void streamOff() = 0;
};
#define __IINPUT_SERVICE_H__
#include <functional>
-#include "ISingleoCommonData.h"
#include "InputTypes.h"
namespace singleo
virtual void setUserCb(const InputServiceCallbackType &userCb, void *user_data) = 0;
virtual void configure() = 0;
- virtual void capture(ISingleoCommonData &data) = 0;
+ virtual void capture(BaseDataType &data) = 0;
virtual void streamOn() = 0;
virtual void streamOff() = 0;
};
void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
void configure() override;
- void capture(ISingleoCommonData &data) override;
+ void capture(BaseDataType &data) override;
void streamOn() override;
void streamOff() override;
};
#include <functional>
#include "SingleoCommonTypes.h"
-#include "ISingleoCommonData.h"
namespace singleo
{
unsigned int y_resolution {};
};
-using InputServiceCallbackType = std::function<void(ISingleoCommonData &data, void *user_data)>;
+using InputServiceCallbackType = std::function<void(BaseDataType &data, void *user_data)>;
} // input
} // singleo
CameraServiceDefault::~CameraServiceDefault()
{}
-void CameraServiceDefault::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+void CameraServiceDefault::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb,
void *user_data)
{
_camera->setUserCb(userCb, user_data);
_camera->configure();
}
-void CameraServiceDefault::capture(ISingleoCommonData &data)
+void CameraServiceDefault::capture(BaseDataType &data)
{
- _camera->capture(dynamic_cast<SingleoImageData &>(data));
+ _camera->capture(data);
}
void CameraServiceDefault::streamOn()
CameraServiceExternal::~CameraServiceExternal()
{}
-void CameraServiceExternal::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+void CameraServiceExternal::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb,
void *user_data)
{}
void CameraServiceExternal::configure()
{}
-void CameraServiceExternal::capture(ISingleoCommonData &data)
+void CameraServiceExternal::capture(BaseDataType &data)
{}
void CameraServiceExternal::streamOn()
#include "InputCamera.h"
#include "CameraServiceDefault.h"
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
#include "SingleoLog.h"
using namespace std;
InputCamera::~InputCamera()
{}
-void InputCamera::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
- void *user_data)
+void InputCamera::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb, void *user_data)
{
_input->setUserCb(userCb, user_data);
}
_input->configure();
}
-void InputCamera::capture(ISingleoCommonData &data)
+void InputCamera::capture(BaseDataType &data)
{
_input->capture(data);
#include "IService.h"
#include "SingleoCommonTypes.h"
#include "IInferenceServiceInterface.h"
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
#include "IInputService.h"
#include "SingleoInferenceTypes.h"
#include "InputTypes.h"
private:
std::unique_ptr<singleo::inference::IInferenceServiceInterface> _inference_service;
std::unique_ptr<singleo::input::IInputService> _input_service;
- std::queue<SingleoImageData> _input_data_q;
+ SingleoInputManager _input_image_data;
AutoZoomResult _result {};
std::map<std::string, AutoZoomResultType> _result_keys = { { "X", AutoZoomResultType::X },
{ "Y", AutoZoomResultType::Y },
// This function will be called by specific input service internally.
// Ps. caller has to provide captured data with concrete class object as data parameter.
- static void inputServiceCb(ISingleoCommonData &data, void *user_data);
- void perform_with_file(BaseDataType &input_data) override;
+ static void inputServiceCb(BaseDataType &data, void *user_data);
+ void add_input(BaseDataType &input_data) override;
void perform() override;
void performAsync() override;
void getResultCnt(unsigned int *cnt) override;
_input_service->streamOff();
}
-void AutoZoom::inputServiceCb(ISingleoCommonData &data, void *user_data)
+void AutoZoom::inputServiceCb(BaseDataType &data, void *user_data)
{
auto auto_zoom = static_cast<AutoZoom *>(user_data);
- ImagePreprocessor preprocessor(data.getData());
+ ImagePreprocessor preprocessor(data);
ImageDataType preprocessed = dynamic_cast<ImageDataType &>(preprocessor.getData());
ImageDataType copied = preprocessed;
size_t buffer_size = copied.width * copied.height * copied.byte_per_pixel;
return true;
}
-void AutoZoom::perform_with_file(BaseDataType &input_data)
+void AutoZoom::add_input(BaseDataType &input_data)
{
- ImagePreprocessor preprocessor(input_data);
- SingleoImageData image_data;
- image_data.setData(preprocessor.getData());
-
- _inference_service->invoke(image_data);
+ // This service allows only one input data per a service request.
+ if (_input_image_data.size() > 0) {
+ SINGLEO_LOGW("This service allows only one input data.");
+ return;
+ }
- updateResult(preprocessor.getData());
+ if (input_data._data_type == DataType::FILE) {
+ FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
+ _input_image_data.enqueue(make_shared<FileDataType>(file_data));
+ } else if (input_data._data_type == DataType::IMAGE) {
+ ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
+ _input_image_data.enqueue(make_shared<ImageDataType>(image_data));
+ } else {
+ throw InvalidParameter("Invalid input data type.");
+ }
}
void AutoZoom::perform()
{
- if (!_input_service) {
- SINGLEO_LOGE("This API is valid only the case that input feed device type is given.");
- throw InvalidOperation("Invalid API request.");
- }
+ ImagePreprocessor preprocessor;
- SingleoImageData captured_image;
-
- _input_service->capture(captured_image);
+ // If input service is not set, input data is from file.
+ if (!_input_service) {
+ shared_ptr<BaseDataType> result = _input_image_data.dequeue();
+ auto data = dynamic_pointer_cast<FileDataType>(result);
- ImagePreprocessor preprocessor(captured_image.getData());
- SingleoImageData preprocessed_image;
+ preprocessor.update(*data);
+ _inference_service->invoke(preprocessor.getData());
+ updateResult(preprocessor.getData());
+ return;
+ } else {
+ ImageDataType input_data;
- preprocessed_image.setData(preprocessor.getData());
- _inference_service->invoke(preprocessed_image);
+ _input_service->capture(input_data);
+ preprocessor.update(input_data);
+ }
+ _inference_service->invoke(preprocessor.getData());
updateResult(preprocessor.getData());
}
_async_mode = true;
_async_manager = make_unique<AsyncManager<ImageDataType, AutoZoomResult> >();
_async_manager->registerInvokeCb(this, [this](IService *service, BaseDataType &data) {
- SingleoImageData input_container;
auto auto_zoom = static_cast<AutoZoom *>(service);
- input_container.setData(data);
- auto_zoom->getInferenceService()->invoke(input_container);
+ auto_zoom->getInferenceService()->invoke(data);
auto_zoom->updateResult(data);
// This buffer was allocated and copied in inputServiceCb callback.
public:
virtual ~IPreprocessor() {};
- virtual void setData(BaseDataType &data) = 0;
+ virtual void update(BaseDataType &input_data) = 0;
virtual BaseDataType &getData() = 0;
};
public:
virtual ~IService() {};
- virtual void perform_with_file(BaseDataType &input_data) = 0;
+ virtual void add_input(BaseDataType &input_data) = 0;
virtual void perform() = 0;
virtual void performAsync() = 0;
virtual void getResultCnt(unsigned int *cnt) = 0;
ImagePreprocessor(BaseDataType &input_data);
virtual ~ImagePreprocessor() = default;
- void setData(BaseDataType &data) override;
+ void update(BaseDataType &input_data) override;
BaseDataType &getData() override;
void drawBox(Rect &rect, unsigned char r, unsigned char g, unsigned char b);
#ifndef __SERVICE_CONFIG_PARSER_H__
#define __SERVICE_CONFIG_PARSER_H__
+#include <map>
+
#include "SingleoCommonTypes.h"
#include "InputTypes.h"
{
ImagePreprocessor::ImagePreprocessor(BaseDataType &input_data)
{
- if (input_data._data_type != DataType::FILE && input_data._data_type != DataType::IMAGE) {
- SINGLEO_LOGE("Invalid data type.");
- throw InvalidParameter("Invalid data type.");
- }
-
- if (input_data._data_type == DataType::FILE) {
- FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
-
- run(file_data._file_name);
- return;
- }
-
- ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
-
- run(image_data);
+ update(input_data);
}
void ImagePreprocessor::run(string file_name)
_cv_image = cv_image;
}
-void ImagePreprocessor::setData(BaseDataType &data)
+void ImagePreprocessor::update(BaseDataType &input_data)
{
- _image_data = dynamic_cast<ImageDataType &>(data);
+ if (input_data._data_type != DataType::FILE && input_data._data_type != DataType::IMAGE) {
+ SINGLEO_LOGE("Invalid data type.");
+ throw InvalidParameter("Invalid data type.");
+ }
+
+ if (input_data._data_type == DataType::FILE) {
+ FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
+
+ run(file_data._file_name);
+ return;
+ }
+
+ ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
+
+ run(image_data);
}
BaseDataType &ImagePreprocessor::getData()
return SINGLEO_ERROR_NONE;
}
-int singleo_service_perform_with_file(singleo_service_h handle, const char *file_name)
+int singleo_service_add_input_image_file(singleo_service_h handle, const char *file_name)
{
try {
auto context = static_cast<Context *>(handle);
FileDataType input_data;
- SINGLEO_LOGD("Inference requested with %s", file_name);
+ SINGLEO_LOGD("Add input image file(%s)", file_name);
+
input_data._file_name = file_name;
- context->_service_handle->perform_with_file(input_data);
+ context->_service_handle->add_input(input_data);
+ } catch (const BaseException &e) {
+ return e.getError();
+ }
+
+ return SINGLEO_ERROR_NONE;
+}
+
+int singleo_service_add_input_image_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
+ unsigned int height, unsigned long byte_per_pixel)
+{
+ try {
+ auto context = static_cast<Context *>(handle);
+ ImageDataType input_data;
+
+ input_data.ptr = const_cast<unsigned char *>(buffer);
+ input_data.width = width;
+ input_data.height = height;
+ input_data.byte_per_pixel = byte_per_pixel;
+ context->_service_handle->add_input(input_data);
+ } catch (const BaseException &e) {
+ return e.getError();
+ }
+
+ return SINGLEO_ERROR_NONE;
+}
+
+int singleo_service_add_input_raw_data(singleo_service_h handle, const unsigned char *buffer,
+ unsigned long buffer_size_in_bytes)
+{
+ try {
+ auto context = static_cast<Context *>(handle);
+ RawDataType input_data;
+
+ input_data.ptr = const_cast<unsigned char *>(buffer);
+ input_data.size_in_bytes = buffer_size_in_bytes;
+ context->_service_handle->add_input(input_data);
} catch (const BaseException &e) {
return e.getError();
}
-add_subdirectory(services)
+ADD_SUBDIRECTORY(services)
int ret = singleo_service_create("service=auto_zoom", &handle);
ASSERT_EQ(ret, SINGLEO_ERROR_NONE);
- ret = singleo_service_perform_with_file(handle, IMG_FACE);
+ ret = singleo_service_add_input_image_file(handle, IMG_FACE);
+ ASSERT_EQ(ret, SINGLEO_ERROR_NONE);
+
+ ret = singleo_service_perform(handle);
ASSERT_EQ(ret, SINGLEO_ERROR_NONE);
unsigned int cnt;
/**
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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.
#ifndef __SINGLEO_UTIL_VISUALIZER_2D_H__
#define __SINGLEO_UTIL_VISUALIZER_2D_H__
-#include <opencv2/opencv.hpp>
-#include <GLES2/gl2.h>
-
#include "singleo_util_render_2d.h"
int singleo_util_visualizer_2d(cv::Mat &source, const char *url);
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
+#include <GLES2/gl2.h>
#include "SingleoLog.h"
#include "singleo_error.h"