Skip to content

Commit

Permalink
added TrackerGOTURN (see roadmap)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohce authored and deadprogram committed Sep 16, 2024
1 parent 88c11e5 commit e3a10b9
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:
curl -sL https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/detect.prototxt > ${GITHUB_WORKSPACE}/testdata/detect.prototxt
curl -sL https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/sr.caffemodel > ${GITHUB_WORKSPACE}/testdata/sr.caffemodel
curl -sL https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/sr.prototxt > ${GITHUB_WORKSPACE}/testdata/sr.prototxt
curl -sL https://raw.githubusercontent.com/opencv/opencv_extra/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.prototxt > ${GITHUB_WORKSPACE}/goturn.prototxt
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.001 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.001
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.002 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.002
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.003 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.003
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.004 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.004
cat ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.001 ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.002 ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.003 ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.004 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip
unzip -o ${GITHUB_WORKSPACE}/goturn.caffemodel.zip goturn.caffemodel -d ${GITHUB_WORKSPACE}/
- name: Install Tensorflow test model
run: |
mkdir -p ${GITHUB_WORKSPACE}/testdata
Expand All @@ -40,6 +48,7 @@ jobs:
DISPLAY: 99.0
GOCV_TENSORFLOW_TEST_FILES: ${{ github.workspace }}/testdata
GOCV_ONNX_TEST_FILES: ${{ github.workspace }}/testdata
GOCV_TRACKER_GOTURN_TEST_FILES: ${{ github.workspace }}
- name: Run contrib tests
run: xvfb-run -a --error-file /var/log/xvfb_error.log --server-args="-screen 0 1024x768x24 +extension RANDR" go test -v -coverprofile=/tmp/contrib.out -count=1 -tags matprofile ./contrib
env:
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
curl -sL https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/detect.prototxt > ${GITHUB_WORKSPACE}/testdata/detect.prototxt
curl -sL https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/sr.caffemodel > ${GITHUB_WORKSPACE}/testdata/sr.caffemodel
curl -sL https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/sr.prototxt > ${GITHUB_WORKSPACE}/testdata/sr.prototxt
curl -sL https://raw.githubusercontent.com/opencv/opencv_extra/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.prototxt > ${GITHUB_WORKSPACE}/goturn.prototxt
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.001 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.001
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.002 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.002
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.003 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.003
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.004 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.004
cat ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.001 ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.002 ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.003 ${GITHUB_WORKSPACE}/goturn.caffemodel.zip.004 > ${GITHUB_WORKSPACE}/goturn.caffemodel.zip
unzip -o ${GITHUB_WORKSPACE}/goturn.caffemodel.zip goturn.caffemodel -d ${GITHUB_WORKSPACE}/
- name: Install Tensorflow test model
run: |
mkdir -p ${GITHUB_WORKSPACE}/testdata
Expand All @@ -48,5 +56,6 @@ jobs:
env:
GOCV_TENSORFLOW_TEST_FILES: ${{ github.workspace }}/testdata
GOCV_ONNX_TEST_FILES: ${{ github.workspace }}/testdata
GOCV_TRACKER_GOTURN_TEST_FILES: ${{ github.workspace }}
- name: Run contrib tests
run: go test -v -tags matprofile ./contrib
14 changes: 13 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,24 @@ jobs:
unzip -o ./testdata/inception5h.zip tensorflow_inception_graph.pb -d ./testdata
- name: Install ONNX test model
run: |
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/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ./testdata/googlenet-9.onnx
- name: Install Caffe test model
shell: bash
run: |
curl -sL https://raw.githubusercontent.com/opencv/opencv_extra/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.prototxt > ./testdata/goturn.prototxt
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.001 > ./testdata/goturn.caffemodel.zip.001
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.002 > ./testdata/goturn.caffemodel.zip.002
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.003 > ./testdata/goturn.caffemodel.zip.003
curl -sL https://github.com/opencv/opencv_extra/raw/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking/goturn.caffemodel.zip.004 > ./testdata/goturn.caffemodel.zip.004
cat ./testdata/goturn.caffemodel.zip.00* > ./testdata/goturn.caffemodel.zip
unzip -o ./testdata/goturn.caffemodel.zip goturn.caffemodel -d ./testdata/
- name: Set GoCV model env
run: |
go env
echo "GOCV_TENSORFLOW_TEST_FILES=${env:GITHUB_WORKSPACE}\testdata" >> $env:GITHUB_ENV
echo "GOCV_ONNX_TEST_FILES=${env:GITHUB_WORKSPACE}\testdata" >> $env:GITHUB_ENV
echo "GOCV_TRACKER_GOTURN_TEST_FILES=${env:GITHUB_WORKSPACE}\testdata" >> $env:GITHUB_ENV
- name: Test GoCV
run: |
go test -v -tags="matprofile,customenv" .
Expand Down
18 changes: 18 additions & 0 deletions video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ void TrackerMIL_Close(TrackerMIL self) {
delete self;
}

