mirror of
https://github.com/bububa/openvision.git
synced 2025-09-27 10:02:11 +08:00
fix(hand): pose3d/mediapipe palmobject.landmarks wrong malloc
This commit is contained in:
@@ -43,6 +43,7 @@ func main() {
|
|||||||
// }
|
// }
|
||||||
d3d := mediapipe(modelPath)
|
d3d := mediapipe(modelPath)
|
||||||
detect3d(d3d, imgPath, fontPath, "hand1.jpg")
|
detect3d(d3d, imgPath, fontPath, "hand1.jpg")
|
||||||
|
detect3d(d3d, imgPath, fontPath, "hand2.jpg")
|
||||||
}
|
}
|
||||||
|
|
||||||
func yolox(modelPath string) detecter.Detecter {
|
func yolox(modelPath string) detecter.Detecter {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -19,9 +19,12 @@
|
|||||||
#ifndef SVM_LEARN
|
#ifndef SVM_LEARN
|
||||||
#define SVM_LEARN
|
#define SVM_LEARN
|
||||||
|
|
||||||
|
#include "svm_common.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void svm_learn_classification(DOC **, double *, long, long, LEARN_PARM *,
|
void svm_learn_classification(DOC **, double *, long, long, LEARN_PARM *,
|
||||||
KERNEL_PARM *, KERNEL_CACHE *, MODEL *, double *);
|
KERNEL_PARM *, KERNEL_CACHE *, MODEL *, double *);
|
||||||
void svm_learn_regression(DOC **, double *, long, long, LEARN_PARM *,
|
void svm_learn_regression(DOC **, double *, long, long, LEARN_PARM *,
|
||||||
|
@@ -53,6 +53,8 @@ int mediapipe_hand_detect(IHandPose3DEstimator d, const unsigned char *rgbdata,
|
|||||||
int ret = static_cast<ovhand3d::MediapipeHand *>(d)->Detect(
|
int ret = static_cast<ovhand3d::MediapipeHand *>(d)->Detect(
|
||||||
rgbdata, img_width, img_height, objs);
|
rgbdata, img_width, img_height, objs);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
objects->length = 0;
|
||||||
|
objects->items = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
const size_t total_objs = objs.size();
|
const size_t total_objs = objs.size();
|
||||||
@@ -61,6 +63,7 @@ int mediapipe_hand_detect(IHandPose3DEstimator d, const unsigned char *rgbdata,
|
|||||||
objects->items = NULL;
|
objects->items = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
objects->items = (PalmObject *)malloc(total_objs * sizeof(PalmObject));
|
objects->items = (PalmObject *)malloc(total_objs * sizeof(PalmObject));
|
||||||
for (size_t i = 0; i < total_objs; ++i) {
|
for (size_t i = 0; i < total_objs; ++i) {
|
||||||
objects->items[i].score = objs[i].score;
|
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));
|
(Point2fVector *)malloc(sizeof(Point2fVector));
|
||||||
objects->items[i].landmarks->length = 7;
|
objects->items[i].landmarks->length = 7;
|
||||||
objects->items[i].landmarks->points =
|
objects->items[i].landmarks->points =
|
||||||
(Point2f *)malloc(4 * sizeof(Point2f));
|
(Point2f *)malloc(7 * sizeof(Point2f));
|
||||||
for (size_t j = 0; j < 7; ++j) {
|
for (size_t j = 0; j < 7; ++j) {
|
||||||
objects->items[i].landmarks->points[j] = objs[i].landmarks[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;
|
objects->items[i].skeleton3d = NULL;
|
||||||
continue;
|
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 = (Point2fVector *)malloc(sizeof(Point2fVector));
|
||||||
objects->items[i].skeleton->length = total_skeleton;
|
objects->items[i].skeleton->length = total_skeleton;
|
||||||
objects->items[i].skeleton->points =
|
objects->items[i].skeleton->points =
|
||||||
(Point2f *)malloc(total_skeleton * sizeof(Point2f));
|
(Point2f *)malloc(total_skeleton * sizeof(Point2f));
|
||||||
objects->items[i].skeleton3d =
|
objects->items[i].skeleton3d =
|
||||||
(Point3dVector *)malloc(sizeof(Point3dVector));
|
(Point3dVector *)malloc(sizeof(Point3dVector));
|
||||||
objects->items[i].skeleton3d->length = total_skeleton;
|
objects->items[i].skeleton3d->length = total_skeleton3d;
|
||||||
objects->items[i].skeleton3d->points =
|
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) {
|
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].x = objs[i].skeleton[j].x;
|
||||||
objects->items[i].skeleton->points[j].y = objs[i].skeleton[j].y;
|
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].x = objs[i].skeleton3d[j].x;
|
||||||
objects->items[i].skeleton3d->points[j].y = objs[i].skeleton3d[j].y;
|
objects->items[i].skeleton3d->points[j].y = objs[i].skeleton3d[j].y;
|
||||||
objects->items[i].skeleton3d->points[j].z = objs[i].skeleton3d[j].z;
|
objects->items[i].skeleton3d->points[j].z = objs[i].skeleton3d[j].z;
|
||||||
|
@@ -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,
|
decode_bounds(region_list, prob_threshold, target_size, target_size, scores,
|
||||||
bboxes, anchors);
|
bboxes, anchors);
|
||||||
non_max_suppression(region_list, region_nms_list, nms_threshold);
|
non_max_suppression(region_list, region_nms_list, nms_threshold);
|
||||||
|
|
||||||
objects.clear();
|
objects.clear();
|
||||||
pack_detect_result(detect_results, region_nms_list, target_size, objects);
|
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 trans_image =
|
||||||
ncnn::Mat::from_pixels(trans_mat, ncnn::Mat::PIXEL_RGB, 224, 224);
|
ncnn::Mat::from_pixels(trans_mat, ncnn::Mat::PIXEL_RGB, 224, 224);
|
||||||
|
|
||||||
|
free(trans_mat);
|
||||||
float score = GetLandmarks(trans_image, tm, objects[i].skeleton,
|
float score = GetLandmarks(trans_image, tm, objects[i].skeleton,
|
||||||
objects[i].skeleton3d);
|
objects[i].skeleton3d);
|
||||||
|
|
||||||
free(trans_mat);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user