mirror of
https://github.com/hybridgroup/gocv
synced 2025-08-25 08:41:04 +08:00
feature: add video tracker implementation using Vit DNN
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
1
.github/workflows/linux.yml
vendored
1
.github/workflows/linux.yml
vendored
@@ -46,6 +46,7 @@ jobs:
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ${GITHUB_WORKSPACE}/testdata/object_tracking_vittrack_2023sep.onnx
|
||||
- name: Run main tests
|
||||
run: xvfb-run -a --error-file /var/log/xvfb_error.log --server-args="-screen 0 1024x768x24 +extension RANDR" go test -v -coverprofile=/tmp/coverage.out -count=1 -tags matprofile .
|
||||
env:
|
||||
|
1
.github/workflows/macos.yml
vendored
1
.github/workflows/macos.yml
vendored
@@ -56,6 +56,7 @@ jobs:
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ${GITHUB_WORKSPACE}/testdata/object_tracking_vittrack_2023sep.onnx
|
||||
- name: Run main tests
|
||||
run: go test -v -tags matprofile .
|
||||
env:
|
||||
|
1
.github/workflows/windows.yml
vendored
1
.github/workflows/windows.yml
vendored
@@ -92,6 +92,7 @@ jobs:
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ./testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ./testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ./testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ./testdata/object_tracking_vittrack_2023sep.onnx
|
||||
- name: Install GOTURN test model
|
||||
shell: bash
|
||||
run: |
|
||||
|
1
Makefile
1
Makefile
@@ -362,6 +362,7 @@ download_onnx_testdata: create_testdata_dir
|
||||
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ./testdata/googlenet-9.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ./testdata/face_recognition_sface_2021dec.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ./testdata/face_detection_yunet_2023mar.onnx
|
||||
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx > ./testdata/object_tracking_vittrack_2023sep.onnx
|
||||
|
||||
download_goturn_testdata: create_testdata_dir
|
||||
curl -sL https://raw.githubusercontent.com/opencv/opencv_extra/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.prototxt > ./testdata/goturn.prototxt
|
||||
|
25
video.cpp
25
video.cpp
@@ -190,6 +190,31 @@ void TrackerGOTURN_Close(TrackerGOTURN tr) {
|
||||
delete tr;
|
||||
}
|
||||
|
||||
TrackerVit TrackerVit_Create() {
|
||||
try {
|
||||
return new cv::Ptr<cv::TrackerVit>(cv::TrackerVit::create());
|
||||
} catch(const cv::Exception& e){
|
||||
setExceptionInfo(e.code, e.what());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
TrackerVit TrackerVit_CreateWithParams(const char* model){
|
||||
try {
|
||||
cv::TrackerVit::Params params;
|
||||
params.net = model;
|
||||
|
||||
return new cv::Ptr<cv::TrackerVit>(cv::TrackerVit::create(params));
|
||||
} catch(const cv::Exception& e){
|
||||
setExceptionInfo(e.code, e.what());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void TrackerVit_Close(TrackerVit self) {
|
||||
delete self;
|
||||
}
|
||||
|
||||
KalmanFilter KalmanFilter_New(int dynamParams, int measureParams) {
|
||||
try {
|
||||
return new cv::KalmanFilter(dynamParams, measureParams, 0, CV_32F);
|
||||
|
37
video.go
37
video.go
@@ -301,6 +301,43 @@ func (t TrackerGOTURN) Close() error {
|
||||
|
||||
}
|
||||
|
||||
// TrackerVit is a Tracker using the Vit tracker, a super lightweight dnn-based general object tracking.
|
||||
//
|
||||
// For further details, please see:
|
||||
// https://docs.opencv.org/4.x/d9/d26/classcv_1_1TrackerVit.html
|
||||
type TrackerVit struct {
|
||||
p C.TrackerVit
|
||||
}
|
||||
|
||||
// NewTrackerVit returns a new TrackerVit.
|
||||
func NewTrackerVit() Tracker {
|
||||
return TrackerVit{p: C.TrackerVit_Create()}
|
||||
}
|
||||
|
||||
func NewTrackerVitWithParams(model string) TrackerVit {
|
||||
c_model := C.CString(model)
|
||||
defer C.free(unsafe.Pointer(c_model))
|
||||
|
||||
return TrackerVit{p: C.TrackerVit_CreateWithParams(c_model)}
|
||||
}
|
||||
|
||||
// Close closes the TrackerMIL.
|
||||
func (trk TrackerVit) Close() error {
|
||||
C.TrackerVit_Close(trk.p)
|
||||
trk.p = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Init initializes the TrackerVIT.
|
||||
func (trk TrackerVit) Init(img Mat, boundingBox image.Rectangle) bool {
|
||||
return trackerInit(C.Tracker(trk.p), img, boundingBox)
|
||||
}
|
||||
|
||||
// Update updates the TrackerVIT.
|
||||
func (trk TrackerVit) Update(img Mat) (image.Rectangle, bool) {
|
||||
return trackerUpdate(C.Tracker(trk.p), img)
|
||||
}
|
||||
|
||||
// KalmanFilter implements a standard Kalman filter http://en.wikipedia.org/wiki/Kalman_filter.
|
||||
// However, you can modify transitionMatrix, controlMatrix, and measurementMatrix
|
||||
// to get an extended Kalman filter functionality.
|
||||
|
6
video.h
6
video.h
@@ -15,6 +15,7 @@ typedef cv::Ptr<cv::BackgroundSubtractorKNN>* BackgroundSubtractorKNN;
|
||||
typedef cv::Ptr<cv::Tracker>* Tracker;
|
||||
typedef cv::Ptr<cv::TrackerMIL>* TrackerMIL;
|
||||
typedef cv::Ptr<cv::TrackerGOTURN>* TrackerGOTURN;
|
||||
typedef cv::Ptr<cv::TrackerVit>* TrackerVit;
|
||||
typedef cv::KalmanFilter* KalmanFilter;
|
||||
#else
|
||||
typedef void* BackgroundSubtractorMOG2;
|
||||
@@ -22,6 +23,7 @@ typedef void* BackgroundSubtractorKNN;
|
||||
typedef void* Tracker;
|
||||
typedef void* TrackerMIL;
|
||||
typedef void* TrackerGOTURN;
|
||||
typedef void* TrackerVit;
|
||||
typedef void* KalmanFilter;
|
||||
#endif
|
||||
|
||||
@@ -54,6 +56,10 @@ TrackerGOTURN TrackerGOTURN_Create(void);
|
||||
TrackerGOTURN TrackerGOTURN_CreateWithParams(const char* modelBin, const char* modelTxt);
|
||||
void TrackerGOTURN_Close(TrackerGOTURN tr);
|
||||
|
||||
TrackerVit TrackerVit_Create();
|
||||
TrackerVit TrackerVit_CreateWithParams(const char* model);
|
||||
void TrackerVit_Close(TrackerVit self);
|
||||
|
||||
KalmanFilter KalmanFilter_New(int dynamParams, int measureParams);
|
||||
KalmanFilter KalmanFilter_NewWithParams(int dynamParams, int measureParams, int controlParams, int type);
|
||||
void KalmanFilter_Close(KalmanFilter kf);
|
||||
|
@@ -334,12 +334,18 @@ func TestSingleTrackers(t *testing.T) {
|
||||
goturnPath = "./testdata"
|
||||
}
|
||||
|
||||
vitPath := os.Getenv("GOCV_ONNX_TEST_FILES")
|
||||
if vitPath == "" {
|
||||
vitPath = "./testdata"
|
||||
}
|
||||
|
||||
tab := []struct {
|
||||
name string
|
||||
tracker Tracker
|
||||
}{
|
||||
{"MIL", NewTrackerMIL()},
|
||||
{"GOTURN", NewTrackerGOTURNWithParams(goturnPath+"/goturn.caffemodel", goturnPath+"/goturn.prototxt")},
|
||||
{"Vit", NewTrackerVitWithParams(vitPath + "/object_tracking_vittrack_2023sep.onnx")},
|
||||
}
|
||||
|
||||
for _, test := range tab {
|
||||
|
Reference in New Issue
Block a user