TrackerGOTURN TrackerGOTURN_Create(void){
return new cv::Ptr<cv::TrackerGOTURN>(cv::TrackerGOTURN::create());
}

TrackerGOTURN TrackerGOTURN_CreateWithParams(const char* modelBin, const char* modelTxt){

cv::TrackerGOTURN::Params params;
params.modelBin = modelBin;
params.modelTxt = modelTxt;

return new cv::Ptr<cv::TrackerGOTURN>(cv::TrackerGOTURN::create(params));
}


void TrackerGOTURN_Close(TrackerGOTURN tr) {
delete tr;
}

KalmanFilter KalmanFilter_New(int dynamParams, int measureParams) {
return new cv::KalmanFilter(dynamParams, measureParams, 0, CV_32F);
}
Expand Down
51 changes: 51 additions & 0 deletions video.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,57 @@ func (trk TrackerMIL) Update(img Mat) (image.Rectangle, bool) {
return trackerUpdate(C.Tracker(trk.p), img)
}

type TrackerGOTURN struct {
p C.TrackerGOTURN
}

// NewTrackerGOTURN the GOTURN (Generic Object Tracking Using Regression Networks) tracker
// GOTURN ([122]) is kind of trackers based on Convolutional Neural Networks (CNN).
//
// For further details, please see:
// https://docs.opencv.org/4.x/d7/d4c/classcv_1_1TrackerGOTURN.html#details
func NewTrackerGOTURN() TrackerGOTURN {
return TrackerGOTURN{p: C.TrackerGOTURN_Create()}
}

// NewTrackerGOTURNWithParams the GOTURN (Generic Object Tracking Using Regression Networks) tracker
// GOTURN ([122]) is kind of trackers based on Convolutional Neural Networks (CNN).
//
// For further details, please see:
// https://docs.opencv.org/4.x/d7/d4c/classcv_1_1TrackerGOTURN.html#details
func NewTrackerGOTURNWithParams(modelBin string, modelTxt string) TrackerGOTURN {
c_modelBin := C.CString(modelBin)
c_modelTxt := C.CString(modelTxt)
defer C.free(unsafe.Pointer(c_modelBin))
defer C.free(unsafe.Pointer(c_modelTxt))

return TrackerGOTURN{p: C.TrackerGOTURN_CreateWithParams(c_modelBin, c_modelTxt)}
}

// Init initializes the tracker with a known bounding box that surrounded the target.
// Note: this can only be called once. If you lose the object, you have to Close() the instance,
// create a new one, and call Init() on it again.
//
// see: https://docs.opencv.org/master/d0/d0a/classcv_1_1Tracker.html#a4d285747589b1bdd16d2e4f00c3255dc
func (t TrackerGOTURN) Init(mat Mat, boundingBox image.Rectangle) bool {
return trackerInit(C.Tracker(t.p), mat, boundingBox)
}

// Update updates the tracker, returns a new bounding box and a boolean determining whether the tracker lost the target.
//
// see: https://docs.opencv.org/master/d0/d0a/classcv_1_1Tracker.html#a549159bd0553e6a8de356f3866df1f18
func (t TrackerGOTURN) Update(mat Mat) (image.Rectangle, bool) {
return trackerUpdate(C.Tracker(t.p), mat)

}

func (t TrackerGOTURN) Close() error {
C.TrackerGOTURN_Close(t.p)
t.p = nil
return nil

}

// 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.
Expand Down
4 changes: 4 additions & 0 deletions video.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ bool Tracker_Update(Tracker self, Mat image, Rect* boundingBox);
TrackerMIL TrackerMIL_Create();
void TrackerMIL_Close(TrackerMIL self);

TrackerGOTURN TrackerGOTURN_Create(void);
TrackerGOTURN TrackerGOTURN_CreateWithParams(const char* modelBin, const char* modelTxt);
void TrackerGOTURN_Close(TrackerGOTURN tr);

KalmanFilter KalmanFilter_New(int dynamParams, int measureParams);
KalmanFilter KalmanFilter_NewWithParams(int dynamParams, int measureParams, int controlParams, int type);
void KalmanFilter_Close(KalmanFilter kf);
Expand Down
5 changes: 4 additions & 1 deletion video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"image"
"image/color"
"math"
"os"
"testing"
)

Expand Down Expand Up @@ -286,12 +287,14 @@ func BaseTestTracker(t *testing.T, tracker Tracker, name string) {
}

func TestSingleTrackers(t *testing.T) {
goturnPath := os.Getenv("GOCV_TRACKER_GOTURN_TEST_FILES")

tab := []struct {
name string
tracker Tracker
}{
{"MIL", NewTrackerMIL()},
// {"GOTURN", NewTrackerGOTURN()},
{"GOTURN", NewTrackerGOTURNWithParams(goturnPath+"/goturn.caffemodel", goturnPath+"/goturn.prototxt")},
}

for _, test := range tab {
Expand Down

0 comments on commit e3a10b9

Please sign in to comment.