mirror of
https://github.com/bububa/openvision.git
synced 2025-09-27 10:02:11 +08:00
feat(pose): add utralight posenet
This commit is contained in:
@@ -50,6 +50,12 @@ var (
|
|||||||
Message: "detect head pose failed",
|
Message: "detect head pose failed",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DetectPoseError = func(code int) Error {
|
||||||
|
return Error{
|
||||||
|
Code: code,
|
||||||
|
Message: "detect pose failed",
|
||||||
|
}
|
||||||
|
}
|
||||||
RealsrError = func(code int) Error {
|
RealsrError = func(code int) Error {
|
||||||
return Error{
|
return Error{
|
||||||
Code: code,
|
Code: code,
|
||||||
|
@@ -27,7 +27,7 @@ type Detecter interface {
|
|||||||
func LoadModel(d Detecter, modelPath string) error {
|
func LoadModel(d Detecter, modelPath string) error {
|
||||||
cpath := C.CString(modelPath)
|
cpath := C.CString(modelPath)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
retCode := C.detecter_load_model(d.Handler(), cpath)
|
retCode := C.load_model((C.IEstimator)(unsafe.Pointer(d.Handler())), cpath)
|
||||||
if retCode != 0 {
|
if retCode != 0 {
|
||||||
return openvision.LoadModelError(int(retCode))
|
return openvision.LoadModelError(int(retCode))
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ func LoadModel(d Detecter, modelPath string) error {
|
|||||||
|
|
||||||
// Destroy a detecter
|
// Destroy a detecter
|
||||||
func Destroy(d Detecter) {
|
func Destroy(d Detecter) {
|
||||||
C.destroy_detecter(d.Handler())
|
C.destroy_estimator((C.IEstimator)(unsafe.Pointer(d.Handler())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetectFace detect face useing detecter
|
// DetectFace detect face useing detecter
|
||||||
|
@@ -25,7 +25,7 @@ func NewRetinaFace() *RetinaFace {
|
|||||||
|
|
||||||
// Destroy free detecter
|
// Destroy free detecter
|
||||||
func (d *RetinaFace) Destroy() {
|
func (d *RetinaFace) Destroy() {
|
||||||
C.destroy_detecter(d.d)
|
Destroy(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *RetinaFace) Handler() C.IDetecter {
|
func (d *RetinaFace) Handler() C.IDetecter {
|
||||||
|
@@ -65,7 +65,7 @@ func (f FaceInfo) CFaceInfo() *C.FaceInfo {
|
|||||||
|
|
||||||
// NewCFaceInfoVector returns C.FaceInfoVector pointer
|
// NewCFaceInfoVector returns C.FaceInfoVector pointer
|
||||||
func NewCFaceInfoVector() *C.FaceInfoVector {
|
func NewCFaceInfoVector() *C.FaceInfoVector {
|
||||||
return (*C.FaceInfoVector)(C.malloc(C.sizeof_FaceInfo))
|
return (*C.FaceInfoVector)(C.malloc(C.sizeof_FaceInfoVector))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoFaceInfoVector conver c FaceInfoVector to go FaceInfo slice
|
// GoFaceInfoVector conver c FaceInfoVector to go FaceInfo slice
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
// Package hopenet head pose detecter
|
// Package hopenet include head pose estimation
|
||||||
package hopenet
|
package hopenet
|
||||||
|
@@ -3,7 +3,6 @@ package hopenet
|
|||||||
/*
|
/*
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "openvision/face/common.h"
|
|
||||||
#include "openvision/face/hopenet.h"
|
#include "openvision/face/hopenet.h"
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
@@ -17,7 +16,7 @@ import (
|
|||||||
|
|
||||||
// Hopenet represents Hopenet detecter
|
// Hopenet represents Hopenet detecter
|
||||||
type Hopenet struct {
|
type Hopenet struct {
|
||||||
d C.IHopeNet
|
d C.IHopenet
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHopenet returns a new Hopenet
|
// NewHopenet returns a new Hopenet
|
||||||
@@ -27,22 +26,23 @@ func NewHopenet() *Hopenet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy destroy C.IHopeNet
|
// LoadModel load detecter model
|
||||||
func (h *Hopenet) Destroy() {
|
|
||||||
C.destroy_hopenet(h.d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hopenet) LoadModel(modelPath string) error {
|
func (h *Hopenet) LoadModel(modelPath string) error {
|
||||||
cpath := C.CString(modelPath)
|
cpath := C.CString(modelPath)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
retCode := C.hopenet_load_model(h.d, cpath)
|
retCode := C.load_model((C.IEstimator)(unsafe.Pointer(h.d)), cpath)
|
||||||
if retCode != 0 {
|
if retCode != 0 {
|
||||||
return openvision.LoadModelError(int(retCode))
|
return openvision.LoadModelError(int(retCode))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect
|
// Destroy destroy C.IHopeNet
|
||||||
|
func (h *Hopenet) Destroy() {
|
||||||
|
C.destroy_estimator((C.IEstimator)(unsafe.Pointer(h.d)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect head pose
|
||||||
func (h *Hopenet) Detect(img *common.Image, faceRect common.Rectangle) (face.HeadPose, error) {
|
func (h *Hopenet) Detect(img *common.Image, faceRect common.Rectangle) (face.HeadPose, error) {
|
||||||
imgWidth := img.WidthF64()
|
imgWidth := img.WidthF64()
|
||||||
imgHeight := img.HeightF64()
|
imgHeight := img.HeightF64()
|
||||||
|
@@ -26,7 +26,7 @@ type Landmarker interface {
|
|||||||
func LoadModel(d Landmarker, modelPath string) error {
|
func LoadModel(d Landmarker, modelPath string) error {
|
||||||
cpath := C.CString(modelPath)
|
cpath := C.CString(modelPath)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
retCode := C.landmarker_load_model(d.Handler(), cpath)
|
retCode := C.load_model((C.IEstimator)(unsafe.Pointer(d.Handler())), cpath)
|
||||||
if retCode != 0 {
|
if retCode != 0 {
|
||||||
return openvision.LoadModelError(int(retCode))
|
return openvision.LoadModelError(int(retCode))
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func LoadModel(d Landmarker, modelPath string) error {
|
|||||||
|
|
||||||
// Destroy a landmarker
|
// Destroy a landmarker
|
||||||
func Destroy(d Landmarker) {
|
func Destroy(d Landmarker) {
|
||||||
C.destroy_landmarker(d.Handler())
|
C.destroy_estimator((C.IEstimator)(unsafe.Pointer(d.Handler())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractKeypoints extract keypoints using landmarker
|
// ExtractKeypoints extract keypoints using landmarker
|
||||||
@@ -50,7 +50,7 @@ func ExtractKeypoints(d Landmarker, img *common.Image, faceRect common.Rectangle
|
|||||||
CPoints := common.NewCPoint2fVector()
|
CPoints := common.NewCPoint2fVector()
|
||||||
defer common.FreeCPoint2fVector(CPoints)
|
defer common.FreeCPoint2fVector(CPoints)
|
||||||
CRect := faceRect.CRect()
|
CRect := faceRect.CRect()
|
||||||
errCode := C.extract_keypoints(
|
errCode := C.extract_face_keypoints(
|
||||||
d.Handler(),
|
d.Handler(),
|
||||||
(*C.uchar)(unsafe.Pointer(&data[0])),
|
(*C.uchar)(unsafe.Pointer(&data[0])),
|
||||||
C.int(imgWidth), C.int(imgHeight),
|
C.int(imgWidth), C.int(imgHeight),
|
||||||
|
@@ -26,7 +26,7 @@ type Recognizer interface {
|
|||||||
func LoadModel(r Recognizer, modelPath string) error {
|
func LoadModel(r Recognizer, modelPath string) error {
|
||||||
cpath := C.CString(modelPath)
|
cpath := C.CString(modelPath)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
retCode := C.recognizer_load_model(r.Handler(), cpath)
|
retCode := C.load_model((C.IEstimator)(unsafe.Pointer(r.Handler())), cpath)
|
||||||
if retCode != 0 {
|
if retCode != 0 {
|
||||||
return openvision.LoadModelError(int(retCode))
|
return openvision.LoadModelError(int(retCode))
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func LoadModel(r Recognizer, modelPath string) error {
|
|||||||
|
|
||||||
// Destroy a recognizer
|
// Destroy a recognizer
|
||||||
func Destroy(r Recognizer) {
|
func Destroy(r Recognizer) {
|
||||||
C.destroy_recognizer(r.Handler())
|
C.destroy_estimator((C.IEstimator)(unsafe.Pointer(r.Handler())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractFeatures extract features using recognizer
|
// ExtractFeatures extract features using recognizer
|
||||||
|
@@ -26,7 +26,7 @@ func GoTrackedFaceInfo(cInfo *C.TrackedFaceInfo, w float64, h float64) TrackedFa
|
|||||||
|
|
||||||
// NewCTrackedFaceInfoVector returns C.TrackedFaceInfoVector pointer
|
// NewCTrackedFaceInfoVector returns C.TrackedFaceInfoVector pointer
|
||||||
func NewCTrackedFaceInfoVector() *C.TrackedFaceInfoVector {
|
func NewCTrackedFaceInfoVector() *C.TrackedFaceInfoVector {
|
||||||
return (*C.TrackedFaceInfoVector)(C.malloc(C.sizeof_TrackedFaceInfo))
|
return (*C.TrackedFaceInfoVector)(C.malloc(C.sizeof_TrackedFaceInfoVector))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoTrackedFaceInfoVector conver c TrackedFaceInfoVector to go TrackedFaceInfo slice
|
// GoTrackedFaceInfoVector conver c TrackedFaceInfoVector to go TrackedFaceInfo slice
|
||||||
|
11
go/pose/cgo.go
Normal file
11
go/pose/cgo.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build !vulkan
|
||||||
|
|
||||||
|
package pose
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CXXFLAGS: --std=c++11 -fopenmp
|
||||||
|
#cgo CPPFLAGS: -I ${SRCDIR}/../../include -I /usr/local/include
|
||||||
|
#cgo LDFLAGS: -lstdc++ -lncnn -lomp -lopenvision
|
||||||
|
#cgo LDFLAGS: -L /usr/local/lib -L ${SRCDIR}/../../lib
|
||||||
|
*/
|
||||||
|
import "C"
|
11
go/pose/cgo_vulkan.go
Normal file
11
go/pose/cgo_vulkan.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build vulkan
|
||||||
|
|
||||||
|
package pose
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CXXFLAGS: --std=c++11 -fopenmp
|
||||||
|
#cgo CPPFLAGS: -I ${SRCDIR}/../../include -I /usr/local/include
|
||||||
|
#cgo LDFLAGS: -lstdc++ -lncnn -lomp -lopenvision -lglslang -lvulkan -lSPIRV -lOGLCompiler -lMachineIndependent -lGenericCodeGen -lOSDependent
|
||||||
|
#cgo LDFLAGS: -L /usr/local/lib -L ${SRCDIR}/../../lib
|
||||||
|
*/
|
||||||
|
import "C"
|
11
go/pose/detecter/cgo.go
Normal file
11
go/pose/detecter/cgo.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build !vulkan
|
||||||
|
|
||||||
|
package detecter
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CXXFLAGS: --std=c++11 -fopenmp
|
||||||
|
#cgo CPPFLAGS: -I ${SRCDIR}/../../../include -I /usr/local/include
|
||||||
|
#cgo LDFLAGS: -lstdc++ -lncnn -lomp -lopenvision
|
||||||
|
#cgo LDFLAGS: -L /usr/local/lib -L ${SRCDIR}/../../../lib
|
||||||
|
*/
|
||||||
|
import "C"
|
11
go/pose/detecter/cgo_vulkan.go
Normal file
11
go/pose/detecter/cgo_vulkan.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// +build vulkan
|
||||||
|
|
||||||
|
package detecter
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CXXFLAGS: --std=c++11 -fopenmp
|
||||||
|
#cgo CPPFLAGS: -I ${SRCDIR}/../../../include -I /usr/local/include
|
||||||
|
#cgo LDFLAGS: -lstdc++ -lncnn -lomp -lopenvision -lglslang -lvulkan -lSPIRV -lOGLCompiler -lMachineIndependent -lGenericCodeGen -lOSDependent
|
||||||
|
#cgo LDFLAGS: -L /usr/local/lib -L ${SRCDIR}/../../../lib
|
||||||
|
*/
|
||||||
|
import "C"
|
86
go/pose/detecter/detecter.go
Normal file
86
go/pose/detecter/detecter.go
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package detecter
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "openvision/pose/common.h"
|
||||||
|
#include "openvision/pose/detecter.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
openvision "github.com/bububa/openvision/go"
|
||||||
|
"github.com/bububa/openvision/go/common"
|
||||||
|
"github.com/bububa/openvision/go/pose"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Detecter represents deteter interface
|
||||||
|
type Detecter interface {
|
||||||
|
Handler() C.IDetecter
|
||||||
|
LoadModel(modelPath string) error
|
||||||
|
ExtractKeypoints(img *common.Image) ([]pose.ROI, error)
|
||||||
|
Destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadModel load detecter model
|
||||||
|
func LoadModel(d Detecter, modelPath string) error {
|
||||||
|
cpath := C.CString(modelPath)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
retCode := C.load_model((C.IEstimator)(unsafe.Pointer(d.Handler())), cpath)
|
||||||
|
if retCode != 0 {
|
||||||
|
return openvision.LoadModelError(int(retCode))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy a detecter
|
||||||
|
func Destroy(d Detecter) {
|
||||||
|
C.destroy_estimator((C.IEstimator)(unsafe.Pointer(d.Handler())))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtractKeypoints detect pose keypoints using detecter
|
||||||
|
func ExtractKeypoints(d Detecter, img *common.Image) ([]pose.ROI, error) {
|
||||||
|
imgWidth := img.WidthF64()
|
||||||
|
imgHeight := img.HeightF64()
|
||||||
|
data := img.Bytes()
|
||||||
|
cROIs := pose.NewCROIVector()
|
||||||
|
defer pose.FreeCROIVector(cROIs)
|
||||||
|
errCode := C.extract_pose_rois(
|
||||||
|
d.Handler(),
|
||||||
|
(*C.uchar)(unsafe.Pointer(&data[0])),
|
||||||
|
C.int(imgWidth),
|
||||||
|
C.int(imgHeight),
|
||||||
|
(*C.PoseROIVector)(unsafe.Pointer(cROIs)))
|
||||||
|
if errCode != 0 {
|
||||||
|
return nil, openvision.DetectPoseError(int(errCode))
|
||||||
|
}
|
||||||
|
totalROIs := pose.CROIVectiorLength(cROIs)
|
||||||
|
rois := make([]pose.ROI, 0, totalROIs)
|
||||||
|
ptr := unsafe.Pointer(cROIs)
|
||||||
|
for i := 0; i < totalROIs; i++ {
|
||||||
|
cKeypoints := pose.NewCKeypointVector()
|
||||||
|
defer pose.FreeCKeypointVector(cKeypoints)
|
||||||
|
cROI := (*C.PoseROI)(unsafe.Pointer(uintptr(ptr) + uintptr(C.sizeof_PoseROI*C.int(i))))
|
||||||
|
errCode := C.extract_pose_keypoints(
|
||||||
|
d.Handler(),
|
||||||
|
cROI,
|
||||||
|
(*C.PoseKeypointVector)(unsafe.Pointer(cKeypoints)))
|
||||||
|
if errCode != 0 {
|
||||||
|
return nil, openvision.DetectPoseError(int(errCode))
|
||||||
|
}
|
||||||
|
keypoints := pose.GoKeypointVector(cKeypoints, imgWidth, imgHeight)
|
||||||
|
rois = append(rois, pose.ROI{
|
||||||
|
Keypoints: keypoints,
|
||||||
|
Rect: common.Rect(
|
||||||
|
float64(cROI.rect.x)/imgWidth,
|
||||||
|
float64(cROI.rect.y)/imgHeight,
|
||||||
|
float64(cROI.rect.width)/imgWidth,
|
||||||
|
float64(cROI.rect.height)/imgHeight,
|
||||||
|
),
|
||||||
|
Score: float32(cROI.score),
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
return rois, nil
|
||||||
|
}
|
2
go/pose/detecter/doc.go
Normal file
2
go/pose/detecter/doc.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Package detecter pose detecter
|
||||||
|
package detecter
|
44
go/pose/detecter/ultralight.go
Normal file
44
go/pose/detecter/ultralight.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package detecter
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "openvision/pose/detecter.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"github.com/bububa/openvision/go/common"
|
||||||
|
"github.com/bububa/openvision/go/pose"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ultralight represents utralight detecter
|
||||||
|
type Ultralight struct {
|
||||||
|
d C.IDetecter
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUltralight returns a new Utralight
|
||||||
|
func NewUltralight() *Ultralight {
|
||||||
|
return &Ultralight{
|
||||||
|
d: C.new_ultralight(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy free detecter
|
||||||
|
func (d *Ultralight) Destroy() {
|
||||||
|
Destroy(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler returns C.IDetecter
|
||||||
|
func (d *Ultralight) Handler() C.IDetecter {
|
||||||
|
return d.d
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadModel load model for detecter
|
||||||
|
func (d *Ultralight) LoadModel(modelPath string) error {
|
||||||
|
return LoadModel(d, modelPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtractKeypoints implement Detecter interface
|
||||||
|
func (d *Ultralight) ExtractKeypoints(img *common.Image) ([]pose.ROI, error) {
|
||||||
|
return ExtractKeypoints(d, img)
|
||||||
|
}
|
2
go/pose/doc.go
Normal file
2
go/pose/doc.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Package pose include pose estimation
|
||||||
|
package pose
|
63
go/pose/keypoint.go
Normal file
63
go/pose/keypoint.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package pose
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "openvision/pose/common.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/bububa/openvision/go/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Keypoint represents detected body keypoint
|
||||||
|
type Keypoint struct {
|
||||||
|
// Point keypoint location
|
||||||
|
Point common.Point
|
||||||
|
// Score keypoint prob
|
||||||
|
Score float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoKeypoint convert C.PoseKeypoint to go type
|
||||||
|
func GoKeypoint(c *C.PoseKeypoint, w float64, h float64) Keypoint {
|
||||||
|
return Keypoint{
|
||||||
|
Point: common.Pt(float64(c.p.x)/w, float64(c.p.y)/h),
|
||||||
|
Score: float32(c.prob),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert Keypoint to C.Keypoint pointer
|
||||||
|
func (k Keypoint) CKeypoint() *C.PoseKeypoint {
|
||||||
|
ret := (*C.PoseKeypoint)(C.malloc(C.sizeof_PoseKeypoint))
|
||||||
|
ret.prob = C.float(k.Score)
|
||||||
|
ret.p = C.Point2f{
|
||||||
|
C.float(k.Point.X),
|
||||||
|
C.float(k.Point.Y),
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCKeypointVector returns *C.PoseKeypointVector
|
||||||
|
func NewCKeypointVector() *C.PoseKeypointVector {
|
||||||
|
return (*C.PoseKeypointVector)(C.malloc(C.sizeof_PoseKeypointVector))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FreeCKeypointVector release *C.PoseKeypointVector memory
|
||||||
|
func FreeCKeypointVector(points *C.PoseKeypointVector) {
|
||||||
|
C.FreePoseKeypointVector(points)
|
||||||
|
C.free(unsafe.Pointer(points))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoKeypointVector convert *C.PoseKeypointVector to Keypoint slice
|
||||||
|
func GoKeypointVector(c *C.PoseKeypointVector, w float64, h float64) []Keypoint {
|
||||||
|
l := int(c.length)
|
||||||
|
ret := make([]Keypoint, 0, l)
|
||||||
|
ptr := unsafe.Pointer(c.points)
|
||||||
|
for i := 0; i < l; i++ {
|
||||||
|
cKeypoint := (*C.PoseKeypoint)(unsafe.Pointer(uintptr(ptr) + uintptr(C.sizeof_PoseKeypoint*C.int(i))))
|
||||||
|
ret = append(ret, GoKeypoint(cKeypoint, w, h))
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
38
go/pose/roi.go
Normal file
38
go/pose/roi.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package pose
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "openvision/pose/common.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/bububa/openvision/go/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ROI represents detected person roi
|
||||||
|
type ROI struct {
|
||||||
|
// Score detected score
|
||||||
|
Score float32
|
||||||
|
// Rect roi location
|
||||||
|
Rect common.Rectangle
|
||||||
|
// Keypoints
|
||||||
|
Keypoints []Keypoint
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewROIVector returns *C.PoseROIVector
|
||||||
|
func NewCROIVector() *C.PoseROIVector {
|
||||||
|
return (*C.PoseROIVector)(C.malloc(C.sizeof_PoseROIVector))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FreeCROIVector release *C.PoseROIVectore memory
|
||||||
|
func FreeCROIVector(p *C.PoseROIVector) {
|
||||||
|
C.FreePoseROIVector(p)
|
||||||
|
C.free(unsafe.Pointer(p))
|
||||||
|
}
|
||||||
|
|
||||||
|
func CROIVectiorLength(c *C.PoseROIVector) int {
|
||||||
|
return int(c.length)
|
||||||
|
}
|
@@ -30,14 +30,14 @@ func NewRealERSGAN(gpuid int, ttaMode bool) *RealESRGAN {
|
|||||||
|
|
||||||
// Destroy a detecter
|
// Destroy a detecter
|
||||||
func (d *RealESRGAN) Destroy() {
|
func (d *RealESRGAN) Destroy() {
|
||||||
C.destroy_realesrgan(d.d)
|
C.destroy_estimator((C.IEstimator)(unsafe.Pointer(d.d)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadModel load processer model
|
// LoadModel load processer model
|
||||||
func (d *RealESRGAN) LoadModel(modelPath string) error {
|
func (d *RealESRGAN) LoadModel(modelPath string) error {
|
||||||
cpath := C.CString(modelPath)
|
cpath := C.CString(modelPath)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
retCode := C.realesrgan_load_model(d.d, cpath)
|
retCode := C.load_model((C.IEstimator)(unsafe.Pointer(d.d)), cpath)
|
||||||
if retCode != 0 {
|
if retCode != 0 {
|
||||||
return openvision.LoadModelError(int(retCode))
|
return openvision.LoadModelError(int(retCode))
|
||||||
}
|
}
|
||||||
|
@@ -122,7 +122,14 @@ target_include_directories(openvision
|
|||||||
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/recognizer>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/recognizer>
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/recognizer/mobilefacenet>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/recognizer/mobilefacenet>
|
||||||
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/tracker>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/tracker>
|
||||||
|
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/hopenet>
|
||||||
|
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/pose>
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/pose/common>
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/face/pose/detecter>
|
||||||
)
|
)
|
||||||
|
|
||||||
#install(TARGETS openvision EXPORT openvision ARCHIVE DESTINATION ${LIBRARY_OUTPUT_PATH})
|
#install(TARGETS openvision EXPORT openvision ARCHIVE DESTINATION ${LIBRARY_OUTPUT_PATH})
|
||||||
|
@@ -27,6 +27,14 @@ void destroy_gpu_instance() {
|
|||||||
#endif // OV_VULKAN
|
#endif // OV_VULKAN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int load_model(IEstimator d, const char *root_path) {
|
||||||
|
return static_cast<ov::Estimator*>(d)->LoadModel(root_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_estimator(IEstimator d) {
|
||||||
|
delete static_cast<ov::Estimator*>(d);
|
||||||
|
}
|
||||||
|
|
||||||
void FreePoint2fVector(Point2fVector* p) {
|
void FreePoint2fVector(Point2fVector* p) {
|
||||||
if (p->points != NULL) {
|
if (p->points != NULL) {
|
||||||
free(p->points);
|
free(p->points);
|
||||||
|
@@ -42,9 +42,13 @@ typedef struct Rect {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void* IEstimator;
|
||||||
|
|
||||||
int get_gpu_count();
|
int get_gpu_count();
|
||||||
int create_gpu_instance();
|
int create_gpu_instance();
|
||||||
void destroy_gpu_instance();
|
void destroy_gpu_instance();
|
||||||
|
int load_model(IEstimator e, const char* root_path);
|
||||||
|
void destroy_estimator(IEstimator e);
|
||||||
|
|
||||||
typedef struct Point2fVector {
|
typedef struct Point2fVector {
|
||||||
Point2f* points;
|
Point2f* points;
|
||||||
|
@@ -11,6 +11,12 @@
|
|||||||
namespace ov {
|
namespace ov {
|
||||||
const int threads_num = 2;
|
const int threads_num = 2;
|
||||||
|
|
||||||
|
class Estimator {
|
||||||
|
public:
|
||||||
|
virtual ~Estimator(){};
|
||||||
|
virtual int LoadModel(const char* root_path) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
// Wrapper for an individual cv::cvSize
|
// Wrapper for an individual cv::cvSize
|
||||||
typedef struct Size {
|
typedef struct Size {
|
||||||
int width;
|
int width;
|
||||||
|
@@ -12,8 +12,6 @@ extern "C" {
|
|||||||
IDetecter new_centerface();
|
IDetecter new_centerface();
|
||||||
IDetecter new_mtcnn();
|
IDetecter new_mtcnn();
|
||||||
IDetecter new_anticonv();
|
IDetecter new_anticonv();
|
||||||
void destroy_detecter(IDetecter d);
|
|
||||||
int detecter_load_model(IDetecter d, const char* root_path);
|
|
||||||
int detect_face(IDetecter d, const unsigned char* rgbdata, int img_width, int img_height, FaceInfoVector* faces);
|
int detect_face(IDetecter d, const unsigned char* rgbdata, int img_width, int img_height, FaceInfoVector* faces);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -20,14 +20,6 @@ IDetecter new_anticonv() {
|
|||||||
return new ov::AntiConv();
|
return new ov::AntiConv();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_detecter(IDetecter d) {
|
|
||||||
delete static_cast<ov::Detecter*>(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
int detecter_load_model(IDetecter d, const char *root_path){
|
|
||||||
return static_cast<ov::Detecter*>(d)->LoadModel(root_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
int detect_face(IDetecter d, const unsigned char* rgbdata, int img_width, int img_height, FaceInfoVector* faces) {
|
int detect_face(IDetecter d, const unsigned char* rgbdata, int img_width, int img_height, FaceInfoVector* faces) {
|
||||||
std::vector<FaceInfo> detected;
|
std::vector<FaceInfo> detected;
|
||||||
int ret = static_cast<ov::Detecter*>(d)->DetectFace(rgbdata, img_width, img_height, &detected);
|
int ret = static_cast<ov::Detecter*>(d)->DetectFace(rgbdata, img_width, img_height, &detected);
|
||||||
|
@@ -5,10 +5,9 @@
|
|||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
// 抽象类
|
// 抽象类
|
||||||
class Detecter {
|
class Detecter: public Estimator {
|
||||||
public:
|
public:
|
||||||
virtual ~Detecter() {};
|
virtual ~Detecter() {};
|
||||||
virtual int LoadModel(const char* root_path) = 0;
|
|
||||||
virtual int DetectFace(const unsigned char* rgbdata,
|
virtual int DetectFace(const unsigned char* rgbdata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
std::vector<FaceInfo>* faces) = 0;
|
std::vector<FaceInfo>* faces) = 0;
|
||||||
@@ -19,7 +18,7 @@ public:
|
|||||||
class DetecterFactory {
|
class DetecterFactory {
|
||||||
public:
|
public:
|
||||||
virtual Detecter* CreateDetecter() = 0;
|
virtual Detecter* CreateDetecter() = 0;
|
||||||
virtual ~DetecterFactory() {};
|
virtual ~DetecterFactory() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 不同人脸检测器
|
// 不同人脸检测器
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#ifndef _ROS_NCNN_HOPENET_C_H_
|
#ifndef _FACE_HOPENET_C_H_
|
||||||
#define _ROS_NCNN_HOPENET_C_H_
|
#define _FACE_HOPENET_C_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@@ -7,12 +7,10 @@
|
|||||||
#include "hopenet/hopenet.hpp"
|
#include "hopenet/hopenet.hpp"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
typedef void* IHopeNet;
|
typedef void* IHopenet;
|
||||||
IHopeNet new_hopenet();
|
IHopenet new_hopenet();
|
||||||
void destroy_hopenet(IHopeNet h);
|
int hopenet_detect(IHopenet d, const unsigned char* rgbdata, int img_width, int img_height, const Rect* roi, HeadPose* euler_angles);
|
||||||
int hopenet_load_model(IHopeNet h, const char* root_path);
|
|
||||||
int hopenet_detect(IHopeNet h, const unsigned char* rgbdata, int img_width, int img_height, const Rect* roi, HeadPose* euler_angles);
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif // !_FACE_HOPENET_C_H_
|
||||||
|
@@ -7,27 +7,21 @@
|
|||||||
#include "gpu.h"
|
#include "gpu.h"
|
||||||
#endif // OV_VULKAN
|
#endif // OV_VULKAN
|
||||||
|
|
||||||
#define NEAR_0 1e-10
|
|
||||||
#define ODIM 66
|
|
||||||
|
|
||||||
IHopeNet new_hopenet() {
|
IHopenet new_hopenet() {
|
||||||
return new ov::HopeNet();
|
return new ov::Hopenet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_hopenet(IHopeNet h) {
|
int hopenet_detect(IHopenet h, const unsigned char* rgbdata, int img_width, int img_height, const Rect* roi, HeadPose* euler_angles) {
|
||||||
delete static_cast<ov::HopeNet*>(h);
|
return static_cast<ov::Hopenet*>(h)->Detect(rgbdata, img_width, img_height, *roi, static_cast<ov::HeadPose*>(euler_angles));
|
||||||
}
|
|
||||||
|
|
||||||
int hopenet_load_model(IHopeNet h, const char* root_path) {
|
|
||||||
return static_cast<ov::HopeNet*>(h)->LoadModel(root_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
int hopenet_detect(IHopeNet h, const unsigned char* rgbdata, int img_width, int img_height, const Rect* roi, HeadPose* euler_angles) {
|
|
||||||
return static_cast<ov::HopeNet*>(h)->Detect(rgbdata, img_width, img_height, *roi, static_cast<ov::HeadPose*>(euler_angles));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
HopeNet::HopeNet():
|
|
||||||
|
#define NEAR_0 1e-10
|
||||||
|
#define ODIM 66
|
||||||
|
|
||||||
|
Hopenet::Hopenet():
|
||||||
net_(new ncnn::Net()),
|
net_(new ncnn::Net()),
|
||||||
initialized_(false) {
|
initialized_(false) {
|
||||||
#ifdef OV_VULKAN
|
#ifdef OV_VULKAN
|
||||||
@@ -35,13 +29,13 @@ HopeNet::HopeNet():
|
|||||||
#endif // OV_VULKAN
|
#endif // OV_VULKAN
|
||||||
}
|
}
|
||||||
|
|
||||||
HopeNet::~HopeNet() {
|
Hopenet::~Hopenet() {
|
||||||
if (net_) {
|
if (net_) {
|
||||||
net_->clear();
|
net_->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HopeNet::LoadModel(const char * root_path) {
|
int Hopenet::LoadModel(const char * root_path) {
|
||||||
std::string param_file = std::string(root_path) + "/param";
|
std::string param_file = std::string(root_path) + "/param";
|
||||||
std::string bin_file = std::string(root_path) + "/bin";
|
std::string bin_file = std::string(root_path) + "/bin";
|
||||||
if (net_->load_param(param_file.c_str()) == -1 ||
|
if (net_->load_param(param_file.c_str()) == -1 ||
|
||||||
@@ -55,7 +49,7 @@ int HopeNet::LoadModel(const char * root_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int HopeNet::Detect(const unsigned char* rgbdata,
|
int Hopenet::Detect(const unsigned char* rgbdata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
Rect roi, HeadPose* head_angles) {
|
Rect roi, HeadPose* head_angles) {
|
||||||
float diff = fabs(roi.height-roi.width);
|
float diff = fabs(roi.height-roi.width);
|
||||||
@@ -101,7 +95,7 @@ int HopeNet::Detect(const unsigned char* rgbdata,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HopeNet::softmax(float* z, size_t el) {
|
void Hopenet::softmax(float* z, size_t el) {
|
||||||
double zmax = -INFINITY;
|
double zmax = -INFINITY;
|
||||||
double zsum = 0;
|
double zsum = 0;
|
||||||
for (size_t i = 0; i < el; i++) if (z[i] > zmax) zmax=z[i];
|
for (size_t i = 0; i < el; i++) if (z[i] > zmax) zmax=z[i];
|
||||||
@@ -110,7 +104,7 @@ void HopeNet::softmax(float* z, size_t el) {
|
|||||||
for (size_t i=0; i<el; i++) z[i] = (z[i]/zsum)+NEAR_0;
|
for (size_t i=0; i<el; i++) z[i] = (z[i]/zsum)+NEAR_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double HopeNet::getAngle(float* prediction, size_t len) {
|
double Hopenet::getAngle(float* prediction, size_t len) {
|
||||||
double expectation[len];
|
double expectation[len];
|
||||||
for (uint i=0; i<len; i++) expectation[i]=idx_tensor[i]*prediction[i];
|
for (uint i=0; i<len; i++) expectation[i]=idx_tensor[i]*prediction[i];
|
||||||
double angle = std::accumulate(expectation, expectation+len, 0.0) * 3 - 99;
|
double angle = std::accumulate(expectation, expectation+len, 0.0) * 3 - 99;
|
||||||
|
@@ -1,15 +1,14 @@
|
|||||||
#ifndef _ROS_NCNN_HOPENET_H_
|
#ifndef _HEAD_HOPENET_H_
|
||||||
#define _ROS_NCNN_HOPENET_H_
|
#define _HEAD_HOPENET_H_
|
||||||
|
|
||||||
#include "../common/common.hpp"
|
#include "../common/common.hpp"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
|
class Hopenet : public Estimator {
|
||||||
class HopeNet {
|
|
||||||
public:
|
public:
|
||||||
HopeNet();
|
Hopenet();
|
||||||
~HopeNet();
|
~Hopenet();
|
||||||
int LoadModel(const char* root_path);
|
int LoadModel(const char* root_path);
|
||||||
int Detect(const unsigned char* rgbdata,
|
int Detect(const unsigned char* rgbdata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
@@ -23,7 +22,5 @@ private:
|
|||||||
double getAngle(float* prediction, size_t len);
|
double getAngle(float* prediction, size_t len);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif // !_HEAD_HOPENET_H_
|
||||||
#endif
|
|
||||||
|
@@ -10,9 +10,7 @@ extern "C" {
|
|||||||
typedef void* ILandmarker;
|
typedef void* ILandmarker;
|
||||||
ILandmarker new_insightface();
|
ILandmarker new_insightface();
|
||||||
ILandmarker new_zq();
|
ILandmarker new_zq();
|
||||||
void destroy_landmarker(ILandmarker m);
|
int extract_face_keypoints(ILandmarker m, const unsigned char* rgbdata, int img_width, int img_height, const Rect* face, Point2fVector* keypoints);
|
||||||
int landmarker_load_model(ILandmarker m, const char* root_path);
|
|
||||||
int extract_keypoints(ILandmarker m, const unsigned char* rgbdata, int img_width, int img_height, const Rect* face, Point2fVector* keypoints);
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -10,15 +10,7 @@ ILandmarker new_insightface() {
|
|||||||
return new ov::InsightfaceLandmarker();
|
return new ov::InsightfaceLandmarker();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_landmarker(ILandmarker m) {
|
int extract_face_keypoints(
|
||||||
delete static_cast<ov::Landmarker*>(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
int landmarker_load_model(ILandmarker m, const char *root_path) {
|
|
||||||
return static_cast<ov::Landmarker*>(m)->LoadModel(root_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
int extract_keypoints(
|
|
||||||
ILandmarker m,
|
ILandmarker m,
|
||||||
const unsigned char* rgbdata,
|
const unsigned char* rgbdata,
|
||||||
int img_width,
|
int img_width,
|
||||||
|
@@ -5,10 +5,9 @@
|
|||||||
|
|
||||||
namespace ov{
|
namespace ov{
|
||||||
// 抽象类
|
// 抽象类
|
||||||
class Landmarker {
|
class Landmarker: public Estimator {
|
||||||
public:
|
public:
|
||||||
virtual ~Landmarker() {};
|
virtual ~Landmarker() {};
|
||||||
virtual int LoadModel(const char* root_path) = 0;
|
|
||||||
virtual int ExtractKeypoints(const unsigned char* rgbdata,
|
virtual int ExtractKeypoints(const unsigned char* rgbdata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
const Rect& face, std::vector<Point2f>* keypoints) = 0;
|
const Rect& face, std::vector<Point2f>* keypoints) = 0;
|
||||||
|
@@ -9,8 +9,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
typedef void* IRecognizer;
|
typedef void* IRecognizer;
|
||||||
IRecognizer new_mobilefacenet();
|
IRecognizer new_mobilefacenet();
|
||||||
void destroy_recognizer(IRecognizer r);
|
|
||||||
int recognizer_load_model(IRecognizer r, const char* root_path);
|
|
||||||
int extract_feature(IRecognizer r, const unsigned char* rgbdata, int img_width, int img_height, const Rect* face, FloatVector* feature);
|
int extract_feature(IRecognizer r, const unsigned char* rgbdata, int img_width, int img_height, const Rect* face, FloatVector* feature);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -5,14 +5,6 @@ IRecognizer new_mobilefacenet() {
|
|||||||
return new ov::Mobilefacenet();
|
return new ov::Mobilefacenet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_recognizer(IRecognizer r) {
|
|
||||||
delete static_cast<ov::Recognizer*>(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
int recognizer_load_model(IRecognizer r, const char* root_path) {
|
|
||||||
return static_cast<ov::Recognizer*>(r)->LoadModel(root_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
int extract_feature(IRecognizer r, const unsigned char* rgbdata, int img_width, int img_height, const Rect* face, FloatVector* feature) {
|
int extract_feature(IRecognizer r, const unsigned char* rgbdata, int img_width, int img_height, const Rect* face, FloatVector* feature) {
|
||||||
std::vector<float>features;
|
std::vector<float>features;
|
||||||
int ret = static_cast<ov::Recognizer*>(r)->ExtractFeature(rgbdata, img_width, img_height, *face, &features);
|
int ret = static_cast<ov::Recognizer*>(r)->ExtractFeature(rgbdata, img_width, img_height, *face, &features);
|
||||||
|
@@ -5,10 +5,9 @@
|
|||||||
#include "../common/common.hpp"
|
#include "../common/common.hpp"
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
class Recognizer {
|
class Recognizer: public Estimator {
|
||||||
public:
|
public:
|
||||||
virtual ~Recognizer() {};
|
virtual ~Recognizer() {};
|
||||||
virtual int LoadModel(const char* root_path) = 0;
|
|
||||||
virtual int ExtractFeature(const unsigned char* rgbdata,
|
virtual int ExtractFeature(const unsigned char* rgbdata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
const Rect& face,
|
const Rect& face,
|
||||||
|
@@ -7,33 +7,33 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
typedef ov::Keypoint Keypoint;
|
typedef ov::PoseKeypoint PoseKeypoint;
|
||||||
typedef ov::ROI ROI;
|
typedef ov::PoseROI PoseROI;
|
||||||
#else
|
#else
|
||||||
typedef struct Keypoint {
|
typedef struct PoseKeypoint {
|
||||||
Point2f p;
|
Point2f p;
|
||||||
float prob;
|
float prob;
|
||||||
} Keypoint;
|
} PoseKeypoint;
|
||||||
|
|
||||||
typedef struct ROI {
|
typedef struct PoseROI {
|
||||||
Rect rect;
|
Rect rect;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
float score;
|
float score;
|
||||||
} ROI;
|
} PoseROI;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
typedef struct ROIVector {
|
typedef struct PoseROIVector {
|
||||||
ROI* items;
|
PoseROI* items;
|
||||||
int length;
|
int length;
|
||||||
} ROIVector;
|
} PoseROIVector;
|
||||||
|
|
||||||
typedef struct KeypointVector {
|
typedef struct PoseKeypointVector {
|
||||||
Keypoint* points;
|
PoseKeypoint* points;
|
||||||
int length;
|
int length;
|
||||||
} KeypointVector;
|
} PoseKeypointVector;
|
||||||
|
|
||||||
void FreeKeypointVector(KeypointVector *p);
|
void FreePoseKeypointVector(PoseKeypointVector *p);
|
||||||
void FreeROIVector(ROIVector *p);
|
void FreePoseROIVector(PoseROIVector *p);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
void FreeKeypointVector(KeypointVector *p) {
|
void FreePoseKeypointVector(PoseKeypointVector *p) {
|
||||||
if (p->points != NULL) {
|
if (p->points != NULL) {
|
||||||
free(p->points);
|
free(p->points);
|
||||||
p->points = NULL;
|
p->points = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeROIVector(ROIVector *p) {
|
void FreePoseROIVector(PoseROIVector *p) {
|
||||||
if (p->items!= NULL) {
|
if (p->items!= NULL) {
|
||||||
free(p->items);
|
free(p->items);
|
||||||
p->items= NULL;
|
p->items= NULL;
|
||||||
|
@@ -4,12 +4,12 @@
|
|||||||
#include "../../common/common.h"
|
#include "../../common/common.h"
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
struct Keypoint {
|
struct PoseKeypoint {
|
||||||
Point2f p;
|
Point2f p;
|
||||||
float prob;
|
float prob;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ROI {
|
struct PoseROI {
|
||||||
Rect rect;
|
Rect rect;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
float score;
|
float score;
|
||||||
|
@@ -9,12 +9,10 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
typedef void* IDetecter;
|
typedef void* IDetecter;
|
||||||
IDetecter new_ultralight();
|
IDetecter new_ultralight();
|
||||||
void destroy_detecter(IDetecter d);
|
int extract_pose_rois(IDetecter d, const unsigned char* rgbdata,
|
||||||
int detecter_load_model(IDetecter d, const char* root_path);
|
|
||||||
int extract_rois(IDetecter d, const unsigned char* rgbdata,
|
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
ROIVector* rois);
|
PoseROIVector* rois);
|
||||||
int extract_keypoints(IDetecter d, const ROI* roi,KeypointVector* keypoints);
|
int extract_pose_keypoints(IDetecter d, const PoseROI* roi, PoseKeypointVector* keypoints);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,41 +1,33 @@
|
|||||||
#include "../detecter.h"
|
#include "../detecter.h"
|
||||||
#include "utralight/utralight.hpp"
|
#include "ultralight/ultralight.hpp"
|
||||||
|
|
||||||
IDetecter new_utralight() {
|
IDetecter new_ultralight() {
|
||||||
return new ov::Utralight();
|
return new ov::Ultralight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_detecter(IDetecter d) {
|
int extract_pose_rois(IDetecter d, const unsigned char* rgbdata, int img_width, int img_height, PoseROIVector* rois) {
|
||||||
delete static_cast<ov::Detecter*>(d);
|
std::vector<PoseROI> detected;
|
||||||
}
|
|
||||||
|
|
||||||
int detecter_load_model(IDetecter d, const char *root_path){
|
|
||||||
return static_cast<ov::Detecter*>(d)->LoadModel(root_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
int extract_rois(IDetecter d, const unsigned char* rgbdata, int img_width, int img_height, ROIVector* rois) {
|
|
||||||
std::vector<ROI> detected;
|
|
||||||
int ret = static_cast<ov::Detecter*>(d)->ExtractROIs(rgbdata, img_width, img_height, &detected);
|
int ret = static_cast<ov::Detecter*>(d)->ExtractROIs(rgbdata, img_width, img_height, &detected);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
rois->length = detected.size();
|
rois->length = detected.size();
|
||||||
rois->items = (ROI*)malloc(rois->length * sizeof(ROI));
|
rois->items = (PoseROI*)malloc(rois->length * sizeof(PoseROI));
|
||||||
for (size_t i = 0; i < detected.size(); ++i) {
|
for (size_t i = 0; i < detected.size(); ++i) {
|
||||||
rois->items[i] = detected[i];
|
rois->items[i] = detected[i];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int extract_keypoints(IDetecter d, const ROI* roi, KeypointVector* keypoints) {
|
int extract_pose_keypoints(IDetecter d, const PoseROI* roi, PoseKeypointVector* keypoints) {
|
||||||
std::vector<Keypoint> points;
|
std::vector<PoseKeypoint> points;
|
||||||
int ret = static_cast<ov::Detecter*>(d)->ExtractKeypoints(*roi, &points);
|
int ret = static_cast<ov::Detecter*>(d)->ExtractKeypoints(*roi, &points);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
keypoints->length = points.size();
|
keypoints->length = points.size();
|
||||||
keypoints->points = (Keypoint*)malloc(keypoints->length * sizeof(Keypoint));
|
keypoints->points = (PoseKeypoint*)malloc(keypoints->length * sizeof(PoseKeypoint));
|
||||||
for (size_t i = 0; i < points.size(); ++i) {
|
for (size_t i = 0; i < points.size(); ++i) {
|
||||||
keypoints->points[i] = points[i];
|
keypoints->points[i] = points[i];
|
||||||
}
|
}
|
||||||
@@ -43,7 +35,7 @@ int extract_keypoints(IDetecter d, const ROI* roi, KeypointVector* keypoints) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace ov{
|
namespace ov{
|
||||||
Detecter* UtralightFactory::CreateDetecter() {
|
Detecter* UltralightFactory::CreateDetecter() {
|
||||||
return new Utralight();
|
return new Ultralight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,14 +5,13 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
namespace ov {
|
namespace ov {
|
||||||
|
|
||||||
class Detecter {
|
class Detecter: Estimator {
|
||||||
public:
|
public:
|
||||||
virtual ~Detecter(){};
|
virtual ~Detecter(){};
|
||||||
virtual int LoadModel(const char* root_path) = 0;
|
|
||||||
virtual int ExtractROIs(const unsigned char* rgbadata,
|
virtual int ExtractROIs(const unsigned char* rgbadata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
std::vector<ROI>* rois) = 0;
|
std::vector<PoseROI>* rois) = 0;
|
||||||
virtual int ExtractKeypoints(const ROI& roi, std::vector<Keypoint>* keypoints) = 0;
|
virtual int ExtractKeypoints(const PoseROI& roi, std::vector<PoseKeypoint>* keypoints) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DetecterFactory {
|
class DetecterFactory {
|
||||||
@@ -21,10 +20,10 @@ public:
|
|||||||
virtual ~DetecterFactory() {};
|
virtual ~DetecterFactory() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class UtralightFactory: public DetecterFactory {
|
class UltralightFactory: public DetecterFactory {
|
||||||
public:
|
public:
|
||||||
UtralightFactory() {}
|
UltralightFactory() {}
|
||||||
~UtralightFactory() {}
|
~UltralightFactory() {}
|
||||||
Detecter* CreateDetecter();
|
Detecter* CreateDetecter();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#include "utralight.hpp"
|
#include "ultralight.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef OV_VULKAN
|
#ifdef OV_VULKAN
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#endif // OV_VULKAN
|
#endif // OV_VULKAN
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
Utralight::Utralight() {
|
Ultralight::Ultralight() {
|
||||||
roi_net_ = new ncnn::Net();
|
roi_net_ = new ncnn::Net();
|
||||||
pose_net_ = new ncnn::Net();
|
pose_net_ = new ncnn::Net();
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
@@ -16,12 +16,12 @@ Utralight::Utralight() {
|
|||||||
#endif // OV_VULKAN
|
#endif // OV_VULKAN
|
||||||
}
|
}
|
||||||
|
|
||||||
Utralight::~Utralight() {
|
Ultralight::~Ultralight() {
|
||||||
roi_net_->clear();
|
roi_net_->clear();
|
||||||
pose_net_->clear();
|
pose_net_->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utralight::LoadModel(const char * root_path) {
|
int Ultralight::LoadModel(const char * root_path) {
|
||||||
std::string roi_param_file = std::string(root_path) + "/roi.param";
|
std::string roi_param_file = std::string(root_path) + "/roi.param";
|
||||||
std::string roi_bin_file = std::string(root_path) + "/roi.bin";
|
std::string roi_bin_file = std::string(root_path) + "/roi.bin";
|
||||||
if (roi_net_->load_param(roi_param_file.c_str()) == -1 ||
|
if (roi_net_->load_param(roi_param_file.c_str()) == -1 ||
|
||||||
@@ -40,9 +40,9 @@ int Utralight::LoadModel(const char * root_path) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utralight::ExtractROIs(const unsigned char* rgbdata,
|
int Ultralight::ExtractROIs(const unsigned char* rgbdata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
std::vector<ROI>* rois) {
|
std::vector<PoseROI>* rois) {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
return 10000;
|
return 10000;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,6 @@ int Utralight::ExtractROIs(const unsigned char* rgbdata,
|
|||||||
|
|
||||||
for (int i = 0; i < out.h; i++)
|
for (int i = 0; i < out.h; i++)
|
||||||
{
|
{
|
||||||
printf("==================================\n");
|
|
||||||
float x1, y1, x2, y2, score, label;
|
float x1, y1, x2, y2, score, label;
|
||||||
float pw,ph,cx,cy;
|
float pw,ph,cx,cy;
|
||||||
const float* values = out.row(i);
|
const float* values = out.row(i);
|
||||||
@@ -108,7 +107,7 @@ int Utralight::ExtractROIs(const unsigned char* rgbdata,
|
|||||||
unsigned char* dstCursor = cropdata + i * rect.width * 3;
|
unsigned char* dstCursor = cropdata + i * rect.width * 3;
|
||||||
memcpy(dstCursor, srcCursor, sizeof(unsigned char) * 3 * rect.width);
|
memcpy(dstCursor, srcCursor, sizeof(unsigned char) * 3 * rect.width);
|
||||||
}
|
}
|
||||||
ROI roi;
|
PoseROI roi;
|
||||||
roi.rect = rect;
|
roi.rect = rect;
|
||||||
roi.data = cropdata;
|
roi.data = cropdata;
|
||||||
roi.score = score;
|
roi.score = score;
|
||||||
@@ -118,7 +117,7 @@ int Utralight::ExtractROIs(const unsigned char* rgbdata,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utralight::ExtractKeypoints(const ROI& roi, std::vector<Keypoint>* keypoints) {
|
int Ultralight::ExtractKeypoints(const PoseROI& roi, std::vector<PoseKeypoint>* keypoints) {
|
||||||
keypoints->clear();
|
keypoints->clear();
|
||||||
int w = roi.rect.width;
|
int w = roi.rect.width;
|
||||||
int h = roi.rect.height;
|
int h = roi.rect.height;
|
||||||
@@ -155,7 +154,7 @@ int Utralight::ExtractKeypoints(const ROI& roi, std::vector<Keypoint>* keypoints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Keypoint keypoint;
|
PoseKeypoint keypoint;
|
||||||
keypoint.p = Point2f(max_x * w / (float)out.w+roi.rect.x, max_y * h / (float)out.h+roi.rect.y);
|
keypoint.p = Point2f(max_x * w / (float)out.w+roi.rect.x, max_y * h / (float)out.h+roi.rect.y);
|
||||||
keypoint.prob = max_prob;
|
keypoint.prob = max_prob;
|
||||||
keypoints->push_back(keypoint);
|
keypoints->push_back(keypoint);
|
@@ -1,5 +1,5 @@
|
|||||||
#ifndef _POSE_UTRALIGHT_H_
|
#ifndef _POSE_ULTRALIGHT_H_
|
||||||
#define _POSE_UTRALIGHT_H_
|
#define _POSE_ULTRALIGHT_H_
|
||||||
|
|
||||||
#include "../detecter.hpp"
|
#include "../detecter.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -7,17 +7,17 @@
|
|||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
|
|
||||||
class Utralight : public Detecter {
|
class Ultralight : public Detecter {
|
||||||
public:
|
public:
|
||||||
Utralight();
|
Ultralight();
|
||||||
~Utralight();
|
~Ultralight();
|
||||||
|
|
||||||
int LoadModel(const char* root_path);
|
int LoadModel(const char* root_path);
|
||||||
int ExtractROIs(const unsigned char* rgbadata,
|
int ExtractROIs(const unsigned char* rgbadata,
|
||||||
int img_width, int img_height,
|
int img_width, int img_height,
|
||||||
std::vector<ROI>* rois);
|
std::vector<PoseROI>* rois);
|
||||||
int ExtractKeypoints(const ROI& roi,
|
int ExtractKeypoints(const PoseROI& roi,
|
||||||
std::vector<Keypoint>* keypoints);
|
std::vector<PoseKeypoint>* keypoints);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ncnn::Net* roi_net_;
|
ncnn::Net* roi_net_;
|
||||||
@@ -27,5 +27,5 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !_POSE_MOBILEFACENET_H_
|
#endif // !_POSE_ULTRALIGHT_H_
|
||||||
|
|
@@ -54,14 +54,6 @@ RealEsrgan new_realesrgan(int gpuid, bool _tta_model) {
|
|||||||
return new ov::RealESRGAN(gpuid, _tta_model);
|
return new ov::RealESRGAN(gpuid, _tta_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_realesrgan(RealEsrgan r) {
|
|
||||||
delete static_cast<ov::RealESRGAN*>(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
int realesrgan_load_model(RealEsrgan r, const char* root_path) {
|
|
||||||
return static_cast<ov::RealESRGAN*>(r)->LoadModel(root_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
int realesrgan_process(RealEsrgan r, const unsigned char* rgbdata, int img_width, int img_height, int scale, Bytes* output) {
|
int realesrgan_process(RealEsrgan r, const unsigned char* rgbdata, int img_width, int img_height, int scale, Bytes* output) {
|
||||||
size_t total_size = img_width * img_height * scale * scale * 3;
|
size_t total_size = img_width * img_height * scale * scale * 3;
|
||||||
#ifdef OV_VULKAN
|
#ifdef OV_VULKAN
|
||||||
|
@@ -9,8 +9,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
typedef void* RealEsrgan;
|
typedef void* RealEsrgan;
|
||||||
RealEsrgan new_realesrgan(int gpuid, bool _ttad_model);
|
RealEsrgan new_realesrgan(int gpuid, bool _ttad_model);
|
||||||
void destroy_realesrgan(RealEsrgan r);
|
|
||||||
int realesrgan_load_model(RealEsrgan r, const char* root_path);
|
|
||||||
int realesrgan_process(RealEsrgan r, const unsigned char* rgbdata, int img_width, int img_height, int scale, Bytes* output);
|
int realesrgan_process(RealEsrgan r, const unsigned char* rgbdata, int img_width, int img_height, int scale, Bytes* output);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#ifndef _REALESRGAN_H
|
#ifndef _REALESRGAN_H
|
||||||
#define _REALESRGAN_H
|
#define _REALESRGAN_H
|
||||||
|
|
||||||
|
#include "../common/common.hpp"
|
||||||
// ncnn
|
// ncnn
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
@@ -10,14 +11,11 @@
|
|||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
|
|
||||||
class RealESRGAN
|
class RealESRGAN: public Estimator {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
RealESRGAN(int gpuid, bool tta_mode = false);
|
RealESRGAN(int gpuid, bool tta_mode = false);
|
||||||
~RealESRGAN();
|
~RealESRGAN();
|
||||||
|
int LoadModel(const char* root_path);
|
||||||
int LoadModel(const char* root_path);
|
|
||||||
|
|
||||||
int process(const ncnn::Mat& inimage, ncnn::Mat& outimage) const;
|
int process(const ncnn::Mat& inimage, ncnn::Mat& outimage) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user