Commit 43925b60 authored by berak's avatar berak

tracking: make opencv_dnn dependancy optional

parent ab63d35d
set(the_description "Tracking API") set(the_description "Tracking API")
ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui opencv_dnn opencv_plot OPTIONAL opencv_datasets WRAP java python) ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui opencv_plot OPTIONAL opencv_dnn opencv_datasets WRAP java python)
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
//1 - Train you own GOTURN model using <https://github.com/Auron-X/GOTURN_Training_Toolkit> //1 - Train you own GOTURN model using <https://github.com/Auron-X/GOTURN_Training_Toolkit>
//2 - Download pretrained caffemodel from <https://github.com/opencv/opencv_extra> //2 - Download pretrained caffemodel from <https://github.com/opencv/opencv_extra>
#include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_DNN) && defined(HAVE_OPENCV_DATASETS)
#include "opencv2/datasets/track_alov.hpp" #include "opencv2/datasets/track_alov.hpp"
#include <opencv2/core/utility.hpp> #include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp> #include <opencv2/tracking.hpp>
...@@ -65,8 +68,8 @@ static bool startSelection = false; ...@@ -65,8 +68,8 @@ static bool startSelection = false;
Rect2d boundingBox; Rect2d boundingBox;
static const char* keys = static const char* keys =
{ "{@dataset_path |true| Dataset path }" { "{@dataset_path || Dataset path }"
"{@dataset_id |1| Dataset ID }" "{@dataset_id |1| Dataset ID }"
}; };
static void onMouse(int event, int x, int y, int, void*) static void onMouse(int event, int x, int y, int, void*)
...@@ -144,9 +147,14 @@ int main(int argc, char *argv[]) ...@@ -144,9 +147,14 @@ int main(int argc, char *argv[])
Ptr<cv::datasets::TRACK_alov> dataset = TRACK_alov::create(); Ptr<cv::datasets::TRACK_alov> dataset = TRACK_alov::create();
dataset->load(datasetRootPath); dataset->load(datasetRootPath);
dataset->initDataset(datasetID); dataset->initDataset(datasetID);
//Read first frame //Read first frame
dataset->getNextFrame(frame); dataset->getNextFrame(frame);
if (frame.empty())
{
cout << "invalid dataset: " << datasetRootPath << endl;
return -2;
}
frame.copyTo(image); frame.copyTo(image);
rectangle(image, boundingBox, Scalar(255, 0, 0), 2, 1); rectangle(image, boundingBox, Scalar(255, 0, 0), 2, 1);
imshow("GOTURN Tracking", image); imshow("GOTURN Tracking", image);
...@@ -215,3 +223,11 @@ int main(int argc, char *argv[]) ...@@ -215,3 +223,11 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
#else // ! HAVE_OPENCV_DNN && HAVE_OPENCV_DATASETS
#include <opencv2/core.hpp>
int main() {
CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets and opencv_dnn !");
return -1;
}
#endif
...@@ -234,6 +234,7 @@ int main(int argc, char *argv[]) ...@@ -234,6 +234,7 @@ int main(int argc, char *argv[])
} }
#else // ! HAVE_OPENCV_DATASETS #else // ! HAVE_OPENCV_DATASETS
#include <opencv2/core.hpp>
int main() { int main() {
CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets !"); CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets !");
return -1; return -1;
......
...@@ -234,6 +234,7 @@ int main(int argc, char *argv[]) ...@@ -234,6 +234,7 @@ int main(int argc, char *argv[])
#else // ! HAVE_OPENCV_DATASETS #else // ! HAVE_OPENCV_DATASETS
#include <opencv2/core.hpp>
int main() { int main() {
CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets !"); CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets !");
return -1; return -1;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#include "opencv2/opencv_modules.hpp"
#include "gtrTracker.hpp" #include "gtrTracker.hpp"
...@@ -54,9 +54,16 @@ void TrackerGOTURN::Params::write(cv::FileStorage& /*fs*/) const {} ...@@ -54,9 +54,16 @@ void TrackerGOTURN::Params::write(cv::FileStorage& /*fs*/) const {}
Ptr<TrackerGOTURN> TrackerGOTURN::createTracker(const TrackerGOTURN::Params &parameters) Ptr<TrackerGOTURN> TrackerGOTURN::createTracker(const TrackerGOTURN::Params &parameters)
{ {
#ifdef HAVE_OPENCV_DNN
return Ptr<gtr::TrackerGOTURNImpl>(new gtr::TrackerGOTURNImpl(parameters)); return Ptr<gtr::TrackerGOTURNImpl>(new gtr::TrackerGOTURNImpl(parameters));
#else
(void)(parameters);
CV_ErrorNoReturn(cv::Error::StsNotImplemented , "to use GOTURN, the tracking module needs to be built with opencv_dnn !");
#endif
} }
#ifdef HAVE_OPENCV_DNN
namespace gtr namespace gtr
{ {
...@@ -183,9 +190,11 @@ bool TrackerGOTURNImpl::updateImpl(const Mat& image, Rect2d& boundingBox) ...@@ -183,9 +190,11 @@ bool TrackerGOTURNImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
//Set new model image and BB from current frame //Set new model image and BB from current frame
((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setImage(curFrame); ((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setImage(curFrame);
((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setBoudingBox(curBB); ((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setBoudingBox(curBB);
return true; return true;
} }
} }
#endif // OPENCV_HAVE_DNN
} }
...@@ -45,11 +45,15 @@ ...@@ -45,11 +45,15 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "opencv2/video/tracking.hpp" #include "opencv2/video/tracking.hpp"
#include "opencv2/dnn.hpp"
#include "gtrUtils.hpp" #include "gtrUtils.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include<algorithm>
#include<limits.h> #include <algorithm>
#include <limits.h>
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCV_DNN
#include "opencv2/dnn.hpp"
namespace cv namespace cv
{ {
...@@ -72,5 +76,5 @@ public: ...@@ -72,5 +76,5 @@ public:
} }
} }
#endif
#endif #endif
...@@ -58,7 +58,7 @@ double generateRandomLaplacian(double b, double m) ...@@ -58,7 +58,7 @@ double generateRandomLaplacian(double b, double m)
return m - b*log(n); return m - b*log(n);
} }
Rect2f anno2rect(vector<Point2f> annoBB) Rect2f anno2rect(std::vector<Point2f> annoBB)
{ {
Rect2f rectBB; Rect2f rectBB;
rectBB.x = min(annoBB[0].x, annoBB[1].x); rectBB.x = min(annoBB[0].x, annoBB[1].x);
...@@ -69,9 +69,9 @@ Rect2f anno2rect(vector<Point2f> annoBB) ...@@ -69,9 +69,9 @@ Rect2f anno2rect(vector<Point2f> annoBB)
return rectBB; return rectBB;
} }
vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB) std::vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB)
{ {
vector <TrainingSample> trainingSamples; std::vector <TrainingSample> trainingSamples;
Point2f currCenter, prevCenter; Point2f currCenter, prevCenter;
Rect2f targetPatchRect, searchPatchRect; Rect2f targetPatchRect, searchPatchRect;
Mat targetPatch, searchPatch; Mat targetPatch, searchPatch;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "precomp.hpp" #include "precomp.hpp"
#include <vector> #include <vector>
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include <opencv2/datasets/track_alov.hpp>
namespace cv namespace cv
{ {
...@@ -50,10 +49,10 @@ struct TrainingSample ...@@ -50,10 +49,10 @@ struct TrainingSample
double generateRandomLaplacian(double b, double m); double generateRandomLaplacian(double b, double m);
//Convert ALOV300++ anno coordinates to Rectangle BB //Convert ALOV300++ anno coordinates to Rectangle BB
Rect2f anno2rect(vector<Point2f> annoBB); Rect2f anno2rect(std::vector<Point2f> annoBB);
//Gather samples from random video frame //Gather samples from random video frame
vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB); std::vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB);
} }
} }
......
...@@ -112,6 +112,7 @@ Ptr<Tracker> Tracker::create( const String& trackerType ) ...@@ -112,6 +112,7 @@ Ptr<Tracker> Tracker::create( const String& trackerType )
BOILERPLATE_CODE("TLD",TrackerTLD); BOILERPLATE_CODE("TLD",TrackerTLD);
BOILERPLATE_CODE("KCF",TrackerKCF); BOILERPLATE_CODE("KCF",TrackerKCF);
BOILERPLATE_CODE("GOTURN", TrackerGOTURN); BOILERPLATE_CODE("GOTURN", TrackerGOTURN);
return Ptr<Tracker>(); return Ptr<Tracker>();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment