Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce safe get python bindings to prevent deallocating none exception #2044

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 62 additions & 0 deletions include/openpose/core/datum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,69 @@ namespace op
*/
Datum clone() const;

/**
* Safe poseKeypoint get function
* If the body poses are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted poseKeypoints if not none, empty list if none
*/
Array<float> getPoseKeypoints();

/**
* Safe poseIds get function
* If the body poses are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted poseIds if not none, empty list if none
*/
Array<float> getPoseIds();

/**
* Safe poseScores get function
* If the body poses are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted poseScores if not none, empty list if none
*/
Array<float> getPoseScores();

/**
* Safe poseHeatMaps get function
* If the body poses are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted poseHeatMaps if not none, empty list if none
*/
Array<float> getPoseHeatMaps();

/**
* Safe faceKeypoints get function
* If the face keypoints are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted faceKeypoints if not none, empty list if none
*/
Array<float> getFaceKeypoints();

/**
* Safe faceHeatMaps get function
* If the face keypoints are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted faceHeatMaps if not none, empty list if none
*/
Array<float> getFaceHeatMaps();

/**
* Safe poseKeypoints3D get function
* If the pose keypoints are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted poseKeypoints3D if not none, empty list if none
*/
Array<float> getPoseKeypoints3D();

/**
* Safe faceKeypoints3D get function
* If the face keypoints are empty, it returns an empty array instead of NULL
* Returning too many NULLs can cause python to die
* @return extracted faceKeypoints3D if not none, empty list if none
*/
Array<float> getFaceKeypoints3D();



Expand Down
8 changes: 8 additions & 0 deletions python/openpose/openpose_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ namespace op
// Datum Object
py::class_<Datum, std::shared_ptr<Datum>>(m, "Datum")
.def(py::init<>())
.def("getPoseKeypoints", &Datum::getPoseKeypoints)
.def("getPoseIds", &Datum::getPoseIds)
.def("getPoseScores", &Datum::getPoseScores)
.def("getPoseHeatMaps", &Datum::getPoseHeatMaps)
.def("getFaceKeypoints", &Datum::getFaceKeypoints)
.def("getFaceHeatMaps", &Datum::getFaceHeatMaps)
.def("getPoseKeypoints3D", &Datum::getPoseKeypoints3D)
.def("getFaceKeypoints3D", &Datum::getFaceKeypoints3D)
.def_readwrite("id", &Datum::id)
.def_readwrite("subId", &Datum::subId)
.def_readwrite("subIdMax", &Datum::subIdMax)
Expand Down
72 changes: 72 additions & 0 deletions src/openpose/core/datum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,78 @@ namespace op
{
}

Array<float> Datum::getPoseKeypoints(){
if(!poseKeypoints.empty()){
return poseKeypoints;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getPoseIds(){
if(!poseIds.empty()){
return poseIds;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getPoseScores(){
if(!poseScores.empty()){
return poseScores;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getPoseHeatMaps(){
if(!poseHeatMaps.empty()){
return poseHeatMaps;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getFaceKeypoints(){
if(!faceKeypoints.empty()){
return faceKeypoints;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getFaceHeatMaps(){
if(!faceHeatMaps.empty()){
return faceHeatMaps;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getPoseKeypoints3D(){
if(!poseKeypoints3D.empty()){
return poseKeypoints3D;
}
else {
return Array<float>(1, -1);
}
}

Array<float> Datum::getFaceKeypoints3D(){
if(!faceKeypoints3D.empty()){
return faceKeypoints3D;
}
else {
return Array<float>(1, -1);
}
}

Datum Datum::clone() const
{
try
Expand Down