mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-20 21:40:49 +08:00
Merge pull request #2620 from ieliz:goturn
Bounding box fixes for GOTURN tracker * Trying to change branch from master to 3.4 * Removing unnecessary if statement * Frame existence check is added * Changes in GOTURN tracker for reading path to caffemodel and prototxt files in opencv_extra * Replacing get_data_path with findDataFile and moving paths in parameters * tracking: fix GOTURN model loading * Fixing GOTURN memory test: paths to GOTURN files are in cv::FileNode now * Fix * Fix * Fixing comments * Deleting trailing space * Trying to solve the problem with test * Removing ground truth reading part in GOTURN test * Removing trailing spaces * Trying to fix win64/win32 issue * Fixing problem with win32/win64 * Trying to solve issue with win32/win64
This commit is contained in:
@@ -1292,6 +1292,8 @@ public:
|
|||||||
Params();
|
Params();
|
||||||
void read(const FileNode& /*fn*/);
|
void read(const FileNode& /*fn*/);
|
||||||
void write(FileStorage& /*fs*/) const;
|
void write(FileStorage& /*fs*/) const;
|
||||||
|
String modelTxt;
|
||||||
|
String modelBin;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Constructor
|
/** @brief Constructor
|
||||||
|
@@ -45,7 +45,11 @@
|
|||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
|
|
||||||
TrackerGOTURN::Params::Params(){}
|
TrackerGOTURN::Params::Params()
|
||||||
|
{
|
||||||
|
modelTxt = "goturn.prototxt";
|
||||||
|
modelBin = "goturn.caffemodel";
|
||||||
|
}
|
||||||
|
|
||||||
void TrackerGOTURN::Params::read(const cv::FileNode& /*fn*/){}
|
void TrackerGOTURN::Params::read(const cv::FileNode& /*fn*/){}
|
||||||
|
|
||||||
@@ -75,7 +79,11 @@ class TrackerGOTURNModel : public TrackerModel{
|
|||||||
public:
|
public:
|
||||||
TrackerGOTURNModel(TrackerGOTURN::Params){}
|
TrackerGOTURNModel(TrackerGOTURN::Params){}
|
||||||
Rect2d getBoundingBox(){ return boundingBox_; }
|
Rect2d getBoundingBox(){ return boundingBox_; }
|
||||||
void setBoudingBox(Rect2d boundingBox){ boundingBox_ = boundingBox; }
|
void setBoudingBox(Rect2d boundingBox) {
|
||||||
|
if (image_.empty())
|
||||||
|
CV_Error(Error::StsInternal, "Set image first");
|
||||||
|
boundingBox_ = boundingBox & Rect2d(Point(0, 0), image_.size());
|
||||||
|
}
|
||||||
Mat getImage(){ return image_; }
|
Mat getImage(){ return image_; }
|
||||||
void setImage(const Mat& image){ image.copyTo(image_); }
|
void setImage(const Mat& image){ image.copyTo(image_); }
|
||||||
protected:
|
protected:
|
||||||
@@ -108,9 +116,7 @@ bool TrackerGOTURNImpl::initImpl(const Mat& image, const Rect2d& boundingBox)
|
|||||||
((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setBoudingBox(boundingBox);
|
((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setBoudingBox(boundingBox);
|
||||||
|
|
||||||
//Load GOTURN architecture from *.prototxt and pretrained weights from *.caffemodel
|
//Load GOTURN architecture from *.prototxt and pretrained weights from *.caffemodel
|
||||||
String modelTxt = "goturn.prototxt";
|
net = dnn::readNetFromCaffe(params.modelTxt, params.modelBin);
|
||||||
String modelBin = "goturn.caffemodel";
|
|
||||||
net = dnn::readNetFromCaffe(modelTxt, modelBin);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +143,11 @@ bool TrackerGOTURNImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
|
|||||||
targetPatchRect.x = (float)(prevCenter.x - prevBB.width*padTargetPatch / 2.0 + targetPatchRect.width);
|
targetPatchRect.x = (float)(prevCenter.x - prevBB.width*padTargetPatch / 2.0 + targetPatchRect.width);
|
||||||
targetPatchRect.y = (float)(prevCenter.y - prevBB.height*padTargetPatch / 2.0 + targetPatchRect.height);
|
targetPatchRect.y = (float)(prevCenter.y - prevBB.height*padTargetPatch / 2.0 + targetPatchRect.height);
|
||||||
|
|
||||||
|
targetPatchRect.width = std::min(targetPatchRect.width, (float)prevFrame.cols);
|
||||||
|
targetPatchRect.height = std::min(targetPatchRect.height, (float)prevFrame.rows);
|
||||||
|
targetPatchRect.x = std::max(-prevFrame.cols * 0.5f, std::min(targetPatchRect.x, prevFrame.cols * 1.5f));
|
||||||
|
targetPatchRect.y = std::max(-prevFrame.rows * 0.5f, std::min(targetPatchRect.y, prevFrame.rows * 1.5f));
|
||||||
|
|
||||||
copyMakeBorder(prevFrame, prevFramePadded, (int)targetPatchRect.height, (int)targetPatchRect.height, (int)targetPatchRect.width, (int)targetPatchRect.width, BORDER_REPLICATE);
|
copyMakeBorder(prevFrame, prevFramePadded, (int)targetPatchRect.height, (int)targetPatchRect.height, (int)targetPatchRect.width, (int)targetPatchRect.width, BORDER_REPLICATE);
|
||||||
targetPatch = prevFramePadded(targetPatchRect).clone();
|
targetPatch = prevFramePadded(targetPatchRect).clone();
|
||||||
|
|
||||||
|
@@ -3,4 +3,19 @@
|
|||||||
// of this distribution and at http://opencv.org/license.html.
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
|
|
||||||
CV_TEST_MAIN("cv")
|
static
|
||||||
|
void initTrackingTests()
|
||||||
|
{
|
||||||
|
const char* extraTestDataPath =
|
||||||
|
#ifdef WINRT
|
||||||
|
NULL;
|
||||||
|
#else
|
||||||
|
getenv("OPENCV_DNN_TEST_DATA_PATH");
|
||||||
|
#endif
|
||||||
|
if (extraTestDataPath)
|
||||||
|
cvtest::addDataSearchPath(extraTestDataPath);
|
||||||
|
|
||||||
|
cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_TEST_MAIN("cv", initTrackingTests())
|
||||||
|
@@ -567,6 +567,31 @@ TEST_P(DistanceAndOverlap, Scaled_Data_CSRT)
|
|||||||
test.run();
|
test.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(GOTURN, memory_usage)
|
||||||
|
{
|
||||||
|
cv::Rect2d roi(145, 70, 85, 85);
|
||||||
|
cv::Mat frame;
|
||||||
|
|
||||||
|
std::string model = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.prototxt");
|
||||||
|
std::string weights = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.caffemodel", false);
|
||||||
|
cv::TrackerGOTURN::Params params;
|
||||||
|
params.modelTxt = model;
|
||||||
|
params.modelBin = weights;
|
||||||
|
cv::Ptr<cv::Tracker> tracker = cv::TrackerGOTURN::create(params);
|
||||||
|
string inputVideo = cvtest::findDataFile("tracking/david/data/david.webm");
|
||||||
|
cv::VideoCapture video(inputVideo);
|
||||||
|
|
||||||
|
video >> frame;
|
||||||
|
tracker->init(frame, roi);
|
||||||
|
string ground_truth_bb;
|
||||||
|
for (int nframes = 0; nframes < 15; ++nframes)
|
||||||
|
{
|
||||||
|
std::cout << "Frame: " << nframes << std::endl;
|
||||||
|
video >> frame;
|
||||||
|
tracker->update(frame, roi);
|
||||||
|
std::cout << "Predicted ROI: " << roi << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P( Tracking, DistanceAndOverlap, TESTSET_NAMES);
|
INSTANTIATE_TEST_CASE_P( Tracking, DistanceAndOverlap, TESTSET_NAMES);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user