fix(hand): pose3d/mediapipe palmobject.landmarks wrong malloc

This commit is contained in:
Syd Xu 2022-02-07 17:29:30 +08:00
parent 9c1a2dd8f4
commit a77aaa2798
5 changed files with 3210 additions and 3188 deletions

View File

@ -43,6 +43,7 @@ func main() {
// }
d3d := mediapipe(modelPath)
detect3d(d3d, imgPath, fontPath, "hand1.jpg")
detect3d(d3d, imgPath, fontPath, "hand2.jpg")
}
func yolox(modelPath string) detecter.Detecter {

File diff suppressed because it is too large Load Diff

View File

@ -19,9 +19,12 @@
#ifndef SVM_LEARN
#define SVM_LEARN
#include "svm_common.h"
#ifdef __cplusplus
extern "C" {
#endif
void svm_learn_classification(DOC **, double *, long, long, LEARN_PARM *,
KERNEL_PARM *, KERNEL_CACHE *, MODEL *, double *);
void svm_learn_regression(DOC **, double *, long, long, LEARN_PARM *,

View File

@ -53,6 +53,8 @@ int mediapipe_hand_detect(IHandPose3DEstimator d, const unsigned char *rgbdata,
int ret = static_cast<ovhand3d::MediapipeHand *>(d)->Detect(
rgbdata, img_width, img_height, objs);
if (ret != 0) {
objects->length = 0;
objects->items = NULL;
return ret;
}
const size_t total_objs = objs.size();
@ -61,6 +63,7 @@ int mediapipe_hand_detect(IHandPose3DEstimator d, const unsigned char *rgbdata,
objects->items = NULL;
return 0;
}
objects->items = (PalmObject *)malloc(total_objs * sizeof(PalmObject));
for (size_t i = 0; i < total_objs; ++i) {
objects->items[i].score = objs[i].score;
@ -75,7 +78,7 @@ int mediapipe_hand_detect(IHandPose3DEstimator d, const unsigned char *rgbdata,
(Point2fVector *)malloc(sizeof(Point2fVector));
objects->items[i].landmarks->length = 7;
objects->items[i].landmarks->points =
(Point2f *)malloc(4 * sizeof(Point2f));
(Point2f *)malloc(7 * sizeof(Point2f));
for (size_t j = 0; j < 7; ++j) {
objects->items[i].landmarks->points[j] = objs[i].landmarks[j];
}
@ -85,18 +88,26 @@ int mediapipe_hand_detect(IHandPose3DEstimator d, const unsigned char *rgbdata,
objects->items[i].skeleton3d = NULL;
continue;
}
const size_t total_skeleton3d = objs[i].skeleton3d.size();
if (total_skeleton3d == 0) {
objects->items[i].skeleton = NULL;
objects->items[i].skeleton3d = NULL;
continue;
}
objects->items[i].skeleton = (Point2fVector *)malloc(sizeof(Point2fVector));
objects->items[i].skeleton->length = total_skeleton;
objects->items[i].skeleton->points =
(Point2f *)malloc(total_skeleton * sizeof(Point2f));
objects->items[i].skeleton3d =
(Point3dVector *)malloc(sizeof(Point3dVector));
objects->items[i].skeleton3d->length = total_skeleton;
objects->items[i].skeleton3d->length = total_skeleton3d;
objects->items[i].skeleton3d->points =
(Point3d *)malloc(total_skeleton * sizeof(Point3d));
(Point3d *)malloc(total_skeleton3d * sizeof(Point3d));
for (size_t j = 0; j < total_skeleton; ++j) {
objects->items[i].skeleton->points[j].x = objs[i].skeleton[j].x;
objects->items[i].skeleton->points[j].y = objs[i].skeleton[j].y;
}
for (size_t j = 0; j < total_skeleton3d; ++j) {
objects->items[i].skeleton3d->points[j].x = objs[i].skeleton3d[j].x;
objects->items[i].skeleton3d->points[j].y = objs[i].skeleton3d[j].y;
objects->items[i].skeleton3d->points[j].z = objs[i].skeleton3d[j].z;

View File

@ -440,6 +440,7 @@ int MediapipeHand::Detect(const unsigned char *rgbdata, int img_width,
decode_bounds(region_list, prob_threshold, target_size, target_size, scores,
bboxes, anchors);
non_max_suppression(region_list, region_nms_list, nms_threshold);
objects.clear();
pack_detect_result(detect_results, region_nms_list, target_size, objects);
@ -490,10 +491,9 @@ int MediapipeHand::Detect(const unsigned char *rgbdata, int img_width,
ncnn::Mat trans_image =
ncnn::Mat::from_pixels(trans_mat, ncnn::Mat::PIXEL_RGB, 224, 224);
free(trans_mat);
float score = GetLandmarks(trans_image, tm, objects[i].skeleton,
objects[i].skeleton3d);
free(trans_mat);
}
return 0;
}