mirror of
https://github.com/opencv/opencv.git
synced 2026-11-21 00:35:35 -06:00
253 lines
8.6 KiB
C++
253 lines
8.6 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
//#define DEBUG_TEST
|
|
#ifdef DEBUG_TEST
|
|
#include <opencv2/highgui.hpp>
|
|
#endif
|
|
|
|
namespace opencv_test { namespace {
|
|
//using namespace cv::tracking;
|
|
|
|
#define TESTSET_NAMES testing::Values("david", "dudek", "faceocc2")
|
|
|
|
const string TRACKING_DIR = "tracking";
|
|
const string FOLDER_IMG = "data";
|
|
const string FOLDER_OMIT_INIT = "initOmit";
|
|
|
|
#include "test_trackers.impl.hpp"
|
|
|
|
//[TESTDATA]
|
|
PARAM_TEST_CASE(DistanceAndOverlap, string, int)
|
|
{
|
|
string dataset;
|
|
int numFramesLimit;
|
|
virtual void SetUp()
|
|
{
|
|
dataset = GET_PARAM(0);
|
|
numFramesLimit = GET_PARAM(1);
|
|
}
|
|
};
|
|
|
|
TEST_P(DistanceAndOverlap, MIL)
|
|
{
|
|
TrackerTest<Tracker, Rect> test(TrackerMIL::create(), dataset, 30, .65f, NoTransform);
|
|
test.run(numFramesLimit);
|
|
}
|
|
|
|
TEST_P(DistanceAndOverlap, Shifted_Data_MIL)
|
|
{
|
|
TrackerTest<Tracker, Rect> test(TrackerMIL::create(), dataset, 30, .6f, CenterShiftLeft);
|
|
test.run(numFramesLimit);
|
|
}
|
|
|
|
/***************************************************************************************/
|
|
//Tests with scaled initial window
|
|
|
|
TEST_P(DistanceAndOverlap, Scaled_Data_MIL)
|
|
{
|
|
TrackerTest<Tracker, Rect> test(TrackerMIL::create(), dataset, 30, .7f, Scale_1_1);
|
|
test.run(numFramesLimit);
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(Tracking, DistanceAndOverlap,
|
|
testing::Combine(
|
|
TESTSET_NAMES,
|
|
testing::Values(0)
|
|
)
|
|
);
|
|
|
|
INSTANTIATE_TEST_CASE_P(Tracking5Frames, DistanceAndOverlap,
|
|
testing::Combine(
|
|
TESTSET_NAMES,
|
|
testing::Values(5)
|
|
)
|
|
);
|
|
|
|
|
|
static bool checkIOU(const Rect& r0, const Rect& r1, double threshold)
|
|
{
|
|
int interArea = (r0 & r1).area();
|
|
double iouVal = (interArea * 1.0 )/ (r0.area() + r1.area() - interArea);;
|
|
|
|
if (iouVal > threshold)
|
|
return true;
|
|
else
|
|
{
|
|
std::cout <<"Unmatched IOU: expect IOU val ("<<iouVal <<") > the IOU threadhold ("<<threshold<<")! Box 0 is "
|
|
<< r0 <<", and Box 1 is "<<r1<< std::endl;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static void checkTrackingAccuracy(cv::Ptr<Tracker>& tracker, double iouThreshold = 0.7)
|
|
{
|
|
// Template image
|
|
Mat img0 = imread(findDataFile("tracking/bag/00000001.jpg"), 1);
|
|
|
|
// Tracking image sequence.
|
|
std::vector<Mat> imgs;
|
|
imgs.push_back(imread(findDataFile("tracking/bag/00000002.jpg"), 1));
|
|
imgs.push_back(imread(findDataFile("tracking/bag/00000003.jpg"), 1));
|
|
imgs.push_back(imread(findDataFile("tracking/bag/00000004.jpg"), 1));
|
|
imgs.push_back(imread(findDataFile("tracking/bag/00000005.jpg"), 1));
|
|
imgs.push_back(imread(findDataFile("tracking/bag/00000006.jpg"), 1));
|
|
|
|
cv::Rect roi(325, 164, 100, 100);
|
|
std::vector<Rect> targetRois;
|
|
targetRois.push_back(cv::Rect(278, 133, 99, 104));
|
|
targetRois.push_back(cv::Rect(293, 88, 93, 110));
|
|
targetRois.push_back(cv::Rect(287, 76, 89, 116));
|
|
targetRois.push_back(cv::Rect(297, 74, 82, 122));
|
|
targetRois.push_back(cv::Rect(311, 83, 78, 125));
|
|
|
|
tracker->init(img0, roi);
|
|
CV_Assert(targetRois.size() == imgs.size());
|
|
|
|
for (int i = 0; i < (int)imgs.size(); i++)
|
|
{
|
|
bool res = tracker->update(imgs[i], roi);
|
|
ASSERT_TRUE(res);
|
|
ASSERT_TRUE(checkIOU(roi, targetRois[i], iouThreshold)) << cv::format("Fail at img %d.",i);
|
|
}
|
|
}
|
|
|
|
TEST(DaSiamRPN, accuracy)
|
|
{
|
|
std::string model = cvtest::findDataFile("dnn/onnx/models/dasiamrpn_model.onnx", false);
|
|
std::string kernel_r1 = cvtest::findDataFile("dnn/onnx/models/dasiamrpn_kernel_r1.onnx", false);
|
|
std::string kernel_cls1 = cvtest::findDataFile("dnn/onnx/models/dasiamrpn_kernel_cls1.onnx", false);
|
|
cv::TrackerDaSiamRPN::Params params;
|
|
params.model = model;
|
|
params.kernel_r1 = kernel_r1;
|
|
params.kernel_cls1 = kernel_cls1;
|
|
cv::Ptr<Tracker> tracker = TrackerDaSiamRPN::create(params);
|
|
checkTrackingAccuracy(tracker, 0.7);
|
|
}
|
|
|
|
TEST(NanoTrack, accuracy_NanoTrack_V1)
|
|
{
|
|
std::string backbonePath = cvtest::findDataFile("dnn/onnx/models/nanotrack_backbone_sim.onnx", false);
|
|
std::string neckheadPath = cvtest::findDataFile("dnn/onnx/models/nanotrack_head_sim.onnx", false);
|
|
|
|
cv::TrackerNano::Params params;
|
|
params.backbone = backbonePath;
|
|
params.neckhead = neckheadPath;
|
|
cv::Ptr<Tracker> tracker = TrackerNano::create(params);
|
|
checkTrackingAccuracy(tracker);
|
|
}
|
|
|
|
TEST(NanoTrack, accuracy_NanoTrack_V2)
|
|
{
|
|
std::string backbonePath = cvtest::findDataFile("dnn/onnx/models/nanotrack_backbone_sim_v2.onnx", false);
|
|
std::string neckheadPath = cvtest::findDataFile("dnn/onnx/models/nanotrack_head_sim_v2.onnx", false);
|
|
|
|
cv::TrackerNano::Params params;
|
|
params.backbone = backbonePath;
|
|
params.neckhead = neckheadPath;
|
|
cv::Ptr<Tracker> tracker = TrackerNano::create(params);
|
|
checkTrackingAccuracy(tracker, 0.69);
|
|
}
|
|
|
|
// Targets smaller than 10 px must not be inflated to 10x10: the reported box and the
|
|
// internal target size should follow the object (e.g. far-away objects, low-resolution input).
|
|
TEST(NanoTrack, small_target_size)
|
|
{
|
|
std::string backbonePath = cvtest::findDataFile("dnn/onnx/models/nanotrack_backbone_sim_v2.onnx", false);
|
|
std::string neckheadPath = cvtest::findDataFile("dnn/onnx/models/nanotrack_head_sim_v2.onnx", false);
|
|
|
|
cv::TrackerNano::Params params;
|
|
params.backbone = backbonePath;
|
|
params.neckhead = neckheadPath;
|
|
cv::Ptr<Tracker> tracker = TrackerNano::create(params);
|
|
|
|
// Textured static background with a 6x6 object (white with a dark core) moving 2 px right and 1 px down per frame.
|
|
Mat noise(240, 320, CV_8UC1);
|
|
RNG& rng = theRNG();
|
|
rng.fill(noise, RNG::UNIFORM, 0, 256);
|
|
GaussianBlur(noise, noise, Size(0, 0), 3);
|
|
normalize(noise, noise, 60, 160, NORM_MINMAX);
|
|
Mat background;
|
|
cvtColor(noise, background, COLOR_GRAY2BGR);
|
|
|
|
const int sz = 6;
|
|
auto makeFrame = [&](int x, int y) {
|
|
Mat frame = background.clone();
|
|
frame(Rect(x, y, sz, sz)).setTo(Scalar::all(255));
|
|
frame(Rect(x + sz / 3, y + sz / 3, sz - 2 * (sz / 3), sz - 2 * (sz / 3))).setTo(Scalar::all(0));
|
|
return frame;
|
|
};
|
|
|
|
int x = 100, y = 110;
|
|
tracker->init(makeFrame(x, y), Rect(x, y, sz, sz));
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
x += 2; y += 1;
|
|
Rect roi;
|
|
ASSERT_TRUE(tracker->update(makeFrame(x, y), roi));
|
|
// the size must follow the object (it was inflated to 10x10 before)
|
|
EXPECT_LE(roi.width, sz + 2) << cv::format("frame %d", i);
|
|
EXPECT_LE(roi.height, sz + 2) << cv::format("frame %d", i);
|
|
EXPECT_GE(roi.width, sz - 2) << cv::format("frame %d", i);
|
|
EXPECT_GE(roi.height, sz - 2) << cv::format("frame %d", i);
|
|
// and the object must still be tracked (the box is rounded to integers, so allow ~2 px)
|
|
const double dx = (roi.x + roi.width * 0.5) - (x + sz * 0.5);
|
|
const double dy = (roi.y + roi.height * 0.5) - (y + sz * 0.5);
|
|
EXPECT_LE(std::sqrt(dx * dx + dy * dy), 2.5) << cv::format("frame %d", i);
|
|
}
|
|
}
|
|
|
|
TEST(vittrack, accuracy_vittrack)
|
|
{
|
|
std::string model = cvtest::findDataFile("dnn/onnx/models/vitTracker.onnx");
|
|
cv::TrackerVit::Params params;
|
|
params.net = model;
|
|
cv::Ptr<Tracker> tracker = TrackerVit::create(params);
|
|
checkTrackingAccuracy(tracker, 0.64);
|
|
}
|
|
|
|
TEST(vittrack, bbox_inside_image)
|
|
{
|
|
std::string model = cvtest::findDataFile("dnn/onnx/models/vitTracker.onnx");
|
|
cv::TrackerVit::Params params;
|
|
params.net = model;
|
|
cv::Ptr<Tracker> tracker = TrackerVit::create(params);
|
|
|
|
Mat img0 = imread(findDataFile("tracking/bag/00000001.jpg"), 1);
|
|
cv::Rect imgRect(0, 0, img0.cols, img0.rows);
|
|
cv::Rect roi = imgRect;
|
|
tracker->init(img0, roi);
|
|
|
|
for (int i = 2; i <= 6; i++)
|
|
{
|
|
Mat img = imread(findDataFile(cv::format("tracking/bag/%08d.jpg", i)), 1);
|
|
bool res = tracker->update(img, roi);
|
|
ASSERT_TRUE(res);
|
|
ASSERT_EQ(roi & imgRect, roi) << cv::format("Fail at img %d.", i);
|
|
}
|
|
}
|
|
|
|
TEST(vittrack, bbox_inside_tiny_image)
|
|
{
|
|
std::string model = cvtest::findDataFile("dnn/onnx/models/vitTracker.onnx");
|
|
cv::TrackerVit::Params params;
|
|
params.net = model;
|
|
params.tracking_score_threshold = 0.f;
|
|
cv::Ptr<Tracker> tracker = TrackerVit::create(params);
|
|
|
|
Mat img;
|
|
resize(imread(findDataFile("tracking/bag/00000001.jpg"), 1), img, Size(5, 5));
|
|
cv::Rect imgRect(0, 0, img.cols, img.rows);
|
|
cv::Rect roi = imgRect;
|
|
tracker->init(img, roi);
|
|
|
|
bool res = tracker->update(img, roi);
|
|
ASSERT_TRUE(res);
|
|
ASSERT_EQ(roi & imgRect, roi);
|
|
}
|
|
|
|
}} // namespace opencv_test::
|