Commit a80308fd authored by Vladimir's avatar Vladimir

Merge pull request #3 from Itseez/master

Update
parents 3011e80f f9634fd8
...@@ -51,3 +51,5 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_re ...@@ -51,3 +51,5 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_re
21. **opencv_xobjdetect**: Integral Channel Features Detector Framework. 21. **opencv_xobjdetect**: Integral Channel Features Detector Framework.
22. **opencv_xphoto**: Additional photo processing algorithms: Color balance / Denoising / Inpainting. 22. **opencv_xphoto**: Additional photo processing algorithms: Color balance / Denoising / Inpainting.
23. **opencv_stereo**: Stereo Correspondence done with different descriptors: Census / CS-Census / MCT / BRIEF / MV / RT.
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_DATASETS_VOC_PASCAL_HPP
#define OPENCV_DATASETS_VOC_PASCAL_HPP
#include <string>
#include <vector>
#include "opencv2/datasets/dataset.hpp"
#include <opencv2/core.hpp>
namespace cv
{
namespace datasets
{
//! @addtogroup datasets_or
//! @{
struct PascalPart: public Object
{
std::string name;
int xmin;
int ymin;
int xmax;
int ymax;
};
struct PascalObj: public PascalPart
{
std::string pose;
bool truncated;
bool difficult;
bool occluded;
std::vector<PascalPart> parts;
};
struct OR_pascalObj : public Object
{
std::string filename;
int width;
int height;
int depth;
std::vector<PascalObj> objects;
};
class CV_EXPORTS OR_pascal : public Dataset
{
public:
virtual void load(const std::string &path) = 0;
static Ptr<OR_pascal> create();
};
//! @}
}// namespace dataset
}// namespace cv
#endif
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_DATASETS_PD_INRIA_HPP
#define OPENCV_DATASETS_PD_INRIA_HPP
#include <string>
#include <vector>
#include "opencv2/datasets/dataset.hpp"
#include <opencv2/core.hpp>
namespace cv
{
namespace datasets
{
//! @addtogroup datasets_pd
//! @{
enum sampleType
{
POS = 0,
NEG = 1
};
struct PD_inriaObj : public Object
{
// image file name
std::string filename;
// positive or negative
sampleType sType;
// image size
int width;
int height;
int depth;
// bounding boxes
std::vector< Rect > bndboxes;
};
class CV_EXPORTS PD_inria : public Dataset
{
public:
virtual void load(const std::string &path) = 0;
static Ptr<PD_inria> create();
};
//! @}
}
}
#endif
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/datasets/or_pascal.hpp"
#include <opencv2/core.hpp>
#include <cstdio>
#include <cstdlib> // atoi
#include <string>
#include <vector>
#include <set>
using namespace std;
using namespace cv;
using namespace cv::datasets;
int main(int argc, char *argv[])
{
const char *keys =
"{ help h usage ? | | show this message }"
"{ path p |true| path to folder with dataset }";
CommandLineParser parser(argc, argv, keys);
string path(parser.get<string>("path"));
if (parser.has("help") || path=="true")
{
parser.printMessage();
return -1;
}
Ptr<OR_pascal> dataset = OR_pascal::create();
dataset->load(path);
// Print train/test/validation size and first example
OR_pascalObj *example;
vector< Ptr<Object> > &train = dataset->getTrain();
printf("\ntrain:\nsize: %u", (unsigned int)train.size());
example = static_cast<OR_pascalObj *>(train[0].get());
printf("\nfirst image: \n%s", example->filename.c_str());
printf("\nsize:");
printf("\n - width: %d", example->width);
printf("\n - height: %d", example->height);
printf("\n - depth: %d", example->depth);
for (unsigned int i = 0; i < example->objects.size(); i++)
{
printf("\nobject %d", i);
printf("\nname: %s", example->objects[i].name.c_str());
printf("\npose: %s", example->objects[i].pose.c_str());
printf("\ntruncated: %d", example->objects[i].truncated);
printf("\ndifficult: %d", example->objects[i].difficult);
printf("\noccluded: %d", example->objects[i].occluded);
printf("\nbounding box:");
printf("\n - xmin: %d", example->objects[i].xmin);
printf("\n - ymin: %d", example->objects[i].ymin);
printf("\n - xmax: %d", example->objects[i].xmax);
printf("\n - ymax: %d", example->objects[i].ymax);
}
vector< Ptr<Object> > &test = dataset->getTest();
printf("\ntest:\nsize: %u", (unsigned int)test.size());
example = static_cast<OR_pascalObj *>(test[0].get());
printf("\nfirst image: \n%s", example->filename.c_str());
vector< Ptr<Object> > &validation = dataset->getValidation();
printf("\nvalidation:\nsize: %u", (unsigned int)validation.size());
example = static_cast<OR_pascalObj *>(validation[0].get());
printf("\nfirst image: \n%s\n", example->filename.c_str());
return 0;
}
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/datasets/pd_inria.hpp"
#include <opencv2/core.hpp>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace cv;
using namespace cv::datasets;
int main(int argc, char *argv[])
{
const char *keys =
"{ help h usage ? | | show this message }"
"{ path p |true| path to dataset }";
CommandLineParser parser(argc, argv, keys);
string path(parser.get<string>("path"));
if (parser.has("help") || path=="true")
{
parser.printMessage();
return -1;
}
Ptr<PD_inria> dataset = PD_inria::create();
dataset->load(path);
cout << "train size: " << (unsigned int)dataset->getTrain().size() << endl;
PD_inriaObj *example = static_cast<PD_inriaObj *>(dataset->getTrain()[0].get());
cout << "first train object: " << endl;
cout << "name: " << example->filename << endl;
// image size
cout << "image size: " << endl;
cout << " - width: " << example->width << endl;
cout << " - height: " << example->height << endl;
cout << " - depth: " << example->depth << endl;
// bounding boxes
for (unsigned int i = 0; i < (example->bndboxes).size(); i++)
{
cout << "object " << i << endl;
int x = (example->bndboxes)[i].x;
int y = (example->bndboxes)[i].y;
cout << " - xmin = " << x << endl;
cout << " - ymin = " << y << endl;
cout << " - xmax = " << (example->bndboxes)[i].width + x << endl;
cout << " - ymax = " << (example->bndboxes)[i].height + y<< endl;
}
return 0;
}
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/datasets/or_pascal.hpp"
#include "opencv2/datasets/util.hpp"
#include <opencv2/datasets/tinyxml2/tinyxml2.h>
#include <fstream>
namespace cv
{
namespace datasets
{
using namespace std;
using namespace tinyxml2;
class OR_pascalImp : public OR_pascal
{
public:
OR_pascalImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path, const string &nameImageSet, vector< Ptr<Object> > &imageSet);
Ptr<Object> parseAnnotation(const string path, const string id);
const char* parseNodeText(XMLElement* node, const string nodeName, const string defaultValue);
};
void OR_pascalImp::load(const string &path)
{
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
loadDataset(path, "train", train.back());
loadDataset(path, "test", test.back());
loadDataset(path, "val", validation.back());
}
void OR_pascalImp::loadDataset(const string &path, const string &nameImageSet, vector< Ptr<Object> > &imageSet)
{
string pathImageSets(path + "ImageSets/Main/");
string imageList = pathImageSets + nameImageSet + ".txt";
ifstream in(imageList.c_str());
string error_message = format("Image list not exists!\n%s", imageList.c_str());
if (!in.is_open())
CV_Error(Error::StsBadArg, error_message);
string id = "";
while( getline(in, id) )
{
if( strcmp(nameImageSet.c_str(), "test") == 0 ) // test set ground truth is not available
{
Ptr<OR_pascalObj> annotation(new OR_pascalObj);
annotation->filename = path + "JPEGImages/" + id + ".jpg";
imageSet.push_back(annotation);
}
else
{
imageSet.push_back(parseAnnotation(path, id));
}
}
}
const char* OR_pascalImp::parseNodeText(XMLElement* node, const string nodeName, const string defaultValue)
{
const char* e = node->FirstChildElement(nodeName.c_str())->GetText();
if( e != 0 )
return e ;
else
return defaultValue.c_str();
}
Ptr<Object> OR_pascalImp::parseAnnotation(const string path, const string id)
{
string pathAnnotations(path + "Annotations/");
string pathImages(path + "JPEGImages/");
Ptr<OR_pascalObj> annotation(new OR_pascalObj);
XMLDocument doc;
string xml_file = pathAnnotations + id + ".xml";
XMLError error_code = doc.LoadFile(xml_file.c_str());
string error_message = format("Parsing XML failed. Error code = %d. \nFile = %s", error_code, xml_file.c_str());
switch (error_code)
{
case XML_SUCCESS:
break;
case XML_ERROR_FILE_NOT_FOUND:
error_message = "XML file not found! " + error_message;
CV_Error(Error::StsParseError, error_message);
return annotation;
default:
CV_Error(Error::StsParseError, error_message);
break;
}
// <annotation/>
XMLElement *xml_ann = doc.RootElement();
// <filename/>
string img_name = xml_ann->FirstChildElement("filename")->GetText();
annotation->filename = pathImages + img_name;
// <size/>
XMLElement *sz = xml_ann->FirstChildElement("size");
int width = atoi(sz->FirstChildElement("width")->GetText());
int height = atoi(sz->FirstChildElement("height")->GetText());
int depth = atoi(sz->FirstChildElement("depth")->GetText());
annotation->width = width;
annotation->height = height;
annotation->depth = depth;
// <object/>
vector<PascalObj> objects;
XMLElement *xml_obj = xml_ann->FirstChildElement("object");
while (xml_obj)
{
PascalObj pascal_obj;
pascal_obj.name = xml_obj->FirstChildElement("name")->GetText();
pascal_obj.pose = parseNodeText(xml_obj, "pose", "Unspecified");
pascal_obj.truncated = atoi(parseNodeText(xml_obj, "truncated", "0")) > 0;
pascal_obj.difficult = atoi(parseNodeText(xml_obj, "difficult", "0")) > 0;
pascal_obj.occluded = atoi(parseNodeText(xml_obj, "occluded", "0")) > 0;
// <bndbox/>
XMLElement *xml_bndbox = xml_obj->FirstChildElement("bndbox");
pascal_obj.xmin = atoi(xml_bndbox->FirstChildElement("xmin")->GetText());
pascal_obj.ymin = atoi(xml_bndbox->FirstChildElement("ymin")->GetText());
pascal_obj.xmax = atoi(xml_bndbox->FirstChildElement("xmax")->GetText());
pascal_obj.ymax = atoi(xml_bndbox->FirstChildElement("ymax")->GetText());
// <part/>
vector<PascalPart> parts;
XMLElement *xml_part = xml_obj->FirstChildElement("part");
while (xml_part)
{
PascalPart pascal_part;
pascal_part.name = xml_part->FirstChildElement("name")->GetText();
xml_bndbox = xml_part->FirstChildElement("bndbox");
pascal_part.xmin = atoi(xml_bndbox->FirstChildElement("xmin")->GetText());
pascal_part.ymin = atoi(xml_bndbox->FirstChildElement("ymin")->GetText());
pascal_part.xmax = atoi(xml_bndbox->FirstChildElement("xmax")->GetText());
pascal_part.ymax = atoi(xml_bndbox->FirstChildElement("ymax")->GetText());
parts.push_back(pascal_part);
xml_part = xml_part->NextSiblingElement("part");
}
pascal_obj.parts = parts;
objects.push_back(pascal_obj);
xml_obj = xml_obj->NextSiblingElement("object");
}
annotation->objects = objects;
return annotation;
}
Ptr<OR_pascal> OR_pascal::create()
{
return Ptr<OR_pascalImp>(new OR_pascalImp);
}
}
}
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/datasets/pd_inria.hpp"
#include "opencv2/datasets/util.hpp"
namespace cv
{
namespace datasets
{
using namespace std;
class PD_inriaImp : public PD_inria
{
public:
PD_inriaImp() {}
virtual ~PD_inriaImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path, const string nameImageSet, vector< Ptr<Object> > &imageSet);
void readTextLines(const string filename, vector< string > &lines);
void parseAnnotation(const string filename, Ptr< PD_inriaObj > &object);
};
void PD_inriaImp::load(const string &path)
{
// Training set
train.push_back(vector< Ptr<Object> >());
loadDataset(path, "Train", train.back());
// Testing set
test.push_back(vector< Ptr<Object> >());
loadDataset(path, "Test", test.back());
// There is no validation set
validation.push_back(vector< Ptr<Object> >());
}
void PD_inriaImp::readTextLines(const string filename, vector< string > &lines)
{
ifstream in(filename.c_str());
string error_message = "";
if (!in.is_open())
{
error_message = format("Unable to open file: \n%s\n", filename.c_str());
CV_Error(Error::StsBadArg, error_message);
}
string currline = "";
while (getline(in, currline))
lines.push_back(currline);
}
void PD_inriaImp::parseAnnotation(const string filename, Ptr< PD_inriaObj > &object)
{
string error_message = "";
ifstream in(filename.c_str());
if (!in.is_open())
{
error_message = format("Unable to open file: \n%s\n", filename.c_str());
CV_Error(Error::StsBadArg, error_message);
}
string imageSizeHeader = "Image size (X x Y x C) : ";
string imageSizeFmt = imageSizeHeader + "%d x %d x %d";
string objWithGTHeader = "Objects with ground truth : ";
string objWithGTFmt = objWithGTHeader + "%d { \"PASperson\" }";
string boundBoxHeader = "Bounding box for object ";
string boundBoxFmt = boundBoxHeader + "%*d \"PASperson\" (Xmin, Ymin) - (Xmax, Ymax) : (%d, %d) - (%d, %d)";
string line = "";
int width = 0;
int height = 0;
int depth = 0;
int xmin, ymin, xmax, ymax;
int numObjects = 0;
while (getline(in, line))
{
if (line[0] == '#' || !line[0])
continue;
if (strstr(line.c_str(), imageSizeHeader.c_str()))
{
sscanf(line.c_str(), imageSizeFmt.c_str(), &width, &height, &depth);
object->width = width;
object->height = height;
object->depth = depth;
}
else if (strstr(line.c_str(), objWithGTHeader.c_str()))
{
sscanf(line.c_str(), objWithGTFmt.c_str(), &numObjects);
if (numObjects <= 0)
break;
}
else if (strstr(line.c_str(), boundBoxHeader.c_str()))
{
sscanf(line.c_str(), boundBoxFmt.c_str(), &xmin, &ymin, &xmax, &ymax);
Rect bndbox;
bndbox.x = xmin;
bndbox.y = ymin;
bndbox.width = xmax - xmin;
bndbox.height = ymax - ymin;
(object->bndboxes).push_back(bndbox);
}
}
CV_Assert((object->bndboxes).size() == (unsigned int)numObjects);
}
void PD_inriaImp::loadDataset(const string &path, const string nameImageSet, vector< Ptr<Object> > &imageSet)
{
string listAnn = path + nameImageSet + "/annotations.lst";
string listPos = path + nameImageSet + "/pos.lst";
string listNeg = path + nameImageSet + "/neg.lst";
vector< string > fsAnn;
vector< string > fsPos;
vector< string > fsNeg;
// read file names
readTextLines(listAnn, fsAnn);
readTextLines(listPos, fsPos);
readTextLines(listNeg, fsNeg);
CV_Assert(fsAnn.size() == fsPos.size());
for (unsigned int i = 0; i < fsPos.size(); i++)
{
Ptr<PD_inriaObj> curr(new PD_inriaObj);
parseAnnotation(path + fsAnn[i], curr);
curr->filename = path + fsPos[i];
curr->sType = POS;
imageSet.push_back(curr);
}
for (unsigned int i = 0; i < fsNeg.size(); i++)
{
Ptr<PD_inriaObj> curr(new PD_inriaObj);
curr->filename = path + fsNeg[i];
curr->sType = NEG;
imageSet.push_back(curr);
}
}
Ptr<PD_inria> PD_inria::create()
{
return Ptr<PD_inriaImp>(new PD_inriaImp);
}
}
}
set(the_description "Stereo Correspondence")
ocv_define_module(stereo opencv_imgproc opencv_features2d opencv_core opencv_highgui opencv_calib3d)
Stereo Correspondence with different descriptors
================================================
This diff is collapsed.
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifdef __OPENCV_BUILD
#error this is a compatibility header which should not be used inside the OpenCV library
#endif
#include "opencv2/stereo.hpp"
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_STEREO_PRECOMP_H__
#define __OPENCV_STEREO_PRECOMP_H__
#include "opencv2/stereo.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/core/cvdef.h"
#include "opencv2/highgui.hpp"
#include "opencv2/calib3d.hpp"
#include <algorithm>
#include <cmath>
#endif
This diff is collapsed.
This diff is collapsed.
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
CV_TEST_MAIN("cv")
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# if defined __clang__ || defined __APPLE__
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
# pragma GCC diagnostic ignored "-Wextra"
# endif
#endif
#ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__
#include <iostream>
#include "opencv2/ts.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/stereo.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/core/cvdef.h"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <algorithm>
#include <cmath>
#endif
...@@ -110,9 +110,22 @@ int main(int argc, char** argv) ...@@ -110,9 +110,22 @@ int main(int argc, char** argv)
tick2 = cv::getTickCount(); tick2 = cv::getTickCount();
cout << endl << "PPF Elapsed Time " << cout << endl << "PPF Elapsed Time " <<
(tick2-tick1)/cv::getTickFrequency() << " sec" << endl; (tick2-tick1)/cv::getTickFrequency() << " sec" << endl;
// Get only first N results //check results size from match call above
int N = 2; size_t results_size = results.size();
cout << "Number of matching poses: " << results_size;
if (results_size == 0) {
cout << endl << "No matching poses found. Exiting." << endl;
exit(0);
}
// Get only first N results - but adjust to results size if num of results are less than that specified by N
size_t N = 2;
if (results_size < N) {
cout << endl << "Reducing matching poses to be reported (as specified in code): "
<< N << " to the number of matches found: " << results_size << endl;
N = results_size;
}
vector<Pose3DPtr> resultsSub(results.begin(),results.begin()+N); vector<Pose3DPtr> resultsSub(results.begin(),results.begin()+N);
// Create an instance of ICP // Create an instance of ICP
......
...@@ -375,7 +375,7 @@ void PPF3DDetector::clusterPoses(std::vector<Pose3DPtr> poseList, int numPoses, ...@@ -375,7 +375,7 @@ void PPF3DDetector::clusterPoses(std::vector<Pose3DPtr> poseList, int numPoses,
#pragma omp parallel for #pragma omp parallel for
#endif #endif
// uses weighting by the number of votes // uses weighting by the number of votes
for (size_t i=0; i<poseClusters.size(); i++) for (int i=0; i<static_cast<int>(poseClusters.size()); i++)
{ {
// We could only average the quaternions. So I will make use of them here // We could only average the quaternions. So I will make use of them here
double qAvg[4]={0}, tAvg[3]={0}; double qAvg[4]={0}, tAvg[3]={0};
...@@ -426,7 +426,7 @@ void PPF3DDetector::clusterPoses(std::vector<Pose3DPtr> poseList, int numPoses, ...@@ -426,7 +426,7 @@ void PPF3DDetector::clusterPoses(std::vector<Pose3DPtr> poseList, int numPoses,
#if defined _OPENMP #if defined _OPENMP
#pragma omp parallel for #pragma omp parallel for
#endif #endif
for (size_t i=0; i<poseClusters.size(); i++) for (int i=0; i<static_cast<int>(poseClusters.size()); i++)
{ {
// We could only average the quaternions. So I will make use of them here // We could only average the quaternions. So I will make use of them here
double qAvg[4]={0}, tAvg[3]={0}; double qAvg[4]={0}, tAvg[3]={0};
......
...@@ -240,6 +240,119 @@ types. ...@@ -240,6 +240,119 @@ types.
*/ */
CV_EXPORTS Ptr<OCRHMMDecoder::ClassifierCallback> loadOCRHMMClassifierNM(const std::string& filename); CV_EXPORTS Ptr<OCRHMMDecoder::ClassifierCallback> loadOCRHMMClassifierNM(const std::string& filename);
/* OCR BeamSearch Decoder */
/** @brief OCRBeamSearchDecoder class provides an interface for OCR using Beam Search algorithm.
@note
- (C++) An example on using OCRBeamSearchDecoder recognition combined with scene text detection can
be found at the demo sample:
<https://github.com/Itseez/opencv_contrib/blob/master/modules/text/samples/word_recognition.cpp>
*/
class CV_EXPORTS OCRBeamSearchDecoder : public BaseOCR
{
public:
/** @brief Callback with the character classifier is made a class.
This way it hides the feature extractor and the classifier itself, so developers can write
their own OCR code.
The default character classifier and feature extractor can be loaded using the utility funtion
loadOCRBeamSearchClassifierCNN with all its parameters provided in
<https://github.com/Itseez/opencv_contrib/blob/master/modules/text/samples/OCRBeamSearch_CNN_model_data.xml.gz>.
*/
class CV_EXPORTS ClassifierCallback
{
public:
virtual ~ClassifierCallback() { }
/** @brief The character classifier must return a (ranked list of) class(es) id('s)
@param image Input image CV_8UC1 or CV_8UC3 with a single letter.
@param recognition_probabilities For each of the N characters found the classifier returns a list with
class probabilities for each class.
@param oversegmentation The classifier returns a list of N+1 character locations' x-coordinates,
including 0 as start-sequence location.
*/
virtual void eval( InputArray image, std::vector< std::vector<double> >& recognition_probabilities, std::vector<int>& oversegmentation );
};
public:
/** @brief Recognize text using Beam Search.
Takes image on input and returns recognized text in the output_text parameter. Optionally
provides also the Rects for individual text elements found (e.g. words), and the list of those
text elements with their confidence values.
@param image Input image CV_8UC1 with a single text line (or word).
@param output_text Output text. Most likely character sequence found by the HMM decoder.
@param component_rects If provided the method will output a list of Rects for the individual
text elements found (e.g. words).
@param component_texts If provided the method will output a list of text strings for the
recognition of individual text elements found (e.g. words).
@param component_confidences If provided the method will output a list of confidence values
for the recognition of individual text elements found (e.g. words).
@param component_level Only OCR_LEVEL_WORD is supported.
*/
virtual void run(Mat& image, std::string& output_text, std::vector<Rect>* component_rects=NULL,
std::vector<std::string>* component_texts=NULL, std::vector<float>* component_confidences=NULL,
int component_level=0);
/** @brief Creates an instance of the OCRBeamSearchDecoder class. Initializes HMMDecoder.
@param classifier The character classifier with built in feature extractor.
@param vocabulary The language vocabulary (chars when ascii english text). vocabulary.size()
must be equal to the number of classes of the classifier.
@param transition_probabilities_table Table with transition probabilities between character
pairs. cols == rows == vocabulary.size().
@param emission_probabilities_table Table with observation emission probabilities. cols ==
rows == vocabulary.size().
@param mode HMM Decoding algorithm. Only OCR_DECODER_VITERBI is available for the moment
(<http://en.wikipedia.org/wiki/Viterbi_algorithm>).
@param beam_size Size of the beam in Beam Search algorithm.
*/
static Ptr<OCRBeamSearchDecoder> create(const Ptr<OCRBeamSearchDecoder::ClassifierCallback> classifier,// The character classifier with built in feature extractor
const std::string& vocabulary, // The language vocabulary (chars when ascii english text)
// size() must be equal to the number of classes
InputArray transition_probabilities_table, // Table with transition probabilities between character pairs
// cols == rows == vocabulari.size()
InputArray emission_probabilities_table, // Table with observation emission probabilities
// cols == rows == vocabulari.size()
decoder_mode mode = OCR_DECODER_VITERBI, // HMM Decoding algorithm (only Viterbi for the moment)
int beam_size = 50); // Size of the beam in Beam Search algorithm
protected:
Ptr<OCRBeamSearchDecoder::ClassifierCallback> classifier;
std::string vocabulary;
Mat transition_p;
Mat emission_p;
decoder_mode mode;
int beam_size;
};
/** @brief Allow to implicitly load the default character classifier when creating an OCRBeamSearchDecoder object.
@param filename The XML or YAML file with the classifier model (e.g. OCRHMM_knn_model_data.xml)
The default classifier is based in the scene text recognition method proposed by Adam Coates &
Andrew NG in [Coates11a]. The character classifier sonsists in a Single Layer Convolutional Neural Network and
a linear classifier. It is applied to the input image in a sliding window fashion, providing a set of recognitions
at each window location.
*/
CV_EXPORTS Ptr<OCRBeamSearchDecoder::ClassifierCallback> loadOCRBeamSearchClassifierCNN(const std::string& filename);
//! @} //! @}
} }
......
/*
* textdetection.cpp
*
* A demo program of End-to-end Scene Text Detection and Recognition:
* Shows the use of the Tesseract OCR API with the Extremal Region Filter algorithm described in:
* Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012
*
* Created on: Jul 31, 2014
* Author: Lluis Gomez i Bigorda <lgomez AT cvc.uab.es>
*/
#include "opencv2/text.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
using namespace cv::text;
//Perform text recognition in a given cropped word
int main(int argc, char* argv[])
{
cout << endl << argv[0] << endl << endl;
cout << "A demo program of Scene Text cropped word Recognition: " << endl;
cout << "Shows the use of the OCRBeamSearchDecoder class using the Single Layer CNN character classifier described in:" << endl;
cout << "Coates, Adam, et al. \"Text detection and character recognition in scene images with unsupervised feature learning.\" ICDAR 2011." << endl << endl;
Mat image;
if(argc>1)
image = imread(argv[1]);
else
{
cout << " Usage: " << argv[0] << " <input_image>" << endl << endl;
return(0);
}
Mat transition_p;
string filename = "OCRHMM_transitions_table.xml"; // TODO this table was done with a different vocabulary order?
// TODO add a new function in ocr.cpp to create transition tab
// for a given lexicon
FileStorage fs(filename, FileStorage::READ);
fs["transition_probabilities"] >> transition_p;
fs.release();
Mat emission_p = Mat::eye(62,62,CV_64FC1);
string voc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyx0123456789";
Ptr<OCRBeamSearchDecoder> ocr = OCRBeamSearchDecoder::create(
loadOCRBeamSearchClassifierCNN("OCRBeamSearch_CNN_model_data.xml.gz"),
voc, transition_p, emission_p);
double t_r = (double)getTickCount();
string output;
vector<Rect> boxes;
vector<string> words;
vector<float> confidences;
ocr->run(image, output, &boxes, &words, &confidences, OCR_LEVEL_WORD);
cout << "OCR output = \"" << output << "\". Decoded in "
<< ((double)getTickCount() - t_r)*1000/getTickFrequency() << " ms." << endl << endl;
return 0;
}
...@@ -287,7 +287,11 @@ void ERFilterNM::er_tree_extract( InputArray image ) ...@@ -287,7 +287,11 @@ void ERFilterNM::er_tree_extract( InputArray image )
quads[1][3] = (1<<3)|(1<<2)|(1<<1); quads[1][3] = (1<<3)|(1<<2)|(1<<1);
quads[2][0] = (1<<2)|(1<<1); quads[2][0] = (1<<2)|(1<<1);
quads[2][1] = (1<<3)|(1); quads[2][1] = (1<<3)|(1);
quads[2][3] = 255; // quads[2][2] and quads[2][3] are never used so no need to initialize them.
// The four lowest bits in each quads[i][j] correspond to the 2x2 binary patterns
// Q_1, Q_2, Q_3 in the Neumann and Matas CVPR 2012 paper
// (see in page 4 at the end of first column).
// Q_1 and Q_2 have four patterns, while Q_3 has only two.
// masks to know if a pixel is accessible and if it has been already added to some region // masks to know if a pixel is accessible and if it has been already added to some region
......
This diff is collapsed.
...@@ -127,7 +127,7 @@ public: ...@@ -127,7 +127,7 @@ public:
int component_level=0) int component_level=0)
{ {
CV_Assert( (image.type() == CV_8UC1) || (image.type() == CV_8UC1) ); CV_Assert( (image.type() == CV_8UC1) || (image.type() == CV_8UC3) );
#ifdef HAVE_TESSERACT #ifdef HAVE_TESSERACT
......
/*---------------STEP 1---------------------*/
/* modify this file
* opencv2/tracking/tracker.hpp
* and put several lines of snippet similar to
* the following:
*/
/*------------------------------------------*/
class CV_EXPORTS_W TrackerKCF : public Tracker
{
public:
struct CV_EXPORTS Params
{
Params();
void read( const FileNode& /*fn*/ );
void write( FileStorage& /*fs*/ ) const;
};
/** @brief Constructor
@param parameters KCF parameters TrackerKCF::Params
*/
BOILERPLATE_CODE("KCF",TrackerKCF);
};
/*---------------STEP 2---------------------*/
/* modify this file
* src/tracker.cpp
* add one line in function
* Ptr<Tracker> Tracker::create( const String& trackerType )
*/
/*------------------------------------------*/
Ptr<Tracker> Tracker::create( const String& trackerType )
{
BOILERPLATE_CODE("MIL",TrackerMIL);
BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
BOILERPLATE_CODE("TLD",TrackerTLD);
BOILERPLATE_CODE("KCF",TrackerKCF); // add this line!
return Ptr<Tracker>();
}
/*---------------STEP 3---------------------*/
/* make a new file and paste the snippet below
* and modify it according to your needs.
* also make sure to put the LICENSE part.
* src/trackerKCF.cpp
*/
/*------------------------------------------*/
/*---------------------------
| TrackerKCFModel
|---------------------------*/
namespace cv{
/**
* \brief Implementation of TrackerModel for MIL algorithm
*/
class TrackerKCFModel : public TrackerModel{
public:
TrackerKCFModel(TrackerKCF::Params /*params*/){}
~TrackerKCFModel(){}
protected:
void modelEstimationImpl( const std::vector<Mat>& responses ){}
void modelUpdateImpl(){}
};
} /* namespace cv */
/*---------------------------
| TrackerKCF
|---------------------------*/
namespace cv{
/*
* Prototype
*/
class TrackerKCFImpl : public TrackerKCF{
public:
TrackerKCFImpl( const TrackerKCF::Params &parameters = TrackerKCF::Params() );
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
protected:
bool initImpl( const Mat& image, const Rect2d& boundingBox );
bool updateImpl( const Mat& image, Rect2d& boundingBox );
TrackerKCF::Params params;
};
/*
* Constructor
*/
Ptr<TrackerKCF> TrackerKCF::createTracker(const TrackerKCF::Params &parameters){
return Ptr<TrackerKCFImpl>(new TrackerKCFImpl(parameters));
}
TrackerKCFImpl::TrackerKCFImpl( const TrackerKCF::Params &parameters ) :
params( parameters )
{
isInit = false;
}
void TrackerKCFImpl::read( const cv::FileNode& fn ){
params.read( fn );
}
void TrackerKCFImpl::write( cv::FileStorage& fs ) const{
params.write( fs );
}
bool TrackerKCFImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
model=Ptr<TrackerKCFModel>(new TrackerKCFModel(params));
return true;
}
bool TrackerKCFImpl::updateImpl( const Mat& image, Rect2d& boundingBox ){return true;}
/*
* Parameters
*/
TrackerKCF::Params::Params(){
}
void TrackerKCF::Params::read( const cv::FileNode& fn ){
}
void TrackerKCF::Params::write( cv::FileStorage& fs ) const{
}
} /* namespace cv */
...@@ -67,3 +67,29 @@ ...@@ -67,3 +67,29 @@
year={2013}, year={2013},
organization={IEEE} organization={IEEE}
} }
@article{KCF,
title = {High-Speed Tracking with Kernelized Correlation Filters},
journal = {Pattern Analysis and Machine Intelligence, IEEE Transactions on},
author = {Henriques, J. F. and Caseiro, R. and Martins, P. and Batista, J.},
year = {2015},
doi = {10.1109/TPAMI.2014.2345390},
}
@inproceedings{KCF_ECCV,
title = {Exploiting the Circulant Structure of Tracking-by-detection with Kernels},
author = {Henriques, J. F. and Caseiro, R. and Martins, P. and Batista, J.},
booktitle = {proceedings of the European Conference on Computer Vision},
year = {2012},
}
@INPROCEEDINGS{KCF_CN,
author={Danelljan, M. and Khan, F.S. and Felsberg, M. and van de Weijer, J.},
booktitle={Computer Vision and Pattern Recognition (CVPR), 2014 IEEE Conference on},
title={Adaptive Color Attributes for Real-Time Visual Tracking},
year={2014},
month={June},
pages={1090-1097},
keywords={computer vision;feature extraction;image colour analysis;image representation;image sequences;adaptive color attributes;benchmark color sequences;color features;color representations;computer vision;image description;real-time visual tracking;tracking-by-detection framework;Color;Computational modeling;Covariance matrices;Image color analysis;Kernel;Target tracking;Visualization;Adaptive Dimensionality Reduction;Appearance Model;Color Features;Visual Tracking},
doi={10.1109/CVPR.2014.143},
}
...@@ -1189,6 +1189,60 @@ class CV_EXPORTS_W TrackerTLD : public Tracker ...@@ -1189,6 +1189,60 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
BOILERPLATE_CODE("TLD",TrackerTLD); BOILERPLATE_CODE("TLD",TrackerTLD);
}; };
/** @brief KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed.
* This tracking method is an implementation of @cite KCF_ECCV which is extended to KFC with color-names features (@cite KCF_CN).
* The original paper of KCF is available at <http://home.isr.uc.pt/~henriques/circulant/index.html>
* as well as the matlab implementation. For more information about KCF with color-names features, please refer to
* <http://www.cvl.isy.liu.se/research/objrec/visualtracking/colvistrack/index.html>.
*/
class CV_EXPORTS_W TrackerKCF : public Tracker
{
public:
/**
* \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names
* The modes available now:
- "GRAY" -- Use grayscale values as the feature
- "CN" -- Color-names feature
*/
enum MODE {GRAY, CN, CN2};
struct CV_EXPORTS Params
{
/**
* \brief Constructor
*/
Params();
/**
* \brief Read parameters from file, currently unused
*/
void read( const FileNode& /*fn*/ );
/**
* \brief Read parameters from file, currently unused
*/
void write( FileStorage& /*fs*/ ) const;
double sigma; //!< gaussian kernel bandwidth
double lambda; //!< regularization
double interp_factor; //!< linear interpolation factor for adaptation
double output_sigma_factor; //!< spatial bandwidth (proportional to target)
double pca_learning_rate; //!< compression learning rate
bool resize; //!< activate the resize feature to improve the processing speed
bool split_coeff; //!< split the training coefficients into two matrices
bool wrap_kernel; //!< wrap around the kernel values
bool compress_feature; //!< activate the pca method to compress the features
int max_patch_size; //!< threshold for the ROI size
int compressed_size; //!< feature size after compression
MODE descriptor; //!< descriptor type
};
/** @brief Constructor
@param parameters KCF parameters TrackerKCF::Params
*/
BOILERPLATE_CODE("KCF",TrackerKCF);
};
//! @} //! @}
} /* namespace cv */ } /* namespace cv */
......
/*----------------------------------------------
* Usage:
* example_tracking_kcf <video_name>
*
* example:
* example_tracking_kcf Bolt/img/%04.jpg
* example_tracking_kcf faceocc2.webm
*--------------------------------------------------*/
#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
using namespace std;
using namespace cv;
class BoxExtractor {
public:
Rect2d extract(Mat img);
Rect2d extract(const std::string& windowName, Mat img, bool showCrossair = true);
struct handlerT{
bool isDrawing;
Rect2d box;
Mat image;
// initializer list
handlerT(): isDrawing(false) {};
}params;
private:
static void mouseHandler(int event, int x, int y, int flags, void *param);
void opencv_mouse_callback( int event, int x, int y, int , void *param );
};
int main( int argc, char** argv ){
// show help
if(argc<2){
cout<<
" Usage: example_tracking_kcf <video_name>\n"
" examples:\n"
" example_tracking_kcf Bolt/img/%04.jpg\n"
" example_tracking_kcf faceocc2.webm\n"
<< endl;
return 0;
}
// ROI selector
BoxExtractor box;
// create the tracker
Ptr<Tracker> tracker = Tracker::create( "KCF" );
// set input video
std::string video = argv[1];
VideoCapture cap(video);
Mat frame;
// get bounding box
cap >> frame;
Rect2d roi=box.extract("tracker",frame);
//quit if ROI was not selected
if(roi.width==0 || roi.height==0)
return 0;
// initialize the tracker
tracker->init(frame,roi);
// do the tracking
printf("Start the tracking process, press ESC to quit.\n");
for ( ;; ){
// get frame from the video
cap >> frame;
// stop the program if no more images
if(frame.rows==0 || frame.cols==0)
break;
// update the tracking result
tracker->update(frame,roi);
// draw the tracked object
rectangle( frame, roi, Scalar( 255, 0, 0 ), 2, 1 );
// show image with the tracked object
imshow("tracker",frame);
//quit on ESC button
if(waitKey(1)==27)break;
}
}
void BoxExtractor::mouseHandler(int event, int x, int y, int flags, void *param){
BoxExtractor *self =static_cast<BoxExtractor*>(param);
self->opencv_mouse_callback(event,x,y,flags,param);
}
void BoxExtractor::opencv_mouse_callback( int event, int x, int y, int , void *param ){
handlerT * data = (handlerT*)param;
switch( event ){
// update the selected bounding box
case EVENT_MOUSEMOVE:
if( data->isDrawing ){
data->box.width = x-data->box.x;
data->box.height = y-data->box.y;
}
break;
// start to select the bounding box
case EVENT_LBUTTONDOWN:
data->isDrawing = true;
data->box = cvRect( x, y, 0, 0 );
break;
// cleaning up the selected bounding box
case EVENT_LBUTTONUP:
data->isDrawing = false;
if( data->box.width < 0 ){
data->box.x += data->box.width;
data->box.width *= -1;
}
if( data->box.height < 0 ){
data->box.y += data->box.height;
data->box.height *= -1;
}
break;
}
}
Rect2d BoxExtractor::extract(Mat img){
return extract("Bounding Box Extractor", img);
}
Rect2d BoxExtractor::extract(const std::string& windowName, Mat img, bool showCrossair){
int key=0;
// show the image and give feedback to user
imshow(windowName,img);
printf("Select an object to track and then press SPACE/BACKSPACE/ENTER button!\n");
// copy the data, rectangle should be drawn in the fresh image
params.image=img.clone();
// select the object
setMouseCallback( windowName, mouseHandler, (void *)&params );
// end selection process on SPACE (32) BACKSPACE (27) or ENTER (13)
while(!(key==32 || key==27 || key==13)){
// draw the selected object
rectangle(
params.image,
params.box,
Scalar(255,0,0),2,1
);
// draw cross air in the middle of bounding box
if(showCrossair){
// horizontal line
line(
params.image,
Point((int)params.box.x,(int)(params.box.y+params.box.height/2)),
Point((int)(params.box.x+params.box.width),(int)(params.box.y+params.box.height/2)),
Scalar(255,0,0),2,1
);
// vertical line
line(
params.image,
Point((int)(params.box.x+params.box.width/2),(int)params.box.y),
Point((int)(params.box.x+params.box.width/2),(int)(params.box.y+params.box.height)),
Scalar(255,0,0),2,1
);
}
// show the image bouding box
imshow(windowName,params.image);
// reset the image
params.image=img.clone();
//get keyboard event
key=waitKey(1);
}
return params.box;
}
...@@ -48,8 +48,8 @@ ...@@ -48,8 +48,8 @@
using namespace std; using namespace std;
using namespace cv; using namespace cv;
#define NUM_TEST_FRAMES 500 #define NUM_TEST_FRAMES 100
#define TEST_VIDEO_INDEX 1 //TLD Dataset Video Index from 1-10 #define TEST_VIDEO_INDEX 7 //TLD Dataset Video Index from 1-10
//#define RECORD_VIDEO_FLG //#define RECORD_VIDEO_FLG
static Mat image; static Mat image;
......
This diff is collapsed.
// 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.
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
__kernel void NCC(__global const uchar *patch,
__global const uchar *positiveSamples,
__global const uchar *negativeSamples,
__global float *ncc,
int posNum,
int negNum)
{
int id = get_global_id(0);
if (id >= 1000) return;
bool posFlg;
if (id < 500)
posFlg = true;
if (id >= 500)
{
//Negative index
id = id - 500;
posFlg = false;
}
//Variables
int s1 = 0, s2 = 0, n1 = 0, n2 = 0, prod = 0;
float sq1 = 0, sq2 = 0, ares = 0;
int N = 225;
//NCC with positive sample
if (posFlg && id < posNum)
{
for (int i = 0; i < N; i++)
{
s1 += positiveSamples[id * N + i];
s2 += patch[i];
n1 += positiveSamples[id * N + i] * positiveSamples[id * N + i];
n2 += patch[i] * patch[i];
prod += positiveSamples[id * N + i] * patch[i];
}
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
ncc[id] = ares;
}
//NCC with negative sample
if (!posFlg && id < negNum)
{
for (int i = 0; i < N; i++)
{
s1 += negativeSamples[id * N + i];
s2 += patch[i];
n1 += negativeSamples[id * N + i] * negativeSamples[id * N + i];
n2 += patch[i] * patch[i];
prod += negativeSamples[id * N + i] * patch[i];
}
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
ncc[id+500] = ares;
}
}
__kernel void batchNCC(__global const uchar *patches,
__global const uchar *positiveSamples,
__global const uchar *negativeSamples,
__global float *posNcc,
__global float *negNcc,
int posNum,
int negNum,
int patchNum)
{
int id = get_global_id(0);
bool posFlg;
if (id < 500*patchNum)
posFlg = true;
if (id >= 500*patchNum)
{
//Negative index
id = id - 500*patchNum;
posFlg = false;
}
int modelSampleID = id % 500;
int patchID = id / 500;
//Variables
int s1 = 0, s2 = 0, n1 = 0, n2 = 0, prod = 0;
float sq1 = 0, sq2 = 0, ares = 0;
int N = 225;
//NCC with positive sample
if (posFlg && modelSampleID < posNum)
{
for (int i = 0; i < N; i++)
{
s1 += positiveSamples[modelSampleID * N + i];
s2 += patches[patchID*N + i];
n1 += positiveSamples[modelSampleID * N + i] * positiveSamples[modelSampleID * N + i];
n2 += patches[patchID*N + i] * patches[patchID*N + i];
prod += positiveSamples[modelSampleID * N + i] * patches[patchID*N + i];
}
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
posNcc[id] = ares;
}
//NCC with negative sample
if (!posFlg && modelSampleID < negNum)
{
for (int i = 0; i < N; i++)
{
s1 += negativeSamples[modelSampleID * N + i];
s2 += patches[patchID*N + i];
n1 += negativeSamples[modelSampleID * N + i] * negativeSamples[modelSampleID * N + i];
n2 += patches[patchID*N + i] * patches[patchID*N + i];
prod += negativeSamples[modelSampleID * N + i] * patches[patchID*N + i];
}
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
negNcc[id] = ares;
}
}
...@@ -44,5 +44,11 @@ ...@@ -44,5 +44,11 @@
#include "opencv2/tracking.hpp" #include "opencv2/tracking.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#include "opencv2/core/ocl.hpp"
namespace cv
{
extern const double ColorNames[][10];
}
#endif #endif
This diff is collapsed.
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#define OPENCV_TLD_DETECTOR #define OPENCV_TLD_DETECTOR
#include "precomp.hpp" #include "precomp.hpp"
#include "opencl_kernels_tracking.hpp"
#include "tldEnsembleClassifier.hpp" #include "tldEnsembleClassifier.hpp"
#include "tldUtils.hpp" #include "tldUtils.hpp"
...@@ -73,9 +74,14 @@ namespace cv ...@@ -73,9 +74,14 @@ namespace cv
inline double ensembleClassifierNum(const uchar* data); inline double ensembleClassifierNum(const uchar* data);
inline void prepareClassifiers(int rowstep); inline void prepareClassifiers(int rowstep);
double Sr(const Mat_<uchar>& patch); double Sr(const Mat_<uchar>& patch);
double ocl_Sr(const Mat_<uchar>& patch);
double Sc(const Mat_<uchar>& patch); double Sc(const Mat_<uchar>& patch);
double ocl_Sc(const Mat_<uchar>& patch);
void ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches);
std::vector<TLDEnsembleClassifier> classifiers; std::vector<TLDEnsembleClassifier> classifiers;
Mat *posExp, *negExp;
int *posNum, *negNum;
std::vector<Mat_<uchar> > *positiveExamples, *negativeExamples; std::vector<Mat_<uchar> > *positiveExamples, *negativeExamples;
std::vector<int> *timeStampsPositive, *timeStampsNegative; std::vector<int> *timeStampsPositive, *timeStampsNegative;
double *originalVariancePtr; double *originalVariancePtr;
...@@ -87,6 +93,7 @@ namespace cv ...@@ -87,6 +93,7 @@ namespace cv
bool isObject, shouldBeIntegrated; bool isObject, shouldBeIntegrated;
}; };
bool detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize); bool detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize);
bool ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize);
protected: protected:
......
...@@ -58,11 +58,11 @@ namespace cv ...@@ -58,11 +58,11 @@ namespace cv
// Calculate measure locations from 15x15 grid on minSize patches // Calculate measure locations from 15x15 grid on minSize patches
void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr, int pos, int len, int gridSize) void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr, int pos, int len, int gridSize)
{ {
#if 0 #if 0
int step = len / (gridSize - 1), pref = (len - step * (gridSize - 1)) / 2; int step = len / (gridSize - 1), pref = (len - step * (gridSize - 1)) / 2;
for (int i = 0; i < (int)(sizeof(x1) / sizeof(x1[0])); i++) for (int i = 0; i < (int)(sizeof(x1) / sizeof(x1[0])); i++)
arr[i] = pref + arr[i] * step; arr[i] = pref + arr[i] * step;
#else #else
int total = len - gridSize; int total = len - gridSize;
int quo = total / (gridSize - 1), rem = total % (gridSize - 1); int quo = total / (gridSize - 1), rem = total % (gridSize - 1);
int smallStep = quo, bigStep = quo + 1; int smallStep = quo, bigStep = quo + 1;
......
...@@ -64,6 +64,5 @@ namespace cv ...@@ -64,6 +64,5 @@ namespace cv
std::vector<Point2i> offset; std::vector<Point2i> offset;
int lastStep_; int lastStep_;
}; };
} }
} }
\ No newline at end of file
...@@ -56,6 +56,15 @@ namespace cv ...@@ -56,6 +56,15 @@ namespace cv
detector = Ptr<TLDDetector>(new TLDDetector()); detector = Ptr<TLDDetector>(new TLDDetector());
//Propagate data to Detector //Propagate data to Detector
posNum = 0;
negNum = 0;
posExp = Mat(Size(225, 500), CV_8UC1);
negExp = Mat(Size(225, 500), CV_8UC1);
detector->posNum = &posNum;
detector->negNum = &negNum;
detector->posExp = &posExp;
detector->negExp = &negExp;
detector->positiveExamples = &positiveExamples; detector->positiveExamples = &positiveExamples;
detector->negativeExamples = &negativeExamples; detector->negativeExamples = &negativeExamples;
detector->timeStampsPositive = &timeStampsPositive; detector->timeStampsPositive = &timeStampsPositive;
...@@ -69,14 +78,13 @@ namespace cv ...@@ -69,14 +78,13 @@ namespace cv
scaledImg, blurredImg, GaussBlurKernelSize, SCALE_STEP); scaledImg, blurredImg, GaussBlurKernelSize, SCALE_STEP);
GaussianBlur(image, image_blurred, GaussBlurKernelSize, 0.0); GaussianBlur(image, image_blurred, GaussBlurKernelSize, 0.0);
TLDDetector::generateScanGrid(image.rows, image.cols, minSize_, scanGrid); TLDDetector::generateScanGrid(image.rows, image.cols, minSize_, scanGrid);
getClosestN(scanGrid, Rect2d(boundingBox.x / scale, boundingBox.y / scale, boundingBox.width / scale, getClosestN(scanGrid, Rect2d(boundingBox.x / scale, boundingBox.y / scale, boundingBox.width / scale, boundingBox.height / scale), 10, closest);
boundingBox.height / scale), 10, closest);
Mat_<uchar> blurredPatch(minSize); Mat_<uchar> blurredPatch(minSize);
TLDEnsembleClassifier::makeClassifiers(minSize, MEASURES_PER_CLASSIFIER, GRIDSIZE, detector->classifiers); TLDEnsembleClassifier::makeClassifiers(minSize, MEASURES_PER_CLASSIFIER, GRIDSIZE, detector->classifiers);
//Generate initial positive samples and put them to the model //Generate initial positive samples and put them to the model
positiveExamples.reserve(200); positiveExamples.reserve(200);
for (int i = 0; i < (int)closest.size(); i++) for (int i = 0; i < (int)closest.size(); i++)
{ {
for (int j = 0; j < 20; j++) for (int j = 0; j < 20; j++)
...@@ -188,6 +196,11 @@ namespace cv ...@@ -188,6 +196,11 @@ namespace cv
void TrackerTLDModel::integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive) void TrackerTLDModel::integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive)
{ {
int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0; int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0;
if ((int)eForModel.size() == 0) return;
//int64 e1, e2;
//double t;
//e1 = getTickCount();
for (int k = 0; k < (int)eForModel.size(); k++) for (int k = 0; k < (int)eForModel.size(); k++)
{ {
double sr = detector->Sr(eForModel[k]); double sr = detector->Sr(eForModel[k]);
...@@ -218,6 +231,79 @@ namespace cv ...@@ -218,6 +231,79 @@ namespace cv
detector->classifiers[i].integrate(eForEnsemble[k], isPositive); detector->classifiers[i].integrate(eForEnsemble[k], isPositive);
} }
} }
//e2 = getTickCount();
//t = (e2 - e1) / getTickFrequency() * 1000;
//printf("Integrate Additional: %fms\n", t);
/*
if( negativeIntoModel > 0 )
dfprintf((stdout, "negativeIntoModel = %d ", negativeIntoModel));
if( positiveIntoModel > 0 )
dfprintf((stdout, "positiveIntoModel = %d ", positiveIntoModel));
if( negativeIntoEnsemble > 0 )
dfprintf((stdout, "negativeIntoEnsemble = %d ", negativeIntoEnsemble));
if( positiveIntoEnsemble > 0 )
dfprintf((stdout, "positiveIntoEnsemble = %d ", positiveIntoEnsemble));
dfprintf((stdout, "\n"));*/
}
void TrackerTLDModel::ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive)
{
int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0;
if ((int)eForModel.size() == 0) return;
//int64 e1, e2;
//double t;
//e1 = getTickCount();
//Prepare batch of patches
int numOfPatches = (int)eForModel.size();
Mat_<uchar> stdPatches(numOfPatches, 225);
double *resultSr = new double[numOfPatches];
double *resultSc = new double[numOfPatches];
uchar *patchesData = stdPatches.data;
for (int i = 0; i < numOfPatches; i++)
{
uchar *stdPatchData = eForModel[i].data;
for (int j = 0; j < 225; j++)
patchesData[225 * i + j] = stdPatchData[j];
}
//Calculate Sr and Sc batches
detector->ocl_batchSrSc(stdPatches, resultSr, resultSc, numOfPatches);
for (int k = 0; k < (int)eForModel.size(); k++)
{
double sr = resultSr[k];
if ((sr > THETA_NN) != isPositive)
{
if (isPositive)
{
positiveIntoModel++;
pushIntoModel(eForModel[k], true);
}
else
{
negativeIntoModel++;
pushIntoModel(eForModel[k], false);
}
}
double p = 0;
for (int i = 0; i < (int)detector->classifiers.size(); i++)
p += detector->classifiers[i].posteriorProbability(eForEnsemble[k].data, (int)eForEnsemble[k].step[0]);
p /= detector->classifiers.size();
if ((p > ENSEMBLE_THRESHOLD) != isPositive)
{
if (isPositive)
positiveIntoEnsemble++;
else
negativeIntoEnsemble++;
for (int i = 0; i < (int)detector->classifiers.size(); i++)
detector->classifiers[i].integrate(eForEnsemble[k], isPositive);
}
}
//e2 = getTickCount();
//t = (e2 - e1) / getTickFrequency() * 1000;
//printf("Integrate Additional OCL: %fms\n", t);
/* /*
if( negativeIntoModel > 0 ) if( negativeIntoModel > 0 )
dfprintf((stdout, "negativeIntoModel = %d ", negativeIntoModel)); dfprintf((stdout, "negativeIntoModel = %d ", negativeIntoModel));
...@@ -238,12 +324,30 @@ namespace cv ...@@ -238,12 +324,30 @@ namespace cv
std::vector<int>* proxyT; std::vector<int>* proxyT;
if (positive) if (positive)
{ {
if (posNum < 500)
{
uchar *patchPtr = example.data;
uchar *modelPtr = posExp.data;
for (int i = 0; i < STANDARD_PATCH_SIZE*STANDARD_PATCH_SIZE; i++)
modelPtr[posNum*STANDARD_PATCH_SIZE*STANDARD_PATCH_SIZE + i] = patchPtr[i];
posNum++;
}
proxyV = &positiveExamples; proxyV = &positiveExamples;
proxyN = &timeStampPositiveNext; proxyN = &timeStampPositiveNext;
proxyT = &timeStampsPositive; proxyT = &timeStampsPositive;
} }
else else
{ {
if (negNum < 500)
{
uchar *patchPtr = example.data;
uchar *modelPtr = negExp.data;
for (int i = 0; i < STANDARD_PATCH_SIZE*STANDARD_PATCH_SIZE; i++)
modelPtr[negNum*STANDARD_PATCH_SIZE*STANDARD_PATCH_SIZE + i] = patchPtr[i];
negNum++;
}
proxyV = &negativeExamples; proxyV = &negativeExamples;
proxyN = &timeStampNegativeNext; proxyN = &timeStampNegativeNext;
proxyT = &timeStampsNegative; proxyT = &timeStampsNegative;
...@@ -268,9 +372,5 @@ namespace cv ...@@ -268,9 +372,5 @@ namespace cv
dfprintf((port, "\tpositiveExamples.size() = %d\n", (int)positiveExamples.size())); dfprintf((port, "\tpositiveExamples.size() = %d\n", (int)positiveExamples.size()));
dfprintf((port, "\tnegativeExamples.size() = %d\n", (int)negativeExamples.size())); dfprintf((port, "\tnegativeExamples.size() = %d\n", (int)negativeExamples.size()));
} }
} }
} }
\ No newline at end of file
...@@ -50,9 +50,6 @@ namespace cv ...@@ -50,9 +50,6 @@ namespace cv
{ {
namespace tld namespace tld
{ {
class TrackerTLDModel : public TrackerModel class TrackerTLDModel : public TrackerModel
{ {
public: public:
...@@ -61,11 +58,14 @@ namespace cv ...@@ -61,11 +58,14 @@ namespace cv
void setBoudingBox(Rect2d boundingBox){ boundingBox_ = boundingBox; } void setBoudingBox(Rect2d boundingBox){ boundingBox_ = boundingBox; }
void integrateRelabeled(Mat& img, Mat& imgBlurred, const std::vector<TLDDetector::LabeledPatch>& patches); void integrateRelabeled(Mat& img, Mat& imgBlurred, const std::vector<TLDDetector::LabeledPatch>& patches);
void integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive); void integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
void ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
Size getMinSize(){ return minSize_; } Size getMinSize(){ return minSize_; }
void printme(FILE* port = stdout); void printme(FILE* port = stdout);
Ptr<TLDDetector> detector; Ptr<TLDDetector> detector;
std::vector<Mat_<uchar> > positiveExamples, negativeExamples; std::vector<Mat_<uchar> > positiveExamples, negativeExamples;
Mat posExp, negExp;
int posNum, negNum;
std::vector<int> timeStampsPositive, timeStampsNegative; std::vector<int> timeStampsPositive, timeStampsNegative;
int timeStampPositiveNext, timeStampNegativeNext; int timeStampPositiveNext, timeStampNegativeNext;
double originalVariance_; double originalVariance_;
...@@ -80,7 +80,6 @@ namespace cv ...@@ -80,7 +80,6 @@ namespace cv
void modelUpdateImpl(){} void modelUpdateImpl(){}
Rect2d boundingBox_; Rect2d boundingBox_;
RNG rng; RNG rng;
}; };
} }
......
...@@ -116,11 +116,20 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox) ...@@ -116,11 +116,20 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
std::vector<Rect2d> candidates; std::vector<Rect2d> candidates;
std::vector<double> candidatesRes; std::vector<double> candidatesRes;
bool trackerNeedsReInit = false; bool trackerNeedsReInit = false;
bool DETECT_FLG = false;
for( int i = 0; i < 2; i++ ) for( int i = 0; i < 2; i++ )
{ {
Rect2d tmpCandid = boundingBox; Rect2d tmpCandid = boundingBox;
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) ||
((i == 1) && (tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize())))) if (i == 1)
{
if (ocl::haveOpenCL())
DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
else
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
}
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || ( DETECT_FLG))
{ {
candidates.push_back(tmpCandid); candidates.push_back(tmpCandid);
if( i == 0 ) if( i == 0 )
...@@ -202,10 +211,17 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox) ...@@ -202,10 +211,17 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults); tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults);
//dprintf(("%d relabeled by nExpert\n", negRelabeled)); //dprintf(("%d relabeled by nExpert\n", negRelabeled));
pExpert.additionalExamples(examplesForModel, examplesForEnsemble); pExpert.additionalExamples(examplesForModel, examplesForEnsemble);
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true); if (ocl::haveOpenCL())
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
else
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
examplesForModel.clear(); examplesForEnsemble.clear(); examplesForModel.clear(); examplesForEnsemble.clear();
nExpert.additionalExamples(examplesForModel, examplesForEnsemble); nExpert.additionalExamples(examplesForModel, examplesForEnsemble);
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
if (ocl::haveOpenCL())
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
else
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
} }
else else
{ {
......
...@@ -60,7 +60,6 @@ void TrackerTLD::Params::write(cv::FileStorage& /*fs*/) const {} ...@@ -60,7 +60,6 @@ void TrackerTLD::Params::write(cv::FileStorage& /*fs*/) const {}
namespace tld namespace tld
{ {
class TrackerProxy class TrackerProxy
{ {
public: public:
......
...@@ -110,6 +110,7 @@ Ptr<Tracker> Tracker::create( const String& trackerType ) ...@@ -110,6 +110,7 @@ Ptr<Tracker> Tracker::create( const String& trackerType )
BOILERPLATE_CODE("BOOSTING",TrackerBoosting); BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow); BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
BOILERPLATE_CODE("TLD",TrackerTLD); BOILERPLATE_CODE("TLD",TrackerTLD);
BOILERPLATE_CODE("KCF",TrackerKCF);
return Ptr<Tracker>(); return Ptr<Tracker>();
} }
......
This diff is collapsed.
...@@ -165,10 +165,10 @@ Note: the descriptor can be coupled with any keypoint extractor. The only demand ...@@ -165,10 +165,10 @@ Note: the descriptor can be coupled with any keypoint extractor. The only demand
Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures2D/latch_match.cpp Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures2D/latch_match.cpp
*/ */
class CV_EXPORTS LATCH : public DescriptorExtractor class CV_EXPORTS_W LATCH : public Feature2D
{ {
public: public:
static Ptr<LATCH> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size=3); CV_WRAP static Ptr<LATCH> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size=3);
}; };
/** @brief Class implementing DAISY descriptor, described in @cite Tola10 /** @brief Class implementing DAISY descriptor, described in @cite Tola10
...@@ -187,14 +187,14 @@ DAISY::NRM_SIFT mean that descriptors are normalized for L2 norm equal to 1.0 bu ...@@ -187,14 +187,14 @@ DAISY::NRM_SIFT mean that descriptors are normalized for L2 norm equal to 1.0 bu
@param use_orientation sample patterns using keypoints orientation, disabled by default. @param use_orientation sample patterns using keypoints orientation, disabled by default.
*/ */
class CV_EXPORTS DAISY : public DescriptorExtractor class CV_EXPORTS_W DAISY : public Feature2D
{ {
public: public:
enum enum
{ {
NRM_NONE = 100, NRM_PARTIAL = 101, NRM_FULL = 102, NRM_SIFT = 103, NRM_NONE = 100, NRM_PARTIAL = 101, NRM_FULL = 102, NRM_SIFT = 103,
}; };
static Ptr<DAISY> create( float radius = 15, int q_radius = 3, int q_theta = 8, CV_WRAP static Ptr<DAISY> create( float radius = 15, int q_radius = 3, int q_theta = 8,
int q_hist = 8, int norm = DAISY::NRM_NONE, InputArray H = noArray(), int q_hist = 8, int norm = DAISY::NRM_NONE, InputArray H = noArray(),
bool interpolation = true, bool use_orientation = false ); bool interpolation = true, bool use_orientation = false );
......
...@@ -1267,7 +1267,7 @@ struct RoundingInvoker : ParallelLoopBody ...@@ -1267,7 +1267,7 @@ struct RoundingInvoker : ParallelLoopBody
{ {
for (int c = range.start; c < range.end; ++c) for (int c = range.start; c < range.end; ++c)
{ {
scale_map->at<float>(r,c) = (float) round( scale_map->at<float>(r,c) ); scale_map->at<float>(r,c) = (float) cvRound( scale_map->at<float>(r,c) );
} }
} }
int r; int r;
......
...@@ -55,3 +55,25 @@ ...@@ -55,3 +55,25 @@
year={2013}, year={2013},
organization={IEEE} organization={IEEE}
} }
@article{Min2014,
title={Fast global image smoothing based on weighted least squares},
author={Min, Dongbo and Choi, Sunghwan and Lu, Jiangbo and Ham, Bumsub and Sohn, Kwanghoon and Do, Minh N},
journal={Image Processing, IEEE Transactions on},
volume={23},
number={12},
pages={5638--5653},
year={2014},
publisher={IEEE}
}
@inproceedings{Farbman2008,
title={Edge-preserving decompositions for multi-scale tone and detail manipulation},
author={Farbman, Zeev and Fattal, Raanan and Lischinski, Dani and Szeliski, Richard},
booktitle={ACM Transactions on Graphics (TOG)},
volume={27},
number={3},
pages={67},
year={2008},
organization={ACM}
}
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define __OPENCV_XIMGPROC_HPP__ #define __OPENCV_XIMGPROC_HPP__
#include "ximgproc/edge_filter.hpp" #include "ximgproc/edge_filter.hpp"
#include "ximgproc/disparity_filter.hpp"
#include "ximgproc/structured_edge_detection.hpp" #include "ximgproc/structured_edge_detection.hpp"
#include "ximgproc/seeds.hpp" #include "ximgproc/seeds.hpp"
......
...@@ -43,49 +43,147 @@ ...@@ -43,49 +43,147 @@
namespace cv { namespace cv {
namespace ximgproc { namespace ximgproc {
//! @addtogroup ximgproc_filters
//! @{
/** @brief Main interface for all disparity map filters.
*/
class CV_EXPORTS_W DisparityFilter : public Algorithm class CV_EXPORTS_W DisparityFilter : public Algorithm
{ {
public: public:
CV_WRAP virtual void filter(InputArray disparity_map, InputArray left_view, OutputArray filtered_disparity_map,Rect ROI) = 0;
};
///////////////////////////////////////////////////////////////////////////////////////////////// /** @brief Apply filtering to the disparity map.
class CV_EXPORTS_W DisparityDTFilter : public DisparityFilter @param disparity_map_left disparity map of the left view, 1 channel, CV_16S type. Implicitly assumes that disparity
{ values are scaled by 16 (one-pixel disparity corresponds to the value of 16 in the disparity map). Disparity map
public: can have any resolution, it will be automatically resized to fit left_view resolution.
CV_WRAP virtual double getSigmaSpatial() = 0;
CV_WRAP virtual void setSigmaSpatial(double _sigmaSpatial) = 0;
CV_WRAP virtual double getSigmaColor() = 0;
CV_WRAP virtual void setSigmaColor(double _sigmaColor) = 0;
};
CV_EXPORTS_W @param left_view left view of the original stereo-pair to guide the filtering process, 8-bit single-channel
Ptr<DisparityDTFilter> createDisparityDTFilter(); or three-channel image.
class CV_EXPORTS_W DisparityGuidedFilter : public DisparityFilter @param filtered_disparity_map output disparity map.
{
public:
CV_WRAP virtual double getEps() = 0;
CV_WRAP virtual void setEps(double _eps) = 0;
CV_WRAP virtual int getRadius() = 0;
CV_WRAP virtual void setRadius(int _radius) = 0;
};
CV_EXPORTS_W @param ROI region of the disparity map to filter.
Ptr<DisparityGuidedFilter> createDisparityGuidedFilter();
@param disparity_map_right optional argument, some implementations might also use the disparity map
of the right view to compute confidence maps, for instance.
@param right_view optional argument, some implementations might also use the right view of the original
stereo-pair.
*/
CV_WRAP virtual void filter(InputArray disparity_map_left, InputArray left_view, OutputArray filtered_disparity_map, Rect ROI, InputArray disparity_map_right = Mat(), InputArray right_view = Mat()) = 0;
};
/** @brief Disparity map filter based on Weighted Least Squares filter (in form of Fast Global Smoother that
is a lot faster than traditional Weighted Least Squares filter implementations) and optional use of
left-right-consistency-based confidence to refine the results in half-occlusions and uniform areas.
*/
class CV_EXPORTS_W DisparityWLSFilter : public DisparityFilter class CV_EXPORTS_W DisparityWLSFilter : public DisparityFilter
{ {
public:
/** filter parameters */
/** @brief Lambda is a parameter defining the amount of regularization during filtering. Larger values force
filtered disparity map edges to adhere more to source image edges. Typical value is 8000.
*/
CV_WRAP virtual double getLambda() = 0; CV_WRAP virtual double getLambda() = 0;
/** @see getLambda */
CV_WRAP virtual void setLambda(double _lambda) = 0; CV_WRAP virtual void setLambda(double _lambda) = 0;
/** @brief SigmaColor is a parameter defining how sensitive the filtering process is to source image edges.
Large values can lead to disparity leakage through low-contrast edges. Small values can make the filter too
sensitive to noise and textures in the source image. Typical values range from 0.8 to 2.0.
*/
CV_WRAP virtual double getSigmaColor() = 0; CV_WRAP virtual double getSigmaColor() = 0;
/** @see getSigmaColor */
CV_WRAP virtual void setSigmaColor(double _sigma_color) = 0; CV_WRAP virtual void setSigmaColor(double _sigma_color) = 0;
/** confidence-related parameters */
/** @brief LRCthresh is a threshold of disparity difference used in left-right-consistency check during
confidence map computation. The default value of 24 (1.5 pixels) is virtually always good enough.
*/
CV_WRAP virtual int getLRCthresh() = 0;
/** @see getLRCthresh */
CV_WRAP virtual void setLRCthresh(int _LRC_thresh) = 0;
/** @brief DepthDiscontinuityRadius is a parameter used in confidence computation. It defines the size of
low-confidence regions around depth discontinuities. For typical window sizes used in stereo matching the
optimal value is around 5.
*/
CV_WRAP virtual int getDepthDiscontinuityRadius() = 0;
/** @see getDepthDiscontinuityRadius */
CV_WRAP virtual void setDepthDiscontinuityRadius(int _disc_radius) = 0;
/** @brief Get the confidence map that was used in the last filter call. It is a CV_32F one-channel image
with values ranging from 0.0 (totally untrusted regions of the raw disparity map) to 255.0 (regions containing
correct disparity values with a high degree of confidence).
*/
CV_WRAP virtual Mat getConfidenceMap() = 0;
}; };
/** @brief Factory method, create instance of DisparityWLSFilter and execute the initialization routines.
@param use_confidence filtering with confidence requires two disparity maps (for the left and right views) and is
approximately two times slower. However, quality is typically significantly better.
*/
CV_EXPORTS_W CV_EXPORTS_W
Ptr<DisparityWLSFilter> createDisparityWLSFilter(); Ptr<DisparityWLSFilter> createDisparityWLSFilter(bool use_confidence);
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/** @brief Function for reading ground truth disparity maps. Supports basic Middlebury
and MPI-Sintel formats. Note that the resulting disparity map is scaled by 16.
@param src_path path to the image, containing ground-truth disparity map
@param dst output disparity map, CV_16S depth
@result returns zero if successfully read the ground truth
*/
CV_EXPORTS
int readGT(String src_path,OutputArray dst);
/** @brief Function for computing mean square error for disparity maps
@param GT ground truth disparity map
@param src disparity map to evaluate
@param ROI region of interest
@result returns mean square error between GT and src
*/
CV_EXPORTS
double computeMSE(InputArray GT, InputArray src, Rect ROI);
/** @brief Function for computing the percent of "bad" pixels in the disparity map
(pixels where error is higher than a specified threshold)
@param GT ground truth disparity map
@param src disparity map to evaluate
@param ROI region of interest
@param thresh threshold used to determine "bad" pixels
@result returns mean square error between GT and src
*/
CV_EXPORTS
double computeBadPixelPercent(InputArray GT, InputArray src, Rect ROI, int thresh=24/*1.5 pixels*/);
/** @brief Function for creating a disparity map visualization (clamped CV_8U image)
@param src input disparity map (CV_16S depth)
@param dst output visualization
@param scale disparity map will be multiplied by this value for visualization
*/
CV_EXPORTS
void getDisparityVis(InputArray src,OutputArray dst,double scale=1.0);
//! @}
} }
} }
#endif #endif
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -273,8 +273,8 @@ void SuperpixelSEEDSImpl::initialize(int num_superpixels, int num_levels) ...@@ -273,8 +273,8 @@ void SuperpixelSEEDSImpl::initialize(int num_superpixels, int num_levels)
parent_pre_init.resize(seeds_nr_levels); parent_pre_init.resize(seeds_nr_levels);
nr_wh.resize(2 * seeds_nr_levels); nr_wh.resize(2 * seeds_nr_levels);
int level = 0; int level = 0;
int nr_seeds_w = (int)floor(width / seeds_w); int nr_seeds_w = (width / seeds_w);
int nr_seeds_h = (int)floor(height / seeds_h); int nr_seeds_h = (height / seeds_h);
nr_wh[2 * level] = nr_seeds_w; nr_wh[2 * level] = nr_seeds_w;
nr_wh[2 * level + 1] = nr_seeds_h; nr_wh[2 * level + 1] = nr_seeds_h;
parent_mat.push_back(Mat(nr_seeds_h, nr_seeds_w, CV_32SC1)); parent_mat.push_back(Mat(nr_seeds_h, nr_seeds_w, CV_32SC1));
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0"?>
<opencv_storage>
<x>166</x>
<y>7</y>
<width>851</width>
<height>422</height>
</opencv_storage>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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