Skip to content

Instantly share code, notes, and snippets.

@cjhgo
Created August 22, 2024 16:03
Show Gist options
  • Select an option

  • Save cjhgo/a2f11cb21d8f53d51d2b4eea694ffc60 to your computer and use it in GitHub Desktop.

Select an option

Save cjhgo/a2f11cb21d8f53d51d2b4eea694ffc60 to your computer and use it in GitHub Desktop.
#include <rockx/rockx.h>
#include <opencv2/opencv.hpp>
#include <functional>
#include <cstring>
namespace rockx {
enum class RockxModule {
OBJECT_DETECTION = ROCKX_MODULE_OBJECT_DETECTION,
OBJECT_TRACK = ROCKX_MODULE_OBJECT_TRACK,
POSE_FINGER_3 = ROCKX_MODULE_POSE_FINGER_3,
POSE_FINGER_21 = ROCKX_MODULE_POSE_FINGER_21,
POSE_BODY = ROCKX_MODULE_POSE_BODY,
POSE_BODYV2 = ROCKX_MODULE_POSE_BODY_V2,
};
void finger_postprocess(rockx_keypoints_t& finger, rockx_image_t& input_image);
void bodyv1_postprocess(rockx_keypoints_array_t& body, rockx_image_t& input_image);
void bodyv2_postprocess(rockx_keypoints_array_t& body, rockx_image_t& input_image);
template <typename KeyType>
using AlgoFunc = std::function<rockx_ret_t(rockx_handle_t, rockx_image_t*, KeyType*)>;
template <typename KeyType>
using PostProcessFunc = std::function<void(KeyType&, rockx_image_t&)>;
template <RockxModule module>
struct RockxPipe;
template <>
struct RockxPipe<RockxModule::POSE_FINGER_3> {
using KeyType = rockx_keypoints_t;
inline static AlgoFunc<KeyType> algo_func = rockx_pose_finger;
inline static PostProcessFunc<KeyType> post_process_func = finger_postprocess;
};
template <>
struct RockxPipe<RockxModule::POSE_FINGER_21> : RockxPipe<RockxModule::POSE_FINGER_3> {};
template <>
struct RockxPipe<RockxModule::POSE_BODY> {
using KeyType = rockx_keypoints_array_t;
inline static AlgoFunc<KeyType> algo_func = [](rockx_handle_t handle, rockx_image_t* input_image,
rockx_keypoints_array_t* keys) {
return rockx_pose_body(handle, input_image, keys, nullptr);
};
inline static PostProcessFunc<KeyType> post_process_func = bodyv1_postprocess;
};
template <>
struct RockxPipe<RockxModule::POSE_BODYV2> {
using KeyType = rockx_keypoints_array_t;
inline static AlgoFunc<KeyType> algo_func = [](rockx_handle_t handle, rockx_image_t* input_image,
rockx_keypoints_array_t* keys) {
return rockx_pose_body(handle, input_image, keys, nullptr);
};
inline static PostProcessFunc<KeyType> post_process_func = bodyv2_postprocess;
};
template <RockxModule module>
int rockx_process_image(rockx_handle_t& handle, rockx_image_t& input_image) {
typename RockxPipe<module>::KeyType keys;
std::memset(&keys, 0, sizeof(typename RockxPipe<module>::KeyType));
rockx_ret_t ret = RockxPipe<module>::algo_func(handle, &input_image, &keys);
if (ret != ROCKX_RET_SUCCESS) {
// Handle error
return ret;
}
RockxPipe<module>::post_process_func(keys, input_image);
return ret;
}
} // namespace rockx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment