Avoid void* for the sake of forward declaration
This commit is contained in:
parent
281199e278
commit
092e1ad899
|
@ -1,14 +1,14 @@
|
||||||
|
#include "pose_tracking.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "pose_tracking.h"
|
|
||||||
|
|
||||||
#include "absl/flags/flag.h"
|
#include "absl/flags/flag.h"
|
||||||
#include "absl/flags/parse.h"
|
#include "absl/flags/parse.h"
|
||||||
#include "mediapipe/framework/formats/landmark.pb.h"
|
|
||||||
#include "mediapipe/framework/calculator_framework.h"
|
#include "mediapipe/framework/calculator_framework.h"
|
||||||
#include "mediapipe/framework/formats/image_frame.h"
|
#include "mediapipe/framework/formats/image_frame.h"
|
||||||
#include "mediapipe/framework/formats/image_frame_opencv.h"
|
#include "mediapipe/framework/formats/image_frame_opencv.h"
|
||||||
|
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||||
#include "mediapipe/framework/port/file_helpers.h"
|
#include "mediapipe/framework/port/file_helpers.h"
|
||||||
#include "mediapipe/framework/port/opencv_highgui_inc.h"
|
#include "mediapipe/framework/port/opencv_highgui_inc.h"
|
||||||
#include "mediapipe/framework/port/opencv_imgproc_inc.h"
|
#include "mediapipe/framework/port/opencv_imgproc_inc.h"
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
#include "mediapipe/framework/port/status.h"
|
#include "mediapipe/framework/port/status.h"
|
||||||
|
|
||||||
class PoseTrackingImpl {
|
class PoseTrackingImpl {
|
||||||
public:
|
public:
|
||||||
PoseTrackingImpl(const std::string& calculatorGraphConfigFile) {
|
PoseTrackingImpl(const std::string& calculatorGraphConfigFile) {
|
||||||
auto status = initialize(calculatorGraphConfigFile);
|
auto status = initialize(calculatorGraphConfigFile);
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
|
@ -27,13 +27,10 @@ public:
|
||||||
|
|
||||||
absl::Status initialize(const std::string& calculatorGraphConfigFile) {
|
absl::Status initialize(const std::string& calculatorGraphConfigFile) {
|
||||||
std::string graphContents;
|
std::string graphContents;
|
||||||
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
|
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(calculatorGraphConfigFile, &graphContents));
|
||||||
calculatorGraphConfigFile,
|
|
||||||
&graphContents));
|
|
||||||
|
|
||||||
mediapipe::CalculatorGraphConfig config =
|
mediapipe::CalculatorGraphConfig config =
|
||||||
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(
|
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(graphContents);
|
||||||
graphContents);
|
|
||||||
|
|
||||||
MP_RETURN_IF_ERROR(graph.Initialize(config));
|
MP_RETURN_IF_ERROR(graph.Initialize(config));
|
||||||
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller poller,
|
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller poller,
|
||||||
|
@ -45,14 +42,13 @@ public:
|
||||||
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller posePresencePoller,
|
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller posePresencePoller,
|
||||||
graph.AddOutputStreamPoller(kOutpuPosePresenceStream));
|
graph.AddOutputStreamPoller(kOutpuPosePresenceStream));
|
||||||
|
|
||||||
|
|
||||||
maskPollerPtr = std::make_unique<mediapipe::OutputStreamPoller>(std::move(poller));
|
maskPollerPtr = std::make_unique<mediapipe::OutputStreamPoller>(std::move(poller));
|
||||||
|
|
||||||
landmarksPollerPtr = std::make_unique<mediapipe::OutputStreamPoller>(
|
landmarksPollerPtr =
|
||||||
std::move(landmarksPoller));
|
std::make_unique<mediapipe::OutputStreamPoller>(std::move(landmarksPoller));
|
||||||
|
|
||||||
posePresencePollerPtr = std::make_unique<mediapipe::OutputStreamPoller>(
|
posePresencePollerPtr =
|
||||||
std::move(posePresencePoller));
|
std::make_unique<mediapipe::OutputStreamPoller>(std::move(posePresencePoller));
|
||||||
|
|
||||||
MP_RETURN_IF_ERROR(graph.StartRun({}));
|
MP_RETURN_IF_ERROR(graph.StartRun({}));
|
||||||
}
|
}
|
||||||
|
@ -69,8 +65,8 @@ public:
|
||||||
size_t frameTimestampUs =
|
size_t frameTimestampUs =
|
||||||
static_cast<double>(cv::getTickCount()) / static_cast<double>(cv::getTickFrequency()) * 1e6;
|
static_cast<double>(cv::getTickCount()) / static_cast<double>(cv::getTickFrequency()) * 1e6;
|
||||||
auto status = graph.AddPacketToInputStream(
|
auto status = graph.AddPacketToInputStream(
|
||||||
kInputStream, mediapipe::Adopt(inputFrame.release())
|
kInputStream,
|
||||||
.At(mediapipe::Timestamp(frameTimestampUs)));
|
mediapipe::Adopt(inputFrame.release()).At(mediapipe::Timestamp(frameTimestampUs)));
|
||||||
|
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
LOG(WARNING) << "Graph execution failed: " << status;
|
LOG(WARNING) << "Graph execution failed: " << status;
|
||||||
|
@ -91,8 +87,7 @@ public:
|
||||||
auto& outputFrame = maskPacket.Get<mediapipe::ImageFrame>();
|
auto& outputFrame = maskPacket.Get<mediapipe::ImageFrame>();
|
||||||
|
|
||||||
// Get pose landmarks.
|
// Get pose landmarks.
|
||||||
if (!landmarksPollerPtr ||
|
if (!landmarksPollerPtr || !landmarksPollerPtr->Next(&poseLandmarksPacket)) {
|
||||||
!landmarksPollerPtr->Next(&poseLandmarksPacket)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,16 +100,12 @@ public:
|
||||||
return landmarksStatus.ok();
|
return landmarksStatus.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status detectLandmarksWithStatus(
|
absl::Status detectLandmarksWithStatus(nimagna::cv_wrapper::Point3f* poseLandmarks) {
|
||||||
nimagna::cv_wrapper::Point3f* poseLandmarks) {
|
|
||||||
|
|
||||||
if (poseLandmarksPacket.IsEmpty()) {
|
if (poseLandmarksPacket.IsEmpty()) {
|
||||||
return absl::CancelledError("Pose landmarks packet is empty.");
|
return absl::CancelledError("Pose landmarks packet is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto retrievedLandmarks =
|
auto retrievedLandmarks = poseLandmarksPacket.Get<::mediapipe::NormalizedLandmarkList>();
|
||||||
poseLandmarksPacket
|
|
||||||
.Get<::mediapipe::NormalizedLandmarkList>();
|
|
||||||
|
|
||||||
// Convert landmarks to cv::Point3f**.
|
// Convert landmarks to cv::Point3f**.
|
||||||
const auto landmarksCount = retrievedLandmarks.landmark_size();
|
const auto landmarksCount = retrievedLandmarks.landmark_size();
|
||||||
|
@ -129,17 +120,13 @@ public:
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
nimagna::cv_wrapper::Point3f* lastDetectedLandmarks() {
|
nimagna::cv_wrapper::Point3f* lastDetectedLandmarks() { return poseLandmarks; }
|
||||||
return poseLandmarks;
|
|
||||||
}
|
|
||||||
|
|
||||||
cv::Mat lastSegmentedFrame() {
|
cv::Mat lastSegmentedFrame() { return segmentedMask; }
|
||||||
return segmentedMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr size_t kLandmarksCount = 33u;
|
static constexpr size_t kLandmarksCount = 33u;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mediapipe::Packet poseLandmarksPacket;
|
mediapipe::Packet poseLandmarksPacket;
|
||||||
cv::Mat segmentedMask;
|
cv::Mat segmentedMask;
|
||||||
nimagna::cv_wrapper::Point3f poseLandmarks[kLandmarksCount];
|
nimagna::cv_wrapper::Point3f poseLandmarks[kLandmarksCount];
|
||||||
|
@ -154,23 +141,23 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace nimagna {
|
namespace nimagna {
|
||||||
PoseTracking::PoseTracking(const char* calculatorGraphConfigFile) {
|
PoseTracking::PoseTracking(const char* calculatorGraphConfigFile) {
|
||||||
mImplementation = new PoseTrackingImpl(calculatorGraphConfigFile);
|
mImplementation = new PoseTrackingImpl(calculatorGraphConfigFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PoseTracking::processFrame(const cv_wrapper::Mat& inputRGB8Bit) {
|
bool PoseTracking::processFrame(const cv_wrapper::Mat& inputRGB8Bit) {
|
||||||
const auto frame = cv::Mat(inputRGB8Bit.rows, inputRGB8Bit.cols, CV_8UC3, inputRGB8Bit.data);
|
const auto frame = cv::Mat(inputRGB8Bit.rows, inputRGB8Bit.cols, CV_8UC3, inputRGB8Bit.data);
|
||||||
return mImplementation->processFrame(frame);
|
return mImplementation->processFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
cv_wrapper::Point3f* PoseTracking::lastDetectedLandmarks() {
|
cv_wrapper::Point3f* PoseTracking::lastDetectedLandmarks() {
|
||||||
return mImplementation->lastDetectedLandmarks();
|
return mImplementation->lastDetectedLandmarks();
|
||||||
}
|
}
|
||||||
|
|
||||||
cv_wrapper::Mat PoseTracking::lastSegmentedFrame() {
|
cv_wrapper::Mat PoseTracking::lastSegmentedFrame() {
|
||||||
const cv::Mat result = mImplementation->lastSegmentedFrame();
|
const cv::Mat result = mImplementation->lastSegmentedFrame();
|
||||||
|
|
||||||
return cv_wrapper::Mat(result.rows, result.cols, result.data);
|
return cv_wrapper::Mat(result.rows, result.cols, result.data);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace nimagna
|
||||||
|
|
|
@ -10,24 +10,24 @@
|
||||||
class PoseTrackingImpl;
|
class PoseTrackingImpl;
|
||||||
|
|
||||||
namespace nimagna {
|
namespace nimagna {
|
||||||
namespace cv_wrapper {
|
namespace cv_wrapper {
|
||||||
struct Point2f {
|
struct Point2f {
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
|
|
||||||
Point2f() = default;
|
Point2f() = default;
|
||||||
Point2f(float x, float y) : x(x), y(y) {}
|
Point2f(float x, float y) : x(x), y(y) {}
|
||||||
};
|
};
|
||||||
struct Point3f {
|
struct Point3f {
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
float z = 0;
|
float z = 0;
|
||||||
|
|
||||||
Point3f() = default;
|
Point3f() = default;
|
||||||
Point3f(float x, float y, float z) : x(x), y(y), z(z) {}
|
Point3f(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Rect {
|
struct Rect {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
@ -35,18 +35,18 @@ namespace nimagna {
|
||||||
|
|
||||||
Rect() = default;
|
Rect() = default;
|
||||||
Rect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {}
|
Rect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mat {
|
struct Mat {
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
int cols = 0;
|
int cols = 0;
|
||||||
unsigned char* data = 0;
|
unsigned char* data = 0;
|
||||||
|
|
||||||
Mat(int rows, int cols, unsigned char* data) : rows(rows), cols(cols), data(data) {}
|
Mat(int rows, int cols, unsigned char* data) : rows(rows), cols(cols), data(data) {}
|
||||||
};
|
};
|
||||||
}
|
} // namespace cv_wrapper
|
||||||
|
|
||||||
class DLLEXPORT PoseTracking {
|
class DLLEXPORT PoseTracking {
|
||||||
public:
|
public:
|
||||||
static constexpr size_t landmarksCount = 33u;
|
static constexpr size_t landmarksCount = 33u;
|
||||||
enum LandmarkNames {
|
enum LandmarkNames {
|
||||||
|
@ -95,7 +95,7 @@ namespace nimagna {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PoseTrackingImpl* mImplementation;
|
PoseTrackingImpl* mImplementation;
|
||||||
};
|
};
|
||||||
}
|
} // namespace nimagna
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user