I am using OpenCV 3.4.1 tracking classes in C++ Visual Studio 2015. Among the 8 trackers available in OpenCv, I am using mainly KCF,CSRT and MEDIANFLOW and the fps of these tracking algorithms are 30,4,4 respectively. I would like to know whether I can change the fps of these so that the videos are processed faster. Anybody knows how to increase the fps of CSRT/MEDIANFLOW to 30(same as KCF)?
In my code, KCF is faster than CSRT and MEDIANFLOW , but the tracking performance/accuracy is not as good as CSRT. But the processing speed of KCF is really good, because of its high fps.So, I need to acquire this speed in CSRT. What are the possible ways by which I can achieve this. My code part is given below:
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <iostream>
#include <string>
#include <iomanip>
#include <map>
using namespace std;
using namespace cv;
vector<string> trackerTypes = { "BOOSTING", "MIL", "KCF", "TLD", "MEDIANFLOW", "GOTURN", "MOSSE", "CSRT" };
// create tracker by name
Ptr<Tracker> createTrackerByName(string trackerType)
{
Ptr<Tracker> tracker;
if (trackerType == trackerTypes[0])
tracker = TrackerBoosting::create();
else if (trackerType == trackerTypes[1])
tracker = TrackerMIL::create();
else if (trackerType == trackerTypes[2])
tracker = TrackerKCF::create();
else if (trackerType == trackerTypes[3])
tracker = TrackerTLD::create();
else if (trackerType == trackerTypes[4])
tracker = TrackerMedianFlow::create();
else if (trackerType == trackerTypes[5])
tracker = TrackerGOTURN::create();
else if (trackerType == trackerTypes[6])
tracker = TrackerMOSSE::create();
else if (trackerType == trackerTypes[7])
tracker = TrackerCSRT::create();
else {
cout << "Incorrect tracker name" << endl;
cout << "Available trackers are: " << endl;
for (vector<string>::iterator it = trackerTypes.begin(); it != trackerTypes.end(); ++it)
std::cout << " " << *it << endl;
}
return tracker;
}
int main(int argc, char * argv[])
{
const int N = 2;
double xcordinate = 0;
double ycordinate = 0;
double Xvalue = 0;
double Yvalue = 0;
double firstFrameY[10] = {};
double remainFrameY[10] = {};
double firstFrameX[10] = {};
double remainFrameX[10] = {};
string trackerType = "CSRT";
cout << "The Selected tracker is " << trackerType << endl;
string videoPath = "SS-100_random11sec_Trim.mp4";
vector<Rect> bboxes;
Mat frame;
cv::VideoCapture cap(videoPath);
cap >> frame;
bool showCrosshair = true;
bool fromCenter = false;
cout << "Enter the value of X-cordinate\n";
cin >> xcordinate;
cout << "Enter the value of Y-cordinate\n";
cin >> ycordinate;
cv::selectROIs("MultiTracker", frame, bboxes, showCrosshair, fromCenter);
if (bboxes.size() < 1)
return 0;
Ptr<MultiTracker> multiTracker = cv::MultiTracker::create();
for (int i = 0; i < bboxes.size(); i++)
multiTracker->add(createTrackerByName(trackerType), frame, Rect2d(bboxes[i]));
cout << "Started tracking, press ESC to quit." << endl;
int m = 0;
while (cap.isOpened())
{
cap >> frame;
if (frame.empty()) break;
multiTracker->update(frame);
for (unsigned i = 0; i < multiTracker->getObjects().size(); i++)
{
rectangle(frame, multiTracker->getObjects()[i], colors[i], 2, 1);
bboxes[i] = multiTracker->getObjects()[i];
//cout << "The Co-ordinates: " << bboxes[i] << endl;
outputFile << std::left << bboxes[i].x <<',' << std::right << bboxes[i].y << '\n';
}
if (m == 0) //for saving the reference values
{
for (int i = 0; i< N; i++)
{
firstFrameY[i] = bboxes[i].y;
remainFrameY[i] = bboxes[i].y;
firstFrameX[i] = bboxes[i].x;
remainFrameX[i] = bboxes[i].x;
}
m++;
}
else
{
//get the y values into an array and pass it below
for (int i = 0; i < N; i++)
{
remainFrameY[i] = bboxes[i].y;
remainFrameX[i] = bboxes[i].x;
}
}
Xvalue = getTheEquationX(firstFrameX, remainFrameX, xcordinate, TrackedX);
Yvalue = getTheEquationY(firstFrameY, remainFrameY, ycordinate, TrackedY);
cropObject(Xvalue, Yvalue, frame, count_4);
resize(frame, frame, Size(1280, 720), 0, 0, INTER_CUBIC);
imshow("MultiTracker", frame);
if (waitKey(1) == 27) break;
}