| | |
| | | package gosdk |
| | | |
| | | /* |
| | | #cgo CFLAGS: -I. -I./sdk/face/include -I./sdk/darknet/include -I/usr/local/cuda/include -w -g |
| | | #cgo CXXFLAGS: -I. -I./sdk/face/include -I./sdk/darknet/include -I/usr/local/cuda/include -w -g -std=c++11 |
| | | #cgo LDFLAGS: -L/usr/local/cuda/lib64 -L${SRCDIR}/sdk/face/lib/gpu -L${SRCDIR}/sdk/darknet/lib |
| | | #cgo CFLAGS: -I. -I./sdk/face/include -I./sdk/darknet/include -I/usr/local/cuda/include -I./sdk/plate/include -w -g |
| | | #cgo CXXFLAGS: -I. -I./sdk/face/include -I./sdk/darknet/include -I/usr/local/cuda/include -I./sdk/plate/include -w -g -std=c++11 |
| | | #cgo LDFLAGS: -L/usr/local/cuda/lib64 -L${SRCDIR}/sdk/face/lib/gpu -L${SRCDIR}/sdk/darknet/lib -L${SRCDIR}/sdk/plate/lib |
| | | #cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/sdk/face/lib/gpu:${SRCDIR}/sdk/darknet/lib |
| | | #cgo LDFLAGS: -ldarknet -lTHFaceImage -lTHFeature -lTHFaceProperty -lTHFaceTracking -lcudart -lcublas -lcurand -lrt -ldl -lpthread |
| | | #cgo LDFLAGS: -ldarknet -lTHFaceImage -lTHFeature -lTHFaceProperty -lTHFaceTracking -lcudart -lcublas -lcurand -lrt -ldl -lpthread -lthplateid |
| | | #include <stdlib.h> |
| | | #include "csdk.h" |
| | | */ |
| | |
| | | var count C.int |
| | | cfpos := C.c_api_face_detect(&count, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch)) |
| | | if cfpos != nil { |
| | | defer C.free(unsafe.Pointer(cfpos)) |
| | | return CFacePosArrayToGoArray(unsafe.Pointer(cfpos), int(count)) |
| | | } |
| | | return nil |
| | |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | p := C.c_api_face_extract(&featLen, pos, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch)) |
| | | defer C.free(unsafe.Pointer(p)) |
| | | b := C.GoBytes(unsafe.Pointer(p), featLen) |
| | | return b |
| | | } |
| | |
| | | func FaceCompare(feat1 []byte, feat2 []byte) float32 { |
| | | res := C.c_api_face_compare((*C.uchar)(unsafe.Pointer(&feat1[0])), (*C.uchar)(unsafe.Pointer(&feat2[0]))) |
| | | return float32(res) |
| | | } |
| | | |
| | | // FaceTrackOnly face tracker face only |
| | | func FaceTrackOnly(img SDKImage, ch int) []CRECT { |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var fCount C.int |
| | | rect := C.c_api_face_track_only(&fCount, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch)) |
| | | if rect != nil { |
| | | defer C.free(unsafe.Pointer(rect)) |
| | | return CRECTArrayToGoArray(unsafe.Pointer(rect), int(fCount)) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // FaceTrackDetect face tracker face detect |
| | | func FaceTrackDetect(img SDKImage, ch int) []CFaceInfo { |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var fCount C.int |
| | | finfo := C.c_api_face_track_only(&fCount, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch)) |
| | | if finfo != nil { |
| | | defer C.free(unsafe.Pointer(finfo)) |
| | | return CFaceInfoArrayToGoArray(unsafe.Pointer(finfo), int(fCount)) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // FaceTrackingInfo face track info |
| | |
| | | if cFinfo == nil { |
| | | return |
| | | } |
| | | defer C.free(unsafe.Pointer(cFinfo)) |
| | | goFinfo := CFaceInfoArrayToGoArray(unsafe.Pointer(cFinfo), int(fCount)) |
| | | |
| | | // 空,添加 |
| | |
| | | if cFinfo == nil { |
| | | return faces |
| | | } |
| | | defer C.free(unsafe.Pointer(cFinfo)) |
| | | faces = CFaceInfoArrayToGoArray(unsafe.Pointer(cFinfo), int(fCount)) |
| | | //if len(faces) > 0{ |
| | | // fmt.Println("faces detected:", len(faces)) |
| | |
| | | cobjinfo := C.c_api_yolo_detect(handle.handle, &count, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.float(thrsh), C.int(umns)) |
| | | |
| | | if cobjinfo != nil { |
| | | defer C.free(unsafe.Pointer(cobjinfo)) |
| | | return CYoloObjInfoArrayToGoArray(unsafe.Pointer(cobjinfo), int(count)) |
| | | } |
| | | return nil |
| | |
| | | *LastTrackID = id |
| | | return allObjs, newObjs |
| | | } |
| | | |
| | | func DefaultPlateIDSDKConfig() *CPlateIDCfg{ |
| | | return &CPlateIDCfg{ |
| | | FastMemorySize: 32, |
| | | MemorySize: 400, |
| | | MinPlateWidth: 60, |
| | | MaxPlateWidth: 400, |
| | | MaxImageWidth: 4096, |
| | | MaxImageHeight: 2160, |
| | | IsFieldImage: 0, |
| | | MovingImage: 1, |
| | | OrderOpt: 0, |
| | | LeanCorrection: 1, |
| | | ImproveSpeed: 0, |
| | | CarLogo: 1, |
| | | LotDetect: 1, |
| | | Shadow: 1, |
| | | ShieldRailing: 1, |
| | | CarModel: 1, |
| | | LocateTh: 5, |
| | | OCRTh: 2, |
| | | |
| | | Individual: 1, |
| | | TwoRowYellow: 1, |
| | | ArmPolice: 1, |
| | | ArmPolice2: 1, |
| | | TwoRowArmy: 1, |
| | | Tractor: 1, |
| | | Embassy: 1, |
| | | ChangNei: 1, |
| | | MinHang: 1, |
| | | Consulate: 1, |
| | | NewEnergy: 1, |
| | | OnlyTwoRowYellow: 0, |
| | | OnlyLocation: 0, |
| | | } |
| | | } |
| | | |
| | | // InitPlateIDDetector init plateid detector |
| | | func InitPlateIDDetector(config *CPlateIDCfg, soPath []byte) { |
| | | C.c_api_plate_id_init((*C.cPlateIDCfg)(unsafe.Pointer(config)), (*C.char)(unsafe.Pointer(&soPath[0]))) |
| | | } |
| | | |
| | | // PlateIDDetect plateid detect |
| | | func PlateIDDetect(img SDKImage) []CPlateIDResult { |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var count C.int |
| | | cppos := C.c_api_plate_id_detect(&count, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h)) |
| | | if cppos != nil { |
| | | defer C.free(unsafe.Pointer(cppos)) |
| | | return CPlateIDPosArrayToGoArray(unsafe.Pointer(cppos), int(count)) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func FreePlateIdDetector() int{ |
| | | return int(C.c_api_plate_id_free()) |
| | | } |