pull/223/head
Alexandre Benoit 11 years ago
commit e67d4ac13f
  1. 4
      modules/adas/CMakeLists.txt
  2. 40
      modules/adas/include/opencv2/adas.hpp
  3. 0
      modules/adas/src/adas.cpp
  4. 34
      modules/adas/tools/CMakeLists.txt
  5. 195
      modules/adas/tools/fcw_train.cpp
  6. 4
      modules/bioinspired/include/opencv2/bioinspired/transientareassegmentationmodule.hpp
  7. 11
      modules/bioinspired/src/transientareassegmentationmodule.cpp
  8. 4
      modules/reg/samples/map_test.cpp
  9. 3
      modules/rgbd/samples/odometry_evaluation.cpp
  10. 12
      modules/rgbd/src/depth_cleaner.cpp
  11. 8
      modules/rgbd/src/depth_to_3d.cpp
  12. 10
      modules/rgbd/src/depth_to_3d.h
  13. 31
      modules/rgbd/src/normal.cpp
  14. 62
      modules/rgbd/src/odometry.cpp
  15. 13
      modules/rgbd/src/plane.cpp
  16. 4
      modules/rgbd/src/rgbd_init.cpp
  17. 4
      modules/rgbd/src/utils.cpp
  18. 45
      modules/rgbd/test/test_normal.cpp
  19. 4
      modules/rgbd/test/test_odometry.cpp
  20. 2
      modules/rgbd/test/test_utils.cpp
  21. 18
      modules/tracking/perf/perf_Tracker.cpp
  22. 20
      modules/tracking/samples/tracker.cpp
  23. 4
      modules/tracking/src/PFSolver.hpp
  24. 2
      modules/tracking/src/TrackingFunctionPF.hpp
  25. 14
      modules/tracking/src/feature.cpp
  26. 10
      modules/tracking/src/onlineBoosting.cpp
  27. 2
      modules/tracking/src/onlineMIL.cpp
  28. 22
      modules/tracking/src/trackerBoosting.cpp
  29. 8
      modules/tracking/src/trackerBoostingModel.cpp
  30. 10
      modules/tracking/src/trackerFeature.cpp
  31. 6
      modules/tracking/src/trackerMIL.cpp
  32. 4
      modules/tracking/src/trackerMILModel.cpp
  33. 2
      modules/tracking/src/trackerStateEstimator.cpp
  34. 12
      modules/tracking/test/test_trackerOPE.cpp
  35. 60
      modules/tracking/test/test_trackerSRE.cpp
  36. 17
      modules/tracking/test/test_trackerTRE.cpp
  37. 2
      modules/xobjdetect/CMakeLists.txt
  38. 179
      modules/xobjdetect/include/opencv2/xobjdetect.hpp
  39. 62
      modules/xobjdetect/include/opencv2/xobjdetect/private.hpp
  40. 203
      modules/xobjdetect/src/acffeature.cpp
  41. 150
      modules/xobjdetect/src/icfdetector.cpp
  42. 56
      modules/xobjdetect/src/precomp.hpp
  43. 203
      modules/xobjdetect/src/stump.cpp
  44. 187
      modules/xobjdetect/src/waldboost.cpp

@ -0,0 +1,4 @@
set(the_description "Automatic driver assistance algorithms")
ocv_define_module(adas opencv_xobjdetect)
add_subdirectory(tools)

@ -0,0 +1,40 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/

@ -0,0 +1,34 @@
set(name fcw_train)
set(the_target opencv_${name})
set(OPENCV_${the_target}_DEPS opencv_xobjdetect)
ocv_check_dependencies(${OPENCV_${the_target}_DEPS})
if(NOT OCV_DEPENDENCIES_FOUND)
return()
endif()
project(${the_target})
ocv_include_directories("${OpenCV_SOURCE_DIR}/include/opencv")
ocv_include_modules(${OPENCV_${the_target}_DEPS})
file(GLOB ${the_target}_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
add_executable(${the_target} ${${the_target}_SOURCES})
target_link_libraries(${the_target} ${OPENCV_${the_target}_DEPS})
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib
OUTPUT_NAME ${the_target})
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "applications")
endif()
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)

@ -0,0 +1,195 @@
#include <cstdio>
#include <cstring>
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <fstream>
using std::ifstream;
using std::getline;
#include <sstream>
using std::stringstream;
#include <iostream>
using std::cerr;
using std::endl;
#include <opencv2/core.hpp>
using cv::Rect;
#include <opencv2/xobjdetect.hpp>
using cv::xobjdetect::ICFDetectorParams;
using cv::xobjdetect::ICFDetector;
using cv::xobjdetect::WaldBoost;
using cv::xobjdetect::WaldBoostParams;
using cv::Mat;
static bool read_pos_int(const char *str, int *n)
{
int pos = 0;
if( sscanf(str, "%d%n", n, &pos) != 1 || str[pos] != '\0' || *n <= 0 )
{
return false;
}
return true;
}
static bool read_model_size(char *str, int *rows, int *cols)
{
int pos = 0;
if( sscanf(str, "%dx%d%n", rows, cols, &pos) != 2 || str[pos] != '\0' ||
*rows <= 0 || *cols <= 0)
{
return false;
}
return true;
}
static bool read_overlap(const char *str, double *overlap)
{
int pos = 0;
if( sscanf(str, "%lf%n", overlap, &pos) != 1 || str[pos] != '\0' ||
*overlap < 0 || *overlap > 1)
{
return false;
}
return true;
}
static bool read_labels(const string& path,
vector<string>& filenames, vector< vector<Rect> >& labels)
{
string labels_path = path + "/gt.txt";
string filename, line;
int x1, y1, x2, y2;
char delim;
ifstream ifs(labels_path.c_str());
if( !ifs.good() )
return false;
while( getline(ifs, line) )
{
stringstream stream(line);
stream >> filename;
filenames.push_back(path + "/" + filename);
vector<Rect> filename_labels;
while( stream >> x1 >> y1 >> x2 >> y2 >> delim )
{
filename_labels.push_back(Rect(x1, y1, x2, y2));
}
labels.push_back(filename_labels);
filename_labels.clear();
}
return true;
}
int main(int argc, char *argv[])
{
if( argc == 1 )
{
printf("Usage: %s OPTIONS, where OPTIONS are:\n"
"\n"
"--path <path> - path to dir with data and labels\n"
" (labels should have name gt.txt)\n"
"\n"
"--feature_count <count> - number of features to generate\n"
"\n"
"--weak_count <count> - number of weak classifiers in cascade\n"
"\n"
"--model_size <rowsxcols> - model size in pixels\n"
"\n"
"--overlap <measure> - number from [0, 1], means maximum\n"
" overlap with objects while sampling background\n"
"\n"
"--model_filename <path> - filename for saving model\n",
argv[0]);
return 0;
}
string path, model_path;
ICFDetectorParams params;
for( int i = 1; i < argc; ++i )
{
if( !strcmp("--path", argv[i]) )
{
i += 1;
path = argv[i];
}
else if( !strcmp("--feature_count", argv[i]) )
{
i += 1;
if( !read_pos_int(argv[i], &params.feature_count) )
{
fprintf(stderr, "Error reading feature count from `%s`\n",
argv[i]);
return 1;
}
}
else if( !strcmp("--weak_count", argv[i]) )
{
i += 1;
if( !read_pos_int(argv[i], &params.weak_count) )
{
fprintf(stderr, "Error reading weak count from `%s`\n",
argv[i]);
return 1;
}
}
else if( !strcmp("--model_size", argv[i]) )
{
i += 1;
if( !read_model_size(argv[i], &params.model_n_rows,
&params.model_n_cols) )
{
fprintf(stderr, "Error reading model size from `%s`\n",
argv[i]);
return 1;
}
}
else if( !strcmp("--overlap", argv[i]) )
{
i += 1;
if( !read_overlap(argv[i], &params.overlap) )
{
fprintf(stderr, "Error reading overlap from `%s`\n",
argv[i]);
return 1;
}
}
else if( !strcmp("--model_filename", argv[i]) )
{
i += 1;
model_path = argv[i];
}
else
{
fprintf(stderr, "Error: unknown argument `%s`\n", argv[i]);
return 1;
}
}
try
{
ICFDetector detector;
vector<string> filenames;
vector< vector<Rect> > labels;
read_labels(path, filenames, labels);
detector.train(filenames, labels, params);
}
catch( const char *err )
{
cerr << err << endl;
}
catch( ... )
{
cerr << "Unknown error\n" << endl;
}
}

@ -137,12 +137,12 @@ public:
* @param newParameters : a parameters structures updated with the new target configuration
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
*/
virtual void setup(TransientAreasSegmentationModule::SegmentationParameters newParameters)=0;
virtual void setup(SegmentationParameters newParameters)=0;
/**
* @return the current parameters setup
*/
virtual struct TransientAreasSegmentationModule::TransientAreasSegmentationModule::SegmentationParameters getParameters()=0;
virtual SegmentationParameters getParameters()=0;
/**
* parameters setup display method

@ -86,7 +86,8 @@ namespace cv
namespace bioinspired
{
class TransientAreasSegmentationModuleImpl: protected BasicRetinaFilter
class TransientAreasSegmentationModuleImpl :
protected BasicRetinaFilter
{
public:
@ -136,7 +137,7 @@ public:
/**
* @return the current parameters setup
*/
struct TransientAreasSegmentationModule::TransientAreasSegmentationModule::SegmentationParameters getParameters();
struct TransientAreasSegmentationModule::SegmentationParameters getParameters();
/**
* parameters setup display method
@ -219,19 +220,21 @@ protected:
// Buffer conversion utilities
void _convertValarrayBuffer2cvMat(const std::valarray<bool> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, OutputArray outBuffer);
bool _convertCvMat2ValarrayBuffer(InputArray inputMat, std::valarray<float> &outputValarrayMatrix);
const TransientAreasSegmentationModuleImpl & operator = (const TransientAreasSegmentationModuleImpl &);
};
class TransientAreasSegmentationModuleImpl_: public TransientAreasSegmentationModule
{
public:
TransientAreasSegmentationModuleImpl_(const Size size):_segmTool(size){};
TransientAreasSegmentationModuleImpl_(const Size size):_segmTool(size){};
inline virtual Size getSize(){return _segmTool.getSize();};
inline virtual void write( cv::FileStorage& fs ) const{_segmTool.write(fs);};
inline virtual void setup(String segmentationParameterFile, const bool applyDefaultSetupOnFailure){_segmTool.setup(segmentationParameterFile, applyDefaultSetupOnFailure);};
inline virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure){_segmTool.setup(fs, applyDefaultSetupOnFailure);};
inline virtual void setup(TransientAreasSegmentationModule::SegmentationParameters newParameters){_segmTool.setup(newParameters);};
inline virtual const String printSetup(){return _segmTool.printSetup();};
inline virtual struct TransientAreasSegmentationModule::TransientAreasSegmentationModule::SegmentationParameters getParameters(){return _segmTool.getParameters();};
inline virtual struct TransientAreasSegmentationModule::SegmentationParameters getParameters(){return _segmTool.getParameters();};
inline virtual void write( String fs ) const{_segmTool.write(fs);};
inline virtual void run(InputArray inputToSegment, const int channelIndex){_segmTool.run(inputToSegment, channelIndex);};
inline virtual void getSegmentationPicture(OutputArray transientAreas){return _segmTool.getSegmentationPicture(transientAreas);};

@ -125,7 +125,7 @@ static void testEuclidean(const Mat& img1)
Mat img2;
// Warp original image
double theta = 3*M_PI/180;
double theta = 3*CV_PI/180;
double cosT = cos(theta);
double sinT = sin(theta);
Matx<double, 2, 2> linTr(cosT, -sinT, sinT, cosT);
@ -163,7 +163,7 @@ static void testSimilarity(const Mat& img1)
Mat img2;
// Warp original image
double theta = 3*M_PI/180;
double theta = 3*CV_PI/180;
double scale = 0.95;
double a = scale*cos(theta);
double b = scale*sin(theta);

@ -40,7 +40,6 @@
#include <opencv2/calib3d.hpp>
#include <opencv2/imgproc.hpp>
#include <dirent.h>
#include <iostream>
#include <fstream>
@ -187,7 +186,7 @@ int main(int argc, char** argv)
// scale depth
Mat depth_flt;
depth.convertTo(depth_flt, CV_32FC1, 1.f/5000.f);
#if not BILATERAL_FILTER
#if !BILATERAL_FILTER
depth_flt.setTo(std::numeric_limits<float>::quiet_NaN(), depth == 0);
depth = depth_flt;
#else

@ -114,7 +114,7 @@ namespace
{
const cv::Mat_<unsigned short> &depth(depth_in);
cv::Mat depth_out_tmp;
computeImpl<unsigned short, float>(depth, depth_out_tmp, 0.001);
computeImpl<unsigned short, float>(depth, depth_out_tmp, 0.001f);
depth_out_tmp.convertTo(depth_out, CV_16U);
break;
}
@ -142,16 +142,16 @@ namespace
void
computeImpl(const cv::Mat_<DepthDepth> &depth_in, cv::Mat & depth_out, ContainerDepth scale) const
{
const ContainerDepth theta_mean = 30. * CV_PI / 180;
const ContainerDepth theta_mean = (float)(30. * CV_PI / 180);
int rows = depth_in.rows;
int cols = depth_in.cols;
// Precompute some data
const ContainerDepth sigma_L = 0.8 + 0.035 * theta_mean / (CV_PI / 2 - theta_mean);
const ContainerDepth sigma_L = (float)(0.8 + 0.035 * theta_mean / (CV_PI / 2 - theta_mean));
cv::Mat_<ContainerDepth> sigma_z(rows, cols);
for (int y = 0; y < rows; ++y)
for (int x = 0; x < cols; ++x)
sigma_z(y, x) = 0.0012 + 0.0019 * (depth_in(y, x) * scale - 0.4) * (depth_in(y, x) * scale - 0.4);
sigma_z(y, x) = (float)(0.0012 + 0.0019 * (depth_in(y, x) * scale - 0.4) * (depth_in(y, x) * scale - 0.4));
ContainerDepth difference_threshold = 10;
cv::Mat_<ContainerDepth> Dw_sum = cv::Mat_<ContainerDepth>::zeros(rows, cols), w_sum =
@ -170,9 +170,9 @@ namespace
ContainerDepth(j) * ContainerDepth(j) + ContainerDepth(i) * ContainerDepth(i));
ContainerDepth delta_z;
if (depth_in(y, x) > depth_in(y + j, x + i))
delta_z = depth_in(y, x) - depth_in(y + j, x + i);
delta_z = (float)(depth_in(y, x) - depth_in(y + j, x + i));
else
delta_z = depth_in(y + j, x + i) - depth_in(y, x);
delta_z = (float)(depth_in(y + j, x + i) - depth_in(y, x));
if (delta_z < difference_threshold)
{
delta_z *= scale;

@ -104,9 +104,9 @@ namespace
size_t n_points;
if (depth.depth() == CV_16U)
n_points = convertDepthToFloat<uint16_t>(depth, mask, 1.0 / 1000.0f, u_mat, v_mat, z_mat);
n_points = convertDepthToFloat<ushort>(depth, mask, 1.0f / 1000.0f, u_mat, v_mat, z_mat);
else if (depth.depth() == CV_16S)
n_points = convertDepthToFloat<int16_t>(depth, mask, 1.0 / 1000.0f, u_mat, v_mat, z_mat);
n_points = convertDepthToFloat<short>(depth, mask, 1.0f / 1000.0f, u_mat, v_mat, z_mat);
else
{
CV_Assert(depth.type() == CV_32F);
@ -199,9 +199,9 @@ namespace cv
cv::Mat_<float> z_mat;
if (depth.depth() == CV_16U)
convertDepthToFloat<uint16_t>(depth, 1.0 / 1000.0f, points_float, z_mat);
convertDepthToFloat<ushort>(depth, 1.0f / 1000.0f, points_float, z_mat);
else if (depth.depth() == CV_16U)
convertDepthToFloat<int16_t>(depth, 1.0 / 1000.0f, points_float, z_mat);
convertDepthToFloat<short>(depth, 1.0f / 1000.0f, points_float, z_mat);
else
{
CV_Assert(depth.type() == CV_32F);

@ -72,14 +72,14 @@ convertDepthToFloat(const cv::Mat& depth, const cv::Mat& mask, float scale, cv::
for (int u = 0; u < depth_size.width; u++, ++r)
if (*r)
{
u_mat(n_points, 0) = u;
v_mat(n_points, 0) = v;
u_mat((int)n_points, 0) = (float)u;
v_mat((int)n_points, 0) = (float)v;
T depth_i = depth.at<T>(v, u);
if (cvIsNaN(depth_i) || (depth_i == std::numeric_limits<T>::min()) || (depth_i == std::numeric_limits<T>::max()))
z_mat(n_points, 0) = std::numeric_limits<float>::quiet_NaN();
z_mat((int)n_points, 0) = std::numeric_limits<float>::quiet_NaN();
else
z_mat(n_points, 0) = depth_i * scale;
z_mat((int)n_points, 0) = depth_i * scale;
++n_points;
}
@ -104,7 +104,7 @@ convertDepthToFloat(const cv::Mat& depth, float scale, const cv::Mat &uv_mat, cv
for (cv::Mat_<cv::Vec2f>::const_iterator uv_iter = uv_mat.begin<cv::Vec2f>(), uv_end = uv_mat.end<cv::Vec2f>();
uv_iter != uv_end; ++uv_iter, ++z_mat_iter)
{
T depth_i = depth.at < T > ((*uv_iter)[1], (*uv_iter)[0]);
T depth_i = depth.at < T > ((int)(*uv_iter)[1], (int)(*uv_iter)[0]);
if (cvIsNaN(depth_i) || (depth_i == std::numeric_limits < T > ::min())
|| (depth_i == std::numeric_limits < T > ::max()))

@ -111,10 +111,10 @@ namespace
// In the paper, z goes away from the camera, y goes down, x goes right
// OpenCV has the same conventions
// Theta goes from z to x (and actually goes from -pi/2 to pi/2, phi goes from z to y
float theta = std::atan2(row_points->val[0], row_points->val[2]);
float theta = (float)std::atan2(row_points->val[0], row_points->val[2]);
*row_cos_theta = std::cos(theta);
*row_sin_theta = std::sin(theta);
float phi = std::asin(row_points->val[1] / (*row_r));
float phi = (float)std::asin(row_points->val[1] / (*row_r));
*row_cos_phi = std::cos(phi);
*row_sin_phi = std::sin(phi);
}
@ -195,7 +195,7 @@ namespace
if ((K_ori.cols != K_ori_.cols) || (K_ori.rows != K_ori_.rows) || (K_ori.type() != K_ori_.type()))
return false;
bool K_test = !(cv::countNonZero(K_ori != K_ori_));
return (rows == rows_) && (cols = cols_) && (window_size == window_size_) && (depth == depth_) && (K_test)
return (rows == rows_) && (cols == cols_) && (window_size == window_size_) && (depth == depth_) && (K_test)
&& (method == method_);
}
protected:
@ -307,7 +307,14 @@ namespace
(*normal)[2] = *row_r;
}
else
signNormal((*M_inv) * (*B_vec), *normal);
{
Mat33T Mr = *M_inv;
Vec3T Br = *B_vec;
Vec3T MBr(Mr(0, 0) * Br[0] + Mr(0, 1)*Br[1] + Mr(0, 2)*Br[2],
Mr(1, 0) * Br[0] + Mr(1, 1)*Br[1] + Mr(1, 2)*Br[2],
Mr(2, 0) * Br[0] + Mr(2, 1)*Br[1] + Mr(2, 2)*Br[2]);
signNormal(MBr, *normal);
}
}
private:
@ -330,9 +337,9 @@ template<typename T, typename U>
void
multiply_by_K_inv(const cv::Matx<T, 3, 3> & K_inv, U a, U b, U c, cv::Vec<T, 3> &res)
{
res[0] = K_inv(0, 0) * a + K_inv(0, 1) * b + K_inv(0, 2) * c;
res[1] = K_inv(1, 1) * b + K_inv(1, 2) * c;
res[2] = c;
res[0] = (T)(K_inv(0, 0) * a + K_inv(0, 1) * b + K_inv(0, 2) * c);
res[1] = (T)(K_inv(1, 1) * b + K_inv(1, 2) * c);
res[2] = (T)c;
}
namespace
@ -424,7 +431,7 @@ namespace
// Define K_inv by hand, just for higher accuracy
Mat33T K_inv = cv::Matx<T, 3, 3>::eye(), K;
K_.copyTo(K);
K_inv(0, 0) = 1.0 / K(0, 0);
K_inv(0, 0) = 1.0f / K(0, 0);
K_inv(0, 1) = -K(0, 1) / (K(0, 0) * K(1, 1));
K_inv(0, 2) = (K(0, 1) * K(1, 2) - K(0, 2) * K(1, 1)) / (K(0, 0) * K(1, 1));
K_inv(1, 1) = 1 / K(1, 1);
@ -527,8 +534,8 @@ namespace
getDerivKernels(kx_dy_, ky_dy_, 0, 1, window_size_, true, depth_);
// Get the mapping function for SRI
float min_theta = std::asin(sin_theta(0, 0)), max_theta = std::asin(sin_theta(0, cols_ - 1));
float min_phi = std::asin(sin_phi(0, cols_/2-1)), max_phi = std::asin(sin_phi(rows_ - 1, cols_/2-1));
float min_theta = (float)std::asin(sin_theta(0, 0)), max_theta = (float)std::asin(sin_theta(0, cols_ - 1));
float min_phi = (float)std::asin(sin_phi(0, cols_/2-1)), max_phi = (float) std::asin(sin_phi(rows_ - 1, cols_/2-1));
std::vector<cv::Point3f> points3d(cols_ * rows_);
R_hat_.create(rows_, cols_);
@ -566,11 +573,11 @@ namespace
//map for converting from Spherical coordinate space to Euclidean space
euclideanMap_.create(rows_,cols_);
float invFx = 1.0f/K_.at<T>(0,0), cx = K_.at<T>(0,2);
float invFx = (float)(1.0f/K_.at<T>(0,0)), cx = (float)K_.at<T>(0,2);
double invFy = 1.0f/K_.at<T>(1,1), cy = K_.at<T>(1,2);
for (int i = 0; i < rows_; i++)
{
float y = (i - cy)*invFy;
float y = (float)((i - cy)*invFy);
for (int j = 0; j < cols_; j++)
{
float x = (j - cx)*invFx;

@ -147,7 +147,7 @@ void preparePyramidImage(const Mat& image, std::vector<Mat>& pyramidImage, size_
CV_Assert(pyramidImage[i].type() == image.type());
}
else
buildPyramid(image, pyramidImage, levelCount - 1);
buildPyramid(image, pyramidImage, (int)levelCount - 1);
}
static
@ -163,7 +163,7 @@ void preparePyramidDepth(const Mat& depth, std::vector<Mat>& pyramidDepth, size_
CV_Assert(pyramidDepth[i].type() == depth.type());
}
else
buildPyramid(depth, pyramidDepth, levelCount - 1);
buildPyramid(depth, pyramidDepth, (int)levelCount - 1);
}
static
@ -192,7 +192,7 @@ void preparePyramidMask(const Mat& mask, const std::vector<Mat>& pyramidDepth, f
else
validMask = mask.clone();
buildPyramid(validMask, pyramidMask, pyramidDepth.size() - 1);
buildPyramid(validMask, pyramidMask, (int)pyramidDepth.size() - 1);
for(size_t i = 0; i < pyramidMask.size(); i++)
{
@ -238,7 +238,7 @@ void preparePyramidCloud(const std::vector<Mat>& pyramidDepth, const Mat& camera
else
{
std::vector<Mat> pyramidCameraMatrix;
buildPyramidCameraMatrix(cameraMatrix, pyramidDepth.size(), pyramidCameraMatrix);
buildPyramidCameraMatrix(cameraMatrix, (int)pyramidDepth.size(), pyramidCameraMatrix);
pyramidCloud.resize(pyramidDepth.size());
for(size_t i = 0; i < pyramidDepth.size(); i++)
@ -319,7 +319,7 @@ void preparePyramidTexturedMask(const std::vector<Mat>& pyramid_dI_dx, const std
}
else
{
const float sobelScale2_inv = 1.f / (sobelScale * sobelScale);
const float sobelScale2_inv = 1.f / (float)(sobelScale * sobelScale);
pyramidTexturedMask.resize(pyramid_dI_dx.size());
for(size_t i = 0; i < pyramidTexturedMask.size(); i++)
{
@ -343,7 +343,7 @@ void preparePyramidTexturedMask(const std::vector<Mat>& pyramid_dI_dx, const std
}
pyramidTexturedMask[i] = texturedMask & pyramidMask[i];
randomSubsetOfMask(pyramidTexturedMask[i], maxPointsPart);
randomSubsetOfMask(pyramidTexturedMask[i], (float)maxPointsPart);
}
}
}
@ -364,7 +364,7 @@ void preparePyramidNormals(const Mat& normals, const std::vector<Mat>& pyramidDe
}
else
{
buildPyramid(normals, pyramidNormals, pyramidDepth.size() - 1);
buildPyramid(normals, pyramidNormals, (int)pyramidDepth.size() - 1);
// renormalize normals
for(size_t i = 1; i < pyramidNormals.size(); i++)
{
@ -419,7 +419,7 @@ void preparePyramidNormalsMask(const std::vector<Mat>& pyramidNormals, const std
}
}
}
randomSubsetOfMask(normalsMask, maxPointsPart);
randomSubsetOfMask(normalsMask, (float)maxPointsPart);
}
}
}
@ -488,16 +488,16 @@ void computeCorresps(const Mat& K, const Mat& K_inv, const Mat& Rt,
const double * KRK_inv_ptr = KRK_inv.ptr<const double>();
for(int u1 = 0; u1 < depth1.cols; u1++)
{
KRK_inv0_u1[u1] = KRK_inv_ptr[0] * u1;
KRK_inv3_u1[u1] = KRK_inv_ptr[3] * u1;
KRK_inv6_u1[u1] = KRK_inv_ptr[6] * u1;
KRK_inv0_u1[u1] = (float)(KRK_inv_ptr[0] * u1);
KRK_inv3_u1[u1] = (float)(KRK_inv_ptr[3] * u1);
KRK_inv6_u1[u1] = (float)(KRK_inv_ptr[6] * u1);
}
for(int v1 = 0; v1 < depth1.rows; v1++)
{
KRK_inv1_v1_plus_KRK_inv2[v1] = KRK_inv_ptr[1] * v1 + KRK_inv_ptr[2];
KRK_inv4_v1_plus_KRK_inv5[v1] = KRK_inv_ptr[4] * v1 + KRK_inv_ptr[5];
KRK_inv7_v1_plus_KRK_inv8[v1] = KRK_inv_ptr[7] * v1 + KRK_inv_ptr[8];
KRK_inv1_v1_plus_KRK_inv2[v1] = (float)(KRK_inv_ptr[1] * v1 + KRK_inv_ptr[2]);
KRK_inv4_v1_plus_KRK_inv5[v1] = (float)(KRK_inv_ptr[4] * v1 + KRK_inv_ptr[5]);
KRK_inv7_v1_plus_KRK_inv8[v1] = (float)(KRK_inv_ptr[7] * v1 + KRK_inv_ptr[8]);
}
}
@ -542,7 +542,7 @@ void computeCorresps(const Mat& K, const Mat& K_inv, const Mat& Rt,
else
correspCount++;
c = Vec2s(u1,v1);
c = Vec2s((short)u1, (short)v1);
}
}
}
@ -686,9 +686,9 @@ void calcRgbdLsmMatrices(const Mat& image0, const Mat& cloud0, const Mat& Rt,
const Point3f& p0 = cloud0.at<Point3f>(v0,u0);
Point3f tp0;
tp0.x = p0.x * Rt_ptr[0] + p0.y * Rt_ptr[1] + p0.z * Rt_ptr[2] + Rt_ptr[3];
tp0.y = p0.x * Rt_ptr[4] + p0.y * Rt_ptr[5] + p0.z * Rt_ptr[6] + Rt_ptr[7];
tp0.z = p0.x * Rt_ptr[8] + p0.y * Rt_ptr[9] + p0.z * Rt_ptr[10] + Rt_ptr[11];
tp0.x = (float)(p0.x * Rt_ptr[0] + p0.y * Rt_ptr[1] + p0.z * Rt_ptr[2] + Rt_ptr[3]);
tp0.y = (float)(p0.x * Rt_ptr[4] + p0.y * Rt_ptr[5] + p0.z * Rt_ptr[6] + Rt_ptr[7]);
tp0.z = (float)(p0.x * Rt_ptr[8] + p0.y * Rt_ptr[9] + p0.z * Rt_ptr[10] + Rt_ptr[11]);
func(A_ptr,
w_sobelScale * dI_dx1.at<short int>(v1,u1),
@ -742,9 +742,9 @@ void calcICPLsmMatrices(const Mat& cloud0, const Mat& Rt,
const Point3f& p0 = cloud0.at<Point3f>(v0,u0);
Point3f tp0;
tp0.x = p0.x * Rt_ptr[0] + p0.y * Rt_ptr[1] + p0.z * Rt_ptr[2] + Rt_ptr[3];
tp0.y = p0.x * Rt_ptr[4] + p0.y * Rt_ptr[5] + p0.z * Rt_ptr[6] + Rt_ptr[7];
tp0.z = p0.x * Rt_ptr[8] + p0.y * Rt_ptr[9] + p0.z * Rt_ptr[10] + Rt_ptr[11];
tp0.x = (float)(p0.x * Rt_ptr[0] + p0.y * Rt_ptr[1] + p0.z * Rt_ptr[2] + Rt_ptr[3]);
tp0.y = (float)(p0.x * Rt_ptr[4] + p0.y * Rt_ptr[5] + p0.z * Rt_ptr[6] + Rt_ptr[7]);
tp0.z = (float)(p0.x * Rt_ptr[8] + p0.y * Rt_ptr[9] + p0.z * Rt_ptr[10] + Rt_ptr[11]);
Vec3f n1 = normals1.at<Vec3f>(v1, u1);
Point3f v = cloud1.at<Point3f>(v1,u1) - tp0;
@ -846,13 +846,13 @@ bool RGBDICPOdometryImpl(Mat& Rt, const Mat& initRt,
const int minCorrespsCount = minOverdetermScale * transformDim;
std::vector<Mat> pyramidCameraMatrix;
buildPyramidCameraMatrix(cameraMatrix, iterCounts.size(), pyramidCameraMatrix);
buildPyramidCameraMatrix(cameraMatrix, (int)iterCounts.size(), pyramidCameraMatrix);
Mat resultRt = initRt.empty() ? Mat::eye(4,4,CV_64FC1) : initRt.clone();
Mat currRt, ksi;
bool isOk = false;
for(int level = iterCounts.size() - 1; level >= 0; level--)
for(int level = (int)iterCounts.size() - 1; level >= 0; level--)
{
const Mat& levelCameraMatrix = pyramidCameraMatrix[level];
const Mat& levelCameraMatrix_inv = levelCameraMatrix.inv(DECOMP_SVD);
@ -1150,7 +1150,7 @@ Size RgbdOdometry::prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) c
preparePyramidDepth(frame->depth, frame->pyramidDepth, iterCounts.total());
preparePyramidMask(frame->mask, frame->pyramidDepth, minDepth, maxDepth,
preparePyramidMask(frame->mask, frame->pyramidDepth, (float)minDepth, (float)maxDepth,
frame->pyramidNormals, frame->pyramidMask);
if(cacheType & OdometryFrame::CACHE_SRC)
@ -1176,7 +1176,7 @@ void RgbdOdometry::checkParams() const
bool RgbdOdometry::computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt, const Mat& initRt) const
{
return RGBDICPOdometryImpl(Rt, initRt, srcFrame, dstFrame, cameraMatrix, maxDepthDiff, iterCounts, maxTranslation, maxRotation, RGBD_ODOMETRY, transformType);
return RGBDICPOdometryImpl(Rt, initRt, srcFrame, dstFrame, cameraMatrix, (float)maxDepthDiff, iterCounts, maxTranslation, maxRotation, RGBD_ODOMETRY, transformType);
}
//
@ -1250,13 +1250,13 @@ Size ICPOdometry::prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) co
preparePyramidNormals(frame->normals, frame->pyramidDepth, frame->pyramidNormals);
preparePyramidMask(frame->mask, frame->pyramidDepth, minDepth, maxDepth,
preparePyramidMask(frame->mask, frame->pyramidDepth, (float)minDepth, (float)maxDepth,
frame->pyramidNormals, frame->pyramidMask);
preparePyramidNormalsMask(frame->pyramidNormals, frame->pyramidMask, maxPointsPart, frame->pyramidNormalsMask);
}
else
preparePyramidMask(frame->mask, frame->pyramidDepth, minDepth, maxDepth,
preparePyramidMask(frame->mask, frame->pyramidDepth, (float)minDepth, (float)maxDepth,
frame->pyramidNormals, frame->pyramidMask);
return frame->depth.size();
@ -1270,7 +1270,7 @@ void ICPOdometry::checkParams() const
bool ICPOdometry::computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt, const Mat& initRt) const
{
return RGBDICPOdometryImpl(Rt, initRt, srcFrame, dstFrame, cameraMatrix, maxDepthDiff, iterCounts, maxTranslation, maxRotation, ICP_ODOMETRY, transformType);
return RGBDICPOdometryImpl(Rt, initRt, srcFrame, dstFrame, cameraMatrix, (float)maxDepthDiff, iterCounts, maxTranslation, maxRotation, ICP_ODOMETRY, transformType);
}
//
@ -1359,7 +1359,7 @@ Size RgbdICPOdometry::prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType
preparePyramidNormals(frame->normals, frame->pyramidDepth, frame->pyramidNormals);
preparePyramidMask(frame->mask, frame->pyramidDepth, minDepth, maxDepth,
preparePyramidMask(frame->mask, frame->pyramidDepth, (float)minDepth, (float)maxDepth,
frame->pyramidNormals, frame->pyramidMask);
preparePyramidSobel(frame->pyramidImage, 1, 0, frame->pyramid_dI_dx);
@ -1371,7 +1371,7 @@ Size RgbdICPOdometry::prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType
preparePyramidNormalsMask(frame->pyramidNormals, frame->pyramidMask, maxPointsPart, frame->pyramidNormalsMask);
}
else
preparePyramidMask(frame->mask, frame->pyramidDepth, minDepth, maxDepth,
preparePyramidMask(frame->mask, frame->pyramidDepth, (float)minDepth, (float)maxDepth,
frame->pyramidNormals, frame->pyramidMask);
return frame->image.size();
@ -1386,7 +1386,7 @@ void RgbdICPOdometry::checkParams() const
bool RgbdICPOdometry::computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt, const Mat& initRt) const
{
return RGBDICPOdometryImpl(Rt, initRt, srcFrame, dstFrame, cameraMatrix, maxDepthDiff, iterCounts, maxTranslation, maxRotation, MERGED_ODOMETRY, transformType);
return RGBDICPOdometryImpl(Rt, initRt, srcFrame, dstFrame, cameraMatrix, (float)maxDepthDiff, iterCounts, maxTranslation, maxRotation, MERGED_ODOMETRY, transformType);
}
//

@ -523,6 +523,8 @@ private:
unsigned char plane_index_;
/** THe block size as defined in the main algorithm */
int block_size_;
const InlierFinder & operator = (const InlierFinder &);
}
;
@ -563,7 +565,7 @@ namespace cv
size_t index_plane = 0;
std::vector<cv::Vec4f> plane_coefficients;
float mse_min = threshold_ * threshold_;
float mse_min = (float)(threshold_ * threshold_);
while (!plane_queue.empty())
{
@ -572,16 +574,17 @@ namespace cv
if (front_tile.mse_ > mse_min)
break;
InlierFinder inlier_finder(threshold_, points3d, normals, index_plane, block_size_);
InlierFinder inlier_finder((float)threshold_, points3d, normals, (unsigned char)index_plane, block_size_);
// Construct the plane for the first tile
int x = front_tile.x_, y = front_tile.y_;
const cv::Vec3f & n = plane_grid.n_(y, x);
cv::Ptr<PlaneBase> plane;
if ((sensor_error_a_ == 0) && (sensor_error_b_ == 0) && (sensor_error_c_ == 0))
plane = cv::Ptr<PlaneBase>(new Plane(plane_grid.m_(y, x), n, index_plane));
plane = cv::Ptr<PlaneBase>(new Plane(plane_grid.m_(y, x), n, (int)index_plane));
else
plane = cv::Ptr<PlaneBase>(new PlaneABC(plane_grid.m_(y, x), n, index_plane, sensor_error_a_, sensor_error_b_, sensor_error_c_));
plane = cv::Ptr<PlaneBase>(new PlaneABC(plane_grid.m_(y, x), n, (int)index_plane,
(float)sensor_error_a_, (float)sensor_error_b_, (float)sensor_error_c_));
cv::Mat_<unsigned char> plane_mask = cv::Mat_<unsigned char>::zeros(points3d.rows / block_size_,
points3d.cols / block_size_);
@ -631,7 +634,7 @@ namespace cv
// Fill the plane coefficients
if (plane_coefficients.empty())
return;
plane_coefficients_out.create(plane_coefficients.size(), 1, CV_32FC4);
plane_coefficients_out.create((int)plane_coefficients.size(), 1, CV_32FC4);
cv::Mat plane_coefficients_mat = plane_coefficients_out.getMat();
float* data = plane_coefficients_mat.ptr<float>(0);
for(size_t i=0; i<plane_coefficients.size(); ++i)

@ -84,7 +84,7 @@ namespace cv
obj.info()->addParam(obj, "transformType", obj.transformType);
obj.info()->addParam(obj, "maxTranslation", obj.maxTranslation);
obj.info()->addParam(obj, "maxRotation", obj.maxRotation);
obj.info()->addParam(obj, "normalsComputer", obj.normalsComputer, true);)
obj.info()->addParam<cv::RgbdNormals>(obj, "normalsComputer", obj.normalsComputer, true, NULL, NULL);)
CV_INIT_ALGORITHM(RgbdICPOdometry, "RGBD.RgbdICPOdometry",
obj.info()->addParam(obj, "cameraMatrix", obj.cameraMatrix);
@ -97,7 +97,7 @@ namespace cv
obj.info()->addParam(obj, "transformType", obj.transformType);
obj.info()->addParam(obj, "maxTranslation", obj.maxTranslation);
obj.info()->addParam(obj, "maxRotation", obj.maxRotation);
obj.info()->addParam(obj, "normalsComputer", obj.normalsComputer, true);)
obj.info()->addParam<cv::RgbdNormals>(obj, "normalsComputer", obj.normalsComputer, true, NULL, NULL);)
bool
initModule_rgbd(void);

@ -62,13 +62,13 @@ namespace cv
if (in_depth == CV_16U)
{
in.convertTo(out, depth, 1 / 1000.0); //convert to float so that it is in meters
cv::Mat valid_mask = in == std::numeric_limits<uint16_t>::min(); // Should we do std::numeric_limits<uint16_t>::max() too ?
cv::Mat valid_mask = in == std::numeric_limits<ushort>::min(); // Should we do std::numeric_limits<ushort>::max() too ?
out.setTo(std::numeric_limits<float>::quiet_NaN(), valid_mask); //set a$
}
if (in_depth == CV_16S)
{
in.convertTo(out, depth, 1 / 1000.0); //convert to float so tha$
cv::Mat valid_mask = (in == std::numeric_limits<int16_t>::min()) | (in == std::numeric_limits<int16_t>::max()); // Should we do std::numeric_limits<uint16_t>::max() too ?
cv::Mat valid_mask = (in == std::numeric_limits<short>::min()) | (in == std::numeric_limits<short>::max()); // Should we do std::numeric_limits<ushort>::max() too ?
out.setTo(std::numeric_limits<float>::quiet_NaN(), valid_mask); //set a$
}
if ((in_depth == CV_32F) || (in_depth == CV_64F))

@ -65,7 +65,7 @@ rayPlaneIntersection(const cv::Vec3d& uv1, double centroid_dot_normal, const cv:
std::cout << "warning, LdotNormal nearly 0! " << LdotNormal << std::endl;
std::cout << "contents of L, Normal: " << cv::Mat(L) << ", " << cv::Mat(normal) << std::endl;
}
cv::Vec3f xyz(d * L(0), d * L(1), d * L(2));
cv::Vec3f xyz((float)(d * L(0)), (float)(d * L(1)), (float)(d * L(2)));
return xyz;
}
@ -99,7 +99,7 @@ struct Plane
n[1] = rng.uniform(-0.5, 0.5);
n[2] = -0.3; //rng.uniform(-1.f, 0.5f);
n = n / cv::norm(n);
set_d(rng.uniform(-2.0, 0.6));
set_d((float)rng.uniform(-2.0, 0.6));
}
void
@ -146,11 +146,11 @@ gen_points_3d(std::vector<Plane>& planes_out, cv::Mat_<unsigned char> &plane_mas
{
for (int u = 0; u < W; u++)
{
unsigned int plane_index = (u / float(W)) * planes.size();
unsigned int plane_index = (unsigned int)((u / float(W)) * planes.size());
Plane plane = planes[plane_index];
outp(v, u) = plane.intersection(u, v, Kinv);
outp(v, u) = plane.intersection((float)u, (float)v, Kinv);
outn(v, u) = plane.n;
plane_mask(v, u) = plane_index;
plane_mask(v, u) = (uchar)plane_index;
}
}
planes_out = planes;
@ -189,27 +189,30 @@ protected:
case 0:
method = cv::RgbdNormals::RGBD_NORMALS_METHOD_FALS;
std::cout << std::endl << "*** FALS" << std::endl;
errors[0][0] = 0.006;
errors[0][1] = 0.03;
errors[1][0] = 0.00008;
errors[1][1] = 0.02;
errors[0][0] = 0.006f;
errors[0][1] = 0.03f;
errors[1][0] = 0.00008f;
errors[1][1] = 0.02f;
break;
case 1:
method = cv::RgbdNormals::RGBD_NORMALS_METHOD_LINEMOD;
std::cout << std::endl << "*** LINEMOD" << std::endl;
errors[0][0] = 0.04;
errors[0][1] = 0.07;
errors[1][0] = 0.05;
errors[1][1] = 0.08;
errors[0][0] = 0.04f;
errors[0][1] = 0.07f;
errors[1][0] = 0.05f;
errors[1][1] = 0.08f;
break;
case 2:
method = cv::RgbdNormals::RGBD_NORMALS_METHOD_SRI;
std::cout << std::endl << "*** SRI" << std::endl;
errors[0][0] = 0.02;
errors[0][1] = 0.04;
errors[1][0] = 0.02;
errors[1][1] = 0.04;
errors[0][0] = 0.02f;
errors[0][1] = 0.04f;
errors[1][0] = 0.02f;
errors[1][1] = 0.04f;
break;
default:
method = (cv::RgbdNormals::RGBD_NORMALS_METHOD)-1;
CV_Error(0, "");
}
for (unsigned char j = 0; j < 2; ++j)
@ -366,15 +369,15 @@ protected:
}
// Compare each found plane to each ground truth plane
size_t n_planes = plane_coefficients.size();
size_t n_gt_planes = gt_planes.size();
int n_planes = (int)plane_coefficients.size();
int n_gt_planes = (int)gt_planes.size();
cv::Mat_<int> matching(n_gt_planes, n_planes);
for (size_t j = 0; j < n_gt_planes; ++j)
for (int j = 0; j < n_gt_planes; ++j)
{
cv::Mat gt_mask = gt_plane_mask == j;
int n_gt = cv::countNonZero(gt_mask);
int n_max = 0, i_max = 0;
for (size_t i = 0; i < n_planes; ++i)
for (int i = 0; i < n_planes; ++i)
{
cv::Mat dst;
cv::bitwise_and(gt_mask, plane_mask == i, dst);

@ -192,7 +192,7 @@ bool CV_OdometryTest::readData(Mat& image, Mat& depth) const
return false;
}
CV_DbgAssert(gray.type() == CV_8UC1);
CV_DbgAssert(image.type() == CV_8UC1);
CV_DbgAssert(depth.type() == CV_16UC1);
{
Mat depth_flt;
@ -206,7 +206,7 @@ bool CV_OdometryTest::readData(Mat& image, Mat& depth) const
void CV_OdometryTest::generateRandomTransformation(Mat& rvec, Mat& tvec)
{
const float maxRotation = 3.f / 180.f * CV_PI; //rad
const float maxRotation = (float)(3.f / 180.f * CV_PI); //rad
const float maxTranslation = 0.02f; //m
RNG& rng = theRNG();

@ -42,7 +42,7 @@ protected:
float avg_diff = 0;
for (int y = 0; y < rows; ++y)
for (int x = 0; x < cols; ++x)
avg_diff += cv::norm(image_points.at<cv::Vec2f>(y,x) - cv::Vec2f(x,y));
avg_diff += (float)cv::norm(image_points.at<cv::Vec2f>(y,x) - cv::Vec2f((float)x,(float)y));
// Verify the function works
ASSERT_LE(avg_diff/rows/cols, 1e-4) << "Average error for ground truth is: " << (avg_diff / rows / cols);

@ -124,12 +124,12 @@ void getSegment( int segmentId, int numSegments, int bbCounter, int& startFrame,
void getMatOfRects( const vector<Rect>& bbs, Mat& bbs_mat )
{
for ( size_t b = 0; b < bbs.size(); b++ )
for ( int b = 0, size = (int)bbs.size(); b < size; b++ )
{
bbs_mat.at<float>( b, 0 ) = bbs[b].x;
bbs_mat.at<float>( b, 1 ) = bbs[b].y;
bbs_mat.at<float>( b, 2 ) = bbs[b].width;
bbs_mat.at<float>( b, 3 ) = bbs[b].height;
bbs_mat.at<float>( b, 0 ) = (float)bbs[b].x;
bbs_mat.at<float>( b, 1 ) = (float)bbs[b].y;
bbs_mat.at<float>( b, 2 ) = (float)bbs[b].width;
bbs_mat.at<float>( b, 3 ) = (float)bbs[b].height;
}
}
@ -149,7 +149,7 @@ PERF_TEST_P(tracking, mil, testing::Combine(TESTSET_NAMES, SEGMENTS))
string gtFile = getDataPath( TRACKING_DIR + "/" + video + "/gt.txt" );
if( !getGroundTruth( gtFile, gtBBs ) )
FAIL()<< "Ground truth file " << gtFile << " can not be read" << endl;
int bbCounter = gtBBs.size();
int bbCounter = (int)gtBBs.size();
Mat frame;
bool initialized = false;
@ -197,7 +197,7 @@ PERF_TEST_P(tracking, mil, testing::Combine(TESTSET_NAMES, SEGMENTS))
}
}
//save the bounding boxes in a Mat
Mat bbs_mat( bbs.size(), 4, CV_32F );
Mat bbs_mat( (int)bbs.size(), 4, CV_32F );
getMatOfRects( bbs, bbs_mat );
SANITY_CHECK( bbs_mat, 15, ERROR_RELATIVE );
@ -220,7 +220,7 @@ PERF_TEST_P(tracking, boosting, testing::Combine(TESTSET_NAMES, SEGMENTS))
string gtFile = getDataPath( TRACKING_DIR + "/" + video + "/gt.txt" );
if( !getGroundTruth( gtFile, gtBBs ) )
FAIL()<< "Ground truth file " << gtFile << " can not be read" << endl;
int bbCounter = gtBBs.size();
int bbCounter = (int)gtBBs.size();
Mat frame;
bool initialized = false;
@ -267,7 +267,7 @@ PERF_TEST_P(tracking, boosting, testing::Combine(TESTSET_NAMES, SEGMENTS))
}
}
//save the bounding boxes in a Mat
Mat bbs_mat( bbs.size(), 4, CV_32F );
Mat bbs_mat( (int)bbs.size(), 4, CV_32F );
getMatOfRects( bbs, bbs_mat );
SANITY_CHECK( bbs_mat, 15, ERROR_RELATIVE );

@ -58,7 +58,7 @@ static void onMouse( int event, int x, int y, int, void* )
//draw the bounding box
Mat currentFrame;
image.copyTo( currentFrame );
rectangle( currentFrame, Point( boundingBox.x, boundingBox.y ), Point( x, y ), Scalar( 255, 0, 0 ), 2, 1 );
rectangle( currentFrame, Point( (int)boundingBox.x, (int)boundingBox.y ), Point( x, y ), Scalar( 255, 0, 0 ), 2, 1 );
imshow( "Tracking API", currentFrame );
}
break;
@ -82,18 +82,23 @@ int main( int argc, char** argv )
int coords[4]={0,0,0,0};
bool initFrameWasGivenInCommandLine=false;
do{
do
{
String initBoundingBox=parser.get<String>(3);
for(size_t pos=0,ctr=0;ctr<4;ctr++){
for(size_t pos=0,ctr=0;ctr<4;ctr++)
{
size_t npos=initBoundingBox.find_first_of(',',pos);
if(npos==string::npos && ctr<3){
if(npos==string::npos && ctr<3)
{
printf("bounding box should be given in format \"x1,y1,x2,y2\",where x's and y's are integer cordinates of opposed corners of bdd box\n");
printf("got: %s\n",initBoundingBox.substr(pos,string::npos).c_str());
printf("manual selection of bounding box will be employed\n");
break;
}
int num=atoi(initBoundingBox.substr(pos,(ctr==3)?(string::npos):(npos-pos)).c_str());
if(num<=0){
if(num<=0)
{
printf("bounding box should be given in format \"x1,y1,x2,y2\",where x's and y's are integer cordinates of opposed corners of bdd box\n");
printf("got: %s\n",initBoundingBox.substr(pos,npos-pos).c_str());
printf("manual selection of bounding box will be employed\n");
@ -102,10 +107,9 @@ int main( int argc, char** argv )
coords[ctr]=num;
pos=npos+1;
}
if(coords[0]>0 && coords[1]>0 && coords[2]>0 && coords[3]>0){
if(coords[0]>0 && coords[1]>0 && coords[2]>0 && coords[3]>0)
initFrameWasGivenInCommandLine=true;
}
}while(0);
} while((void)0, 0);
//open the capture
VideoCapture cap;

@ -106,7 +106,7 @@ namespace cv{
//Mat_<double> maxrow=_particles.row(std::max_element(_logweight.begin(),_logweight.end())-_logweight.begin());
double max_element;
minMaxLoc(_logweight, 0, &max_element);
Mat_<double> maxrow=_particles.row(max_element);
Mat_<double> maxrow=_particles.row((int)max_element);
for(;num_particles<new_particles.rows;num_particles++){
maxrow.copyTo(new_particles.row(num_particles));
}
@ -136,7 +136,7 @@ namespace cv{
}
_logweight.create(1,_particles.rows);
_logweight.setTo(-log(_particles.rows));
_logweight.setTo(-log((double)_particles.rows));
return 0.0;
}

@ -23,6 +23,8 @@ namespace cv{
Mat_<double> HShist, Vhist;
};
TrackingHistogram _origHist;
const TrackingFunctionPF & operator = (const TrackingFunctionPF &);
};
TrackingFunctionPF::TrackingHistogram::TrackingHistogram(const Mat& img,int nh,int ns,int nv){

@ -686,7 +686,7 @@ void CvHaarEvaluator::FeatureHaar::generateRandomFeature( Size patchSize )
valid = true;
}
else
CV_Assert( false );
CV_Error(CV_StsAssert, "");
}
m_initSize = patchSize;
@ -742,14 +742,14 @@ float CvHaarEvaluator::FeatureHaar::getSum( const Mat& image, Rect imageROI ) co
int depth = image.depth();
if( depth == CV_8U || depth == CV_32S )
value = image.at<int>( OriginY + Height, OriginX + Width ) + image.at<int>( OriginY, OriginX ) - image.at<int>( OriginY, OriginX + Width )
- image.at<int>( OriginY + Height, OriginX );
value = static_cast<float>(image.at<int>( OriginY + Height, OriginX + Width ) + image.at<int>( OriginY, OriginX ) - image.at<int>( OriginY, OriginX + Width )
- image.at<int>( OriginY + Height, OriginX ));
else if( depth == CV_64F )
value = image.at<double>( OriginY + Height, OriginX + Width ) + image.at<double>( OriginY, OriginX )
- image.at<double>( OriginY, OriginX + Width ) - image.at<double>( OriginY + Height, OriginX );
value = static_cast<float>(image.at<double>( OriginY + Height, OriginX + Width ) + image.at<double>( OriginY, OriginX )
- image.at<double>( OriginY, OriginX + Width ) - image.at<double>( OriginY + Height, OriginX ));
else if( depth == CV_32F )
value = image.at<float>( OriginY + Height, OriginX + Width ) + image.at<float>( OriginY, OriginX ) - image.at<float>( OriginY, OriginX + Width )
- image.at<float>( OriginY + Height, OriginX );
value = static_cast<float>(image.at<float>( OriginY + Height, OriginX + Width ) + image.at<float>( OriginY, OriginX ) - image.at<float>( OriginY, OriginX + Width )
- image.at<float>( OriginY + Height, OriginX ));
return value;
}

@ -132,9 +132,9 @@ int StrongClassifierDirectSelection::getSwappedClassifier() const
bool StrongClassifierDirectSelection::update( const Mat& image, int target, float importance )
{
m_errorMask.assign( numAllWeakClassifier, 0 );
m_errors.assign( numAllWeakClassifier, 0 );
m_sumErrors.assign( numAllWeakClassifier, 0 );
m_errorMask.assign( (size_t)numAllWeakClassifier, false );
m_errors.assign( (size_t)numAllWeakClassifier, 0.0f );
m_sumErrors.assign( (size_t)numAllWeakClassifier, 0.0f );
baseClassifier[0]->trainClassifier( image, target, importance, m_errorMask );
for ( int curBaseClassifier = 0; curBaseClassifier < numBaseClassifier; curBaseClassifier++ )
@ -287,7 +287,7 @@ void BaseClassifier::trainClassifier( const Mat& image, int target, float import
double A = 1;
int K = 0;
int K_max = 10;
while ( 1 )
for ( ; ; )
{
double U_k = (double) rand() / RAND_MAX;
A *= U_k;
@ -572,7 +572,7 @@ void Detector::prepareDetectionsMemory( int numDetections )
void Detector::classifySmooth( const std::vector<Mat>& images, float minMargin )
{
int numPatches = images.size();
int numPatches = static_cast<int>(images.size());
prepareConfidencesMemory( numPatches );

@ -99,7 +99,7 @@ ClfMilBoost::Params::Params()
{
_numSel = 50;
_numFeat = 250;
_lRate = 0.85;
_lRate = 0.85f;
}
ClfMilBoost::ClfMilBoost()

@ -56,7 +56,7 @@ TrackerBoosting::Params::Params()
{
numClassifiers = 100;
samplerOverlap = 0.99f;
samplerSearchFactor = 1.8;
samplerSearchFactor = 1.8f;
iterationInit = 50;
featureSetNumFeatures = ( numClassifiers * 10 ) + iterationInit;
}
@ -141,7 +141,7 @@ bool TrackerBoosting::initImpl( const Mat& image, const Rect2d& boundingBox )
TrackerFeatureHAAR::Params HAARparameters;
HAARparameters.numFeatures = params.featureSetNumFeatures;
HAARparameters.isIntegral = true;
HAARparameters.rectSize = Size( boundingBox.width, boundingBox.height );
HAARparameters.rectSize = Size( static_cast<int>(boundingBox.width), static_cast<int>(boundingBox.height) );
Ptr<TrackerFeature> trackerFeature = Ptr<TrackerFeatureHAAR>( new TrackerFeatureHAAR( HAARparameters ) );
if( !featureSet->addTrackerFeature( trackerFeature ) )
return false;
@ -155,7 +155,7 @@ bool TrackerBoosting::initImpl( const Mat& image, const Rect2d& boundingBox )
model = Ptr<TrackerBoostingModel>( new TrackerBoostingModel( boundingBox ) );
Ptr<TrackerStateEstimatorAdaBoosting> stateEstimator = Ptr<TrackerStateEstimatorAdaBoosting>(
new TrackerStateEstimatorAdaBoosting( params.numClassifiers, params.iterationInit, params.featureSetNumFeatures,
Size( boundingBox.width, boundingBox.height ), ROI ) );
Size( static_cast<int>(boundingBox.width), static_cast<int>(boundingBox.height) ), ROI ) );
model->setTrackerStateEstimator( stateEstimator );
//Run model estimation and update for iterationInit iterations
@ -163,9 +163,9 @@ bool TrackerBoosting::initImpl( const Mat& image, const Rect2d& boundingBox )
{
//compute temp features
TrackerFeatureHAAR::Params HAARparameters2;
HAARparameters2.numFeatures = ( posSamples.size() + negSamples.size() );
HAARparameters2.numFeatures = static_cast<int>( posSamples.size() + negSamples.size() );
HAARparameters2.isIntegral = true;
HAARparameters2.rectSize = Size( boundingBox.width, boundingBox.height );
HAARparameters2.rectSize = Size( static_cast<int>(boundingBox.width), static_cast<int>(boundingBox.height) );
Ptr<TrackerFeatureHAAR> trackerFeature2 = Ptr<TrackerFeatureHAAR>( new TrackerFeatureHAAR( HAARparameters2 ) );
model.staticCast<TrackerBoostingModel>()->setMode( TrackerBoostingModel::MODE_NEGATIVE, negSamples );
@ -182,7 +182,7 @@ bool TrackerBoosting::initImpl( const Mat& image, const Rect2d& boundingBox )
if( replacedClassifier[j] != -1 && swappedClassified[j] != -1 )
{
trackerFeature.staticCast<TrackerFeatureHAAR>()->swapFeature( replacedClassifier[j], swappedClassified[j] );
trackerFeature.staticCast<TrackerFeatureHAAR>()->swapFeature( swappedClassified[j], trackerFeature2->getFeatureAt( j ) );
trackerFeature.staticCast<TrackerFeatureHAAR>()->swapFeature( swappedClassified[j], trackerFeature2->getFeatureAt( (int)j ) );
}
}
}
@ -199,7 +199,7 @@ bool TrackerBoosting::updateImpl( const Mat& image, Rect2d& boundingBox )
integral( image_, intImage, intSqImage, CV_32S );
//get the last location [AAM] X(k-1)
Ptr<TrackerTargetState> lastLocation = model->getLastTargetState();
Rect lastBoundingBox( lastLocation->getTargetPosition().x, lastLocation->getTargetPosition().y, lastLocation->getTargetWidth(),
Rect lastBoundingBox( (int)lastLocation->getTargetPosition().x, (int)lastLocation->getTargetPosition().y, lastLocation->getTargetWidth(),
lastLocation->getTargetHeight() );
//sampling new frame based on last location
@ -244,7 +244,7 @@ bool TrackerBoosting::updateImpl( const Mat& image, Rect2d& boundingBox )
}
Ptr<TrackerTargetState> currentState = model->getLastTargetState();
boundingBox = Rect( currentState->getTargetPosition().x, currentState->getTargetPosition().y, currentState->getTargetWidth(),
boundingBox = Rect( (int)currentState->getTargetPosition().x, (int)currentState->getTargetPosition().y, currentState->getTargetWidth(),
currentState->getTargetHeight() );
/*//TODO debug
@ -276,9 +276,9 @@ bool TrackerBoosting::updateImpl( const Mat& image, Rect2d& boundingBox )
//compute temp features
TrackerFeatureHAAR::Params HAARparameters2;
HAARparameters2.numFeatures = ( posSamples.size() + negSamples.size() );
HAARparameters2.numFeatures = static_cast<int>( posSamples.size() + negSamples.size() );
HAARparameters2.isIntegral = true;
HAARparameters2.rectSize = Size( boundingBox.width, boundingBox.height );
HAARparameters2.rectSize = Size( static_cast<int>(boundingBox.width), static_cast<int>(boundingBox.height) );
Ptr<TrackerFeatureHAAR> trackerFeature2 = Ptr<TrackerFeatureHAAR>( new TrackerFeatureHAAR( HAARparameters2 ) );
//model estimate
@ -299,7 +299,7 @@ bool TrackerBoosting::updateImpl( const Mat& image, Rect2d& boundingBox )
{
featureSet->getTrackerFeature().at( 0 ).second.staticCast<TrackerFeatureHAAR>()->swapFeature( replacedClassifier[j], swappedClassified[j] );
featureSet->getTrackerFeature().at( 0 ).second.staticCast<TrackerFeatureHAAR>()->swapFeature( swappedClassified[j],
trackerFeature2->getFeatureAt( j ) );
trackerFeature2->getFeatureAt( (int)j ) );
}
}

@ -55,7 +55,7 @@ TrackerBoostingModel::TrackerBoostingModel( const Rect& boundingBox )
Ptr<TrackerStateEstimatorAdaBoosting::TrackerAdaBoostingTargetState> initState =
Ptr<TrackerStateEstimatorAdaBoosting::TrackerAdaBoostingTargetState>(
new TrackerStateEstimatorAdaBoosting::TrackerAdaBoostingTargetState( Point2f( boundingBox.x, boundingBox.y ), boundingBox.width,
new TrackerStateEstimatorAdaBoosting::TrackerAdaBoostingTargetState( Point2f( (float)boundingBox.x, (float)boundingBox.y ), boundingBox.width,
boundingBox.height, true, Mat() ) );
trajectory.push_back( initState );
maxCMLength = 10;
@ -98,7 +98,7 @@ void TrackerBoostingModel::responseToConfidenceMap( const std::vector<Mat>& resp
Size currentSize;
Point currentOfs;
currentSample.at( i ).locateROI( currentSize, currentOfs );
bool foreground;
bool foreground = false;
if( mode == MODE_POSITIVE || mode == MODE_CLASSIFY )
{
foreground = true;
@ -107,7 +107,7 @@ void TrackerBoostingModel::responseToConfidenceMap( const std::vector<Mat>& resp
{
foreground = false;
}
const Mat resp = responses[0].col( i );
const Mat resp = responses[0].col( (int)i );
//create the state
Ptr<TrackerStateEstimatorAdaBoosting::TrackerAdaBoostingTargetState> currentState = Ptr<
@ -115,7 +115,7 @@ void TrackerBoostingModel::responseToConfidenceMap( const std::vector<Mat>& resp
new TrackerStateEstimatorAdaBoosting::TrackerAdaBoostingTargetState( currentOfs, currentSample.at( i ).cols, currentSample.at( i ).rows,
foreground, resp ) );
confidenceMap.push_back( std::make_pair( currentState, 0 ) );
confidenceMap.push_back( std::make_pair( currentState, 0.0f ) );
}
}

@ -203,10 +203,10 @@ bool TrackerFeatureHAAR::extractSelected( const std::vector<int> selFeatures, co
}
int numFeatures = featureEvaluator->getNumFeatures();
int numSelFeatures = selFeatures.size();
int numSelFeatures = (int)selFeatures.size();
//response = Mat_<float>( Size( images.size(), numFeatures ) );
response.create( Size( images.size(), numFeatures ), CV_32F );
response.create( Size( (int)images.size(), numFeatures ), CV_32F );
response.setTo( 0 );
//double t = getTickCount();
@ -222,7 +222,7 @@ bool TrackerFeatureHAAR::extractSelected( const std::vector<int> selFeatures, co
CvHaarEvaluator::FeatureHaar& feature = featureEvaluator->getFeatures( selFeatures[j] );
feature.eval( images[i], Rect( 0, 0, c, r ), &res );
//( Mat_<float>( response ) )( j, i ) = res;
response.at<float>( selFeatures[j], i ) = res;
response.at<float>( selFeatures[j], (int)i ) = res;
}
}
//t = ( (double) getTickCount() - t ) / getTickFrequency();
@ -273,11 +273,11 @@ bool TrackerFeatureHAAR::computeImpl( const std::vector<Mat>& images, Mat& respo
int numFeatures = featureEvaluator->getNumFeatures();
response = Mat_<float>( Size( images.size(), numFeatures ) );
response = Mat_<float>( Size( (int)images.size(), numFeatures ) );
std::vector<CvHaarEvaluator::FeatureHaar> f = featureEvaluator->getFeatures();
//for each sample compute #n_feature -> put each feature (n Rect) in response
parallel_for_( Range( 0, images.size() ), Parallel_compute( featureEvaluator, images, response ) );
parallel_for_( Range( 0, (int)images.size() ), Parallel_compute( featureEvaluator, images, response ) );
/*for ( size_t i = 0; i < images.size(); i++ )
{

@ -158,7 +158,7 @@ bool TrackerMIL::initImpl( const Mat& image, const Rect2d& boundingBox )
//compute HAAR features
TrackerFeatureHAAR::Params HAARparameters;
HAARparameters.numFeatures = params.featureSetNumFeatures;
HAARparameters.rectSize = Size( boundingBox.width, boundingBox.height );
HAARparameters.rectSize = Size( (int)boundingBox.width, (int)boundingBox.height );
HAARparameters.isIntegral = true;
Ptr<TrackerFeature> trackerFeature = Ptr<TrackerFeatureHAAR>( new TrackerFeatureHAAR( HAARparameters ) );
featureSet->addTrackerFeature( trackerFeature );
@ -191,7 +191,7 @@ bool TrackerMIL::updateImpl( const Mat& image, Rect2d& boundingBox )
//get the last location [AAM] X(k-1)
Ptr<TrackerTargetState> lastLocation = model->getLastTargetState();
Rect lastBoundingBox( lastLocation->getTargetPosition().x, lastLocation->getTargetPosition().y, lastLocation->getTargetWidth(),
Rect lastBoundingBox( (int)lastLocation->getTargetPosition().x, (int)lastLocation->getTargetPosition().y, lastLocation->getTargetWidth(),
lastLocation->getTargetHeight() );
//sampling new frame based on last location
@ -229,7 +229,7 @@ bool TrackerMIL::updateImpl( const Mat& image, Rect2d& boundingBox )
}
Ptr<TrackerTargetState> currentState = model->getLastTargetState();
boundingBox = Rect( currentState->getTargetPosition().x, currentState->getTargetPosition().y, currentState->getTargetWidth(),
boundingBox = Rect( (int)currentState->getTargetPosition().x, (int)currentState->getTargetPosition().y, currentState->getTargetWidth(),
currentState->getTargetHeight() );
/*//TODO debug

@ -57,7 +57,7 @@ TrackerMILModel::TrackerMILModel( const Rect& boundingBox )
height = boundingBox.height;
Ptr<TrackerStateEstimatorMILBoosting::TrackerMILTargetState> initState = Ptr<TrackerStateEstimatorMILBoosting::TrackerMILTargetState>(
new TrackerStateEstimatorMILBoosting::TrackerMILTargetState( Point2f( boundingBox.x, boundingBox.y ), boundingBox.width, boundingBox.height,
new TrackerStateEstimatorMILBoosting::TrackerMILTargetState( Point2f( (float)boundingBox.x, (float)boundingBox.y ), boundingBox.width, boundingBox.height,
true, Mat() ) );
trajectory.push_back( initState );
}
@ -97,7 +97,7 @@ void TrackerMILModel::responseToConfidenceMap( const std::vector<Mat>& responses
Ptr<TrackerStateEstimatorMILBoosting::TrackerMILTargetState> currentState = Ptr<TrackerStateEstimatorMILBoosting::TrackerMILTargetState>(
new TrackerStateEstimatorMILBoosting::TrackerMILTargetState( currentOfs, width, height, foreground, singleResponse ) );
confidenceMap.push_back( std::make_pair( currentState, 0 ) );
confidenceMap.push_back( std::make_pair( currentState, 0.0f ) );
}

@ -394,7 +394,7 @@ void TrackerStateEstimatorAdaBoosting::updateImpl( std::vector<ConfidenceMap>& c
swappedClassifier[i] = -1;
}
int mapPosition = i + lastConfidenceMap.size() / 2;
int mapPosition = (int)(i + lastConfidenceMap.size() / 2);
Ptr<TrackerAdaBoostingTargetState> currentTargetState2 = lastConfidenceMap.at( mapPosition ).first.staticCast<TrackerAdaBoostingTargetState>();
currentFg = 1;

@ -138,15 +138,15 @@ std::vector<std::string> TrackerOPETest::splitString( std::string s, std::string
float TrackerOPETest::calcDistance( Rect a, Rect b )
{
Point2f p_a( a.x + a.width / 2, a.y + a.height / 2 );
Point2f p_b( b.x + b.width / 2, b.y + b.height / 2 );
Point2f p_a( (float)(a.x + a.width / 2), (float)(a.y + a.height / 2) );
Point2f p_b( (float)(b.x + b.width / 2), (float)(b.y + b.height / 2) );
return sqrt( pow( p_a.x - p_b.x, 2 ) + pow( p_a.y - p_b.y, 2 ) );
}
float TrackerOPETest::calcOverlap( Rect a, Rect b )
{
float aArea = a.width * a.height;
float bArea = b.width * b.height;
float aArea = (float)(a.width * a.height);
float bArea = (float)(b.width * b.height);
if( aArea < bArea )
{
@ -165,8 +165,8 @@ float TrackerOPETest::calcOverlap( Rect a, Rect b )
Rect rectIntersection = a & b;
Rect rectUnion = a | b;
float iArea = rectIntersection.width * rectIntersection.height;
float uArea = rectUnion.width * rectUnion.height;
float iArea = (float)(rectIntersection.width * rectIntersection.height);
float uArea = (float)(rectUnion.width * rectUnion.height);
float overlap = iArea / uArea;
return overlap;
}

@ -142,15 +142,15 @@ std::vector<std::string> TrackerSRETest::splitString( std::string s, std::string
float TrackerSRETest::calcDistance( Rect a, Rect b )
{
Point2f p_a( a.x + a.width / 2, a.y + a.height / 2 );
Point2f p_b( b.x + b.width / 2, b.y + b.height / 2 );
Point2f p_a( (float)(a.x + a.width / 2), (float)(a.y + a.height / 2) );
Point2f p_b( (float)(b.x + b.width / 2), (float)(b.y + b.height / 2) );
return sqrt( pow( p_a.x - p_b.x, 2 ) + pow( p_a.y - p_b.y, 2 ) );
}
float TrackerSRETest::calcOverlap( Rect a, Rect b )
{
float aArea = a.width * a.height;
float bArea = b.width * b.height;
float aArea = (float)(a.width * a.height);
float bArea = (float)(b.width * b.height);
if( aArea < bArea )
{
@ -169,8 +169,8 @@ float TrackerSRETest::calcOverlap( Rect a, Rect b )
Rect rectIntersection = a & b;
Rect rectUnion = a | b;
float iArea = rectIntersection.width * rectIntersection.height;
float uArea = rectUnion.width * rectUnion.height;
float iArea = (float)(rectIntersection.width * rectIntersection.height);
float uArea = (float)(rectUnion.width * rectUnion.height);
float overlap = iArea / uArea;
return overlap;
}
@ -327,81 +327,81 @@ void TrackerSRETest::checkDataTest()
{
case 1:
//center shift left
bb.x = bb.x - ceil( 0.1 * bb.width );
bb.x = bb.x - (int)ceil( 0.1 * bb.width );
break;
case 2:
//center shift right
bb.x = bb.x + ceil( 0.1 * bb.width );
bb.x = bb.x + (int)ceil( 0.1 * bb.width );
break;
case 3:
//center shift up
bb.y = bb.y - ceil( 0.1 * bb.height );
bb.y = bb.y - (int)ceil( 0.1 * bb.height );
break;
case 4:
//center shift down
bb.y = bb.y + ceil( 0.1 * bb.height );
bb.y = bb.y + (int)ceil( 0.1 * bb.height );
break;
case 5:
//corner shift top-left
bb.x = round( bb.x - ( 0.1 * bb.width ) );
bb.y = round( bb.y - ( 0.1 * bb.height ) );
bb.x = (int)round( bb.x - 0.1 * bb.width );
bb.y = (int)round( bb.y - 0.1 * bb.height );
bb.width = xLimit - bb.x + 1;
bb.height = yLimit - bb.y + 1;
break;
case 6:
//corner shift top-right
xLimit = round( xLimit + 0.1 * bb.width );
xLimit = (int)round( xLimit + 0.1 * bb.width );
bb.y = round( bb.y - ( 0.1 * bb.height ) );
bb.y = (int)round( bb.y - 0.1 * bb.height );
bb.width = xLimit - bb.x + 1;
bb.height = yLimit - bb.y + 1;
break;
case 7:
//corner shift bottom-left
bb.x = round( bb.x - ( 0.1 * bb.width ) );
yLimit = round( yLimit + 0.1 * bb.height );
bb.x = (int)round( bb.x - 0.1 * bb.width );
yLimit = (int)round( yLimit + 0.1 * bb.height );
bb.width = xLimit - bb.x + 1;
bb.height = yLimit - bb.y + 1;
break;
case 8:
//corner shift bottom-right
xLimit = round( xLimit + 0.1 * bb.width );
yLimit = round( yLimit + 0.1 * bb.height );
xLimit = (int)round( xLimit + 0.1 * bb.width );
yLimit = (int)round( yLimit + 0.1 * bb.height );
bb.width = xLimit - bb.x + 1;
bb.height = yLimit - bb.y + 1;
break;
case 9:
//scale 0.8
ratio = 0.8;
w = ratio * bb.width;
h = ratio * bb.height;
ratio = 0.8f;
w = (int)(ratio * bb.width);
h = (int)(ratio * bb.height);
bb = Rect( center.x - ( w / 2 ), center.y - ( h / 2 ), w, h );
break;
case 10:
//scale 0.9
ratio = 0.9;
w = ratio * bb.width;
h = ratio * bb.height;
ratio = 0.9f;
w = (int)(ratio * bb.width);
h = (int)(ratio * bb.height);
bb = Rect( center.x - ( w / 2 ), center.y - ( h / 2 ), w, h );
break;
case 11:
//scale 1.1
ratio = 1.1;
w = ratio * bb.width;
h = ratio * bb.height;
ratio = 1.1f;
w = (int)(ratio * bb.width);
h = (int)(ratio * bb.height);
bb = Rect( center.x - ( w / 2 ), center.y - ( h / 2 ), w, h );
break;
case 12:
//scale 1.2
ratio = 1.2;
w = ratio * bb.width;
h = ratio * bb.height;
ratio = 1.2f;
w = (int)(ratio * bb.width);
h = (int)(ratio * bb.height);
bb = Rect( center.x - ( w / 2 ), center.y - ( h / 2 ), w, h );
break;

@ -150,15 +150,15 @@ std::vector<std::string> TrackerTRETest::splitString( std::string s, std::string
float TrackerTRETest::calcDistance( Rect a, Rect b )
{
Point2f p_a( a.x + a.width / 2, a.y + a.height / 2 );
Point2f p_b( b.x + b.width / 2, b.y + b.height / 2 );
Point2f p_a( (float)(a.x + a.width / 2), (float)(a.y + a.height / 2) );
Point2f p_b( (float)(b.x + b.width / 2), (float)(b.y + b.height / 2) );
return sqrt( pow( p_a.x - p_b.x, 2 ) + pow( p_a.y - p_b.y, 2 ) );
}
float TrackerTRETest::calcOverlap( Rect a, Rect b )
{
float aArea = a.width * a.height;
float bArea = b.width * b.height;
float aArea = (float)(a.width * a.height);
float bArea = (float)(b.width * b.height);
if( aArea < bArea )
{
@ -177,8 +177,8 @@ float TrackerTRETest::calcOverlap( Rect a, Rect b )
Rect rectIntersection = a & b;
Rect rectUnion = a | b;
float iArea = rectIntersection.width * rectIntersection.height;
float uArea = rectUnion.width * rectUnion.height;
float iArea = (float)(rectIntersection.width * rectIntersection.height);
float uArea = (float)(rectUnion.width * rectUnion.height);
float overlap = iArea / uArea;
return overlap;
}
@ -361,7 +361,7 @@ void TrackerTRETest::checkDataTest()
gtStartFrame = startFrame;
//compute the start and the and for each segment
int segmentLength = sizeof ( SEGMENTS)/sizeof(int);
int numFrame = validSequence.size() / segmentLength;
int numFrame = (int)(validSequence.size() / segmentLength);
startFrame += ( segmentIdx - 1 ) * numFrame;
endFrame = startFrame + numFrame;
@ -389,8 +389,7 @@ void TrackerTRETest::checkDataTest()
gt2.close();
if( segmentIdx == ( sizeof ( SEGMENTS)/sizeof(int) ) )
endFrame = bbs.size();
endFrame = (int)bbs.size();
}
void TrackerTRETest::run()

@ -0,0 +1,2 @@
set(the_description "Object detection algorithms")
ocv_define_module(xobjdetect opencv_core opencv_imgproc opencv_highgui)

@ -0,0 +1,179 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/
#ifndef __OPENCV_XOBJDETECT_XOBJDETECT_HPP__
#define __OPENCV_XOBJDETECT_XOBJDETECT_HPP__
#include <opencv2/core.hpp>
#include <vector>
#include <string>
namespace cv
{
namespace xobjdetect
{
/* Compute channel pyramid for acf features
image image, for which channels should be computed
channels output array for computed channels
*/
void computeChannels(InputArray image, OutputArrayOfArrays channels);
class CV_EXPORTS ACFFeatureEvaluator : public Algorithm
{
public:
/* Set channels for feature evaluation */
virtual void setChannels(InputArrayOfArrays channels) = 0;
/* Set window position */
virtual void setPosition(Size position) = 0;
/* Evaluate feature with given index for current channels
and window position */
virtual int evaluate(size_t feature_ind) const = 0;
/* Evaluate all features for current channels and window position
Returns matrix-column of features
*/
virtual void evaluateAll(OutputArray feature_values) const = 0;
};
/* Construct evaluator, set features to evaluate */
CV_EXPORTS Ptr<ACFFeatureEvaluator>
createACFFeatureEvaluator(const std::vector<Point3i>& features);
/* Generate acf features
window_size size of window in which features should be evaluated
count number of features to generate.
Max number of features is min(count, # possible distinct features)
Returns vector of distinct acf features
*/
std::vector<Point3i>
generateFeatures(Size window_size, int count = INT_MAX);
struct CV_EXPORTS WaldBoostParams
{
int weak_count;
float alpha;
WaldBoostParams(): weak_count(100), alpha(0.01f)
{}
};
class CV_EXPORTS WaldBoost : public Algorithm
{
public:
/* Train WaldBoost cascade for given data
data matrix of feature values, size M x N, one feature per row
labels matrix of sample class labels, size 1 x N. Labels can be from
{-1, +1}
Returns feature indices chosen for cascade.
Feature enumeration starts from 0
*/
virtual std::vector<int> train(const Mat& data,
const Mat& labels) = 0;
/* Predict object class given object that can compute object features
feature_evaluator object that can compute features by demand
Returns confidence_value measure of confidense that object
is from class +1
*/
virtual float predict(
const Ptr<ACFFeatureEvaluator>& feature_evaluator) const = 0;
};
CV_EXPORTS Ptr<WaldBoost>
createWaldBoost(const WaldBoostParams& params = WaldBoostParams());
struct CV_EXPORTS ICFDetectorParams
{
int feature_count;
int weak_count;
int model_n_rows;
int model_n_cols;
double overlap;
ICFDetectorParams(): feature_count(UINT_MAX), weak_count(100),
model_n_rows(40), model_n_cols(40), overlap(0.0)
{}
};
class CV_EXPORTS ICFDetector
{
public:
/* Train detector
image_filenames filenames of images for training
labelling vector of object bounding boxes per every image
params parameters for detector training
*/
void train(const std::vector<std::string>& image_filenames,
const std::vector<std::vector<cv::Rect> >& labelling,
ICFDetectorParams params = ICFDetectorParams());
/* Save detector in file, return true on success, false otherwise */
bool save(const std::string& filename);
};
} /* namespace xobjdetect */
} /* namespace cv */
#endif /* __OPENCV_XOBJDETECT_XOBJDETECT_HPP__ */

@ -0,0 +1,62 @@
#ifndef __OPENCV_XOBJDETECT_PRIVATE_HPP__
#define __OPENCV_XOBJDETECT_PRIVATE_HPP__
#ifndef __OPENCV_BUILD
# error this is a private header, do not include it outside OpenCV
#endif
#include <opencv2/core.hpp>
namespace cv
{
namespace xobjdetect
{
class CV_EXPORTS Stump
{
public:
/* Initialize zero stump */
Stump(): threshold_(0), polarity_(1), pos_value_(1), neg_value_(-1) {}
/* Initialize stump with given threshold, polarity
and classification values */
Stump(int threshold, int polarity, float pos_value, float neg_value):
threshold_(threshold), polarity_(polarity),
pos_value_(pos_value), neg_value_(neg_value) {}
/* Train stump for given data
data matrix of feature values, size M x N, one feature per row
labels matrix of sample class labels, size 1 x N. Labels can be from
{-1, +1}
weights matrix of sample weights, size 1 x N
Returns chosen feature index. Feature enumeration starts from 0
*/
int train(const Mat& data, const Mat& labels, const Mat& weights);
/* Predict object class given
value feature value. Feature must be the same as was chosen
during training stump
Returns real value, sign(value) means class
*/
float predict(int value) const;
private:
/* Stump decision threshold */
int threshold_;
/* Stump polarity, can be from {-1, +1} */
int polarity_;
/* Classification values for positive and negative classes */
float pos_value_, neg_value_;
};
} /* namespace xobjdetect */
} /* namespace cv */
#endif // __OPENCV_XOBJDETECT_PRIVATE_HPP__

@ -0,0 +1,203 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/
#include "precomp.hpp"
using std::vector;
using std::min;
#include <iostream>
using std::cout;
using std::endl;
namespace cv
{
namespace xobjdetect
{
class ACFFeatureEvaluatorImpl : public ACFFeatureEvaluator
{
public:
ACFFeatureEvaluatorImpl(const vector<Point3i>& features):
features_(features), channels_(), position_()
{
CV_Assert(features.size() > 0);
}
virtual void setChannels(InputArrayOfArrays channels);
virtual void setPosition(Size position);
virtual int evaluate(size_t feature_ind) const;
virtual void evaluateAll(OutputArray feature_values) const;
private:
/* Features to evaluate */
std::vector<Point3i> features_;
/* Channels for feature evaluation */
std::vector<Mat> channels_;
/* Channels window position */
Size position_;
};
void ACFFeatureEvaluatorImpl::setChannels(cv::InputArrayOfArrays channels)
{
channels_.clear();
vector<Mat> ch;
channels.getMatVector(ch);
CV_Assert(ch.size() == 10);
for( size_t i = 0; i < ch.size(); ++i )
{
const Mat &channel = ch[i];
Mat_<int> acf_channel(channel.rows / 4, channel.cols / 4);
for( int row = 0; row < channel.rows; row += 4 )
{
for( int col = 0; col < channel.cols; col += 4 )
{
int sum = 0;
for( int cell_row = row; cell_row < row + 4; ++cell_row )
for( int cell_col = col; cell_col < col + 4; ++cell_col )
sum += (int)channel.at<float>(cell_row, cell_col);
acf_channel(row / 4, col / 4) = sum;
}
}
channels_.push_back(acf_channel);
}
}
void ACFFeatureEvaluatorImpl::setPosition(Size position)
{
position_ = position;
}
int ACFFeatureEvaluatorImpl::evaluate(size_t feature_ind) const
{
CV_Assert(channels_.size() == 10);
CV_Assert(feature_ind < features_.size());
Point3i feature = features_.at(feature_ind);
int x = feature.x;
int y = feature.y;
int n = feature.z;
return channels_[n].at<int>(y, x);
}
void ACFFeatureEvaluatorImpl::evaluateAll(OutputArray feature_values) const
{
Mat_<int> feature_vals(1, (int)features_.size());
for( int i = 0; i < (int)features_.size(); ++i )
{
feature_vals(0, i) = evaluate(i);
}
feature_values.setTo(feature_vals);
}
Ptr<ACFFeatureEvaluator>
createACFFeatureEvaluator(const vector<Point3i>& features)
{
return Ptr<ACFFeatureEvaluator>(new ACFFeatureEvaluatorImpl(features));
}
vector<Point3i> generateFeatures(Size window_size, int count)
{
CV_Assert(count > 0);
int cur_count = 0;
int max_count = window_size.width * window_size.height / 16;
count = min(count, max_count);
vector<Point3i> features;
for( int x = 0; x < window_size.width / 4; ++x )
{
for( int y = 0; y < window_size.height / 4; ++y )
{
/* Assume there are 10 channel types */
for( int n = 0; n < 10; ++n )
{
features.push_back(Point3i(x, y, n));
if( (cur_count += 1) == count )
break;
}
}
}
return features;
}
void computeChannels(cv::InputArray image, cv::OutputArrayOfArrays channels_)
{
Mat src(image.getMat().rows, image.getMat().cols, CV_32FC3);
image.getMat().convertTo(src, CV_32FC3, 1./255);
Mat_<float> grad;
Mat gray;
cvtColor(src, gray, CV_RGB2GRAY);
Mat_<float> row_der, col_der;
Sobel(gray, row_der, CV_32F, 0, 1);
Sobel(gray, col_der, CV_32F, 1, 0);
magnitude(row_der, col_der, grad);
Mat_<Vec6f> hist(grad.rows, grad.cols);
const float to_deg = 180 / 3.1415926f;
for (int row = 0; row < grad.rows; ++row) {
for (int col = 0; col < grad.cols; ++col) {
float angle = atan2(row_der(row, col), col_der(row, col)) * to_deg;
if (angle < 0)
angle += 180;
int ind = (int)(angle / 30);
hist(row, col)[ind] = grad(row, col);
}
}
vector<Mat> channels;
channels.push_back(gray);
channels.push_back(grad);
vector<Mat> hist_channels;
split(hist, hist_channels);
for( size_t i = 0; i < hist_channels.size(); ++i )
channels.push_back(hist_channels[i]);
channels_.setTo(channels);
}
} /* namespace xobjdetect */
} /* namespace cv */

@ -0,0 +1,150 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/
#include "precomp.hpp"
using std::vector;
using std::string;
using std::min;
using std::max;
namespace cv
{
namespace xobjdetect
{
static bool overlap(const Rect& r, const vector<Rect>& gt)
{
for( size_t i = 0; i < gt.size(); ++i )
if( (r & gt[i]).area() )
return true;
return false;
}
void ICFDetector::train(const vector<string>& image_filenames,
const vector< vector<Rect> >& labelling,
ICFDetectorParams params)
{
Size model_size(params.model_n_cols, params.model_n_rows);
vector<Mat> samples; /* positive samples + negative samples */
Mat sample, resized_sample;
int pos_count = 0;
for( size_t i = 0; i < image_filenames.size(); ++i, ++pos_count )
{
Mat img = imread(String(image_filenames[i].c_str()));
for( size_t j = 0; j < labelling[i].size(); ++j )
{
Rect r = labelling[i][j];
if( r.x > img.cols || r.y > img.rows )
continue;
sample = img.colRange(max(r.x, 0), min(r.width, img.cols))
.rowRange(max(r.y, 0), min(r.height, img.rows));
resize(sample, resized_sample, model_size);
samples.push_back(resized_sample);
}
}
int neg_count = 0;
RNG rng;
for( size_t i = 0; i < image_filenames.size(); ++i )
{
Mat img = imread(String(image_filenames[i].c_str()));
for( int j = 0; j < (int)(pos_count / image_filenames.size() + 1); )
{
Rect r;
r.x = rng.uniform(0, img.cols);
r.width = rng.uniform(r.x + 1, img.cols);
r.y = rng.uniform(0, img.rows);
r.height = rng.uniform(r.y + 1, img.rows);
if( !overlap(r, labelling[i]) )
{
sample = img.colRange(r.x, r.width).rowRange(r.y, r.height);
//resize(sample, resized_sample);
samples.push_back(resized_sample);
++neg_count;
++j;
}
}
}
Mat_<int> labels(1, pos_count + neg_count);
for( int i = 0; i < pos_count; ++i)
labels(0, i) = 1;
for( int i = pos_count; i < pos_count + neg_count; ++i )
labels(0, i) = -1;
vector<Point3i> features = generateFeatures(model_size);
Ptr<ACFFeatureEvaluator> feature_evaluator = createACFFeatureEvaluator(features);
Mat_<int> data((int)features.size(), (int)samples.size());
Mat_<int> feature_col;
vector<Mat> channels;
for( int i = 0; i < (int)samples.size(); ++i )
{
computeChannels(samples[i], channels);
feature_evaluator->setChannels(channels);
feature_evaluator->evaluateAll(feature_col);
for( int j = 0; j < feature_col.rows; ++j )
data(i, j) = feature_col(0, j);
}
WaldBoostParams wparams;
wparams.weak_count = params.weak_count;
wparams.alpha = 0.001f;
Ptr<WaldBoost> waldboost = createWaldBoost(wparams);
waldboost->train(data, labels);
}
bool ICFDetector::save(const string&)
{
return true;
}
} /* namespace xobjdetect */
} /* namespace cv */

@ -0,0 +1,56 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/
#ifndef __OPENCV_XOBJDETECT_PRECOMP_HPP__
#define __OPENCV_XOBJDETECT_PRECOMP_HPP__
#include <opencv2/xobjdetect.hpp>
#include <opencv2/xobjdetect/private.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/highgui.hpp>
#include <algorithm>
#include <cmath>
#endif /* __OPENCV_XOBJDETECT_PRECOMP_HPP__ */

@ -0,0 +1,203 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/
#include "precomp.hpp"
namespace cv
{
namespace xobjdetect
{
/* Cumulative sum by rows */
static void cumsum(const Mat_<float>& src, Mat_<float> dst)
{
CV_Assert(src.cols > 0);
for( int row = 0; row < src.rows; ++row )
{
dst(row, 0) = src(row, 0);
for( int col = 1; col < src.cols; ++col )
{
dst(row, col) = dst(row, col - 1) + src(row, col);
}
}
}
int Stump::train(const Mat& data, const Mat& labels, const Mat& weights)
{
CV_Assert(labels.rows == 1 && labels.cols == data.cols);
CV_Assert(weights.rows == 1 && weights.cols == data.cols);
/* Assert that data and labels have int type */
/* Assert that weights have float type */
/* Prepare labels for each feature rearranged according to sorted order */
Mat sorted_labels(data.rows, data.cols, labels.type());
Mat sorted_weights(data.rows, data.cols, weights.type());
Mat indices;
sortIdx(data, indices, cv::SORT_EVERY_ROW | cv::SORT_ASCENDING);
for( int row = 0; row < indices.rows; ++row )
{
for( int col = 0; col < indices.cols; ++col )
{
sorted_labels.at<int>(row, col) =
labels.at<int>(0, indices.at<int>(row, col));
sorted_weights.at<float>(row, col) =
weights.at<float>(0, indices.at<int>(row, col));
}
}
/* Sort feature values */
Mat sorted_data(data.rows, data.cols, data.type());
sort(data, sorted_data, cv::SORT_EVERY_ROW | cv::SORT_ASCENDING);
/* Split positive and negative weights */
Mat pos_weights = Mat::zeros(sorted_weights.rows, sorted_weights.cols,
sorted_weights.type());
Mat neg_weights = Mat::zeros(sorted_weights.rows, sorted_weights.cols,
sorted_weights.type());
for( int row = 0; row < data.rows; ++row )
{
for( int col = 0; col < data.cols; ++col )
{
if( sorted_labels.at<int>(row, col) == +1 )
{
pos_weights.at<float>(row, col) =
sorted_weights.at<float>(row, col);
}
else
{
neg_weights.at<float>(row, col) =
sorted_weights.at<float>(row, col);
}
}
}
/* Compute cumulative sums for fast stump error computation */
Mat pos_cum_weights = Mat::zeros(sorted_weights.rows, sorted_weights.cols,
sorted_weights.type());
Mat neg_cum_weights = Mat::zeros(sorted_weights.rows, sorted_weights.cols,
sorted_weights.type());
cumsum(pos_weights, pos_cum_weights);
cumsum(neg_weights, neg_cum_weights);
/* Compute total weights of positive and negative samples */
float pos_total_weight = pos_cum_weights.at<float>(0, weights.cols - 1);
float neg_total_weight = neg_cum_weights.at<float>(0, weights.cols - 1);
float eps = 1.0f / (4 * labels.cols);
/* Compute minimal error */
float min_err = FLT_MAX;
int min_row = -1;
int min_col = -1;
int min_polarity = 0;
float min_pos_value = 1, min_neg_value = -1;
for( int row = 0; row < sorted_weights.rows; ++row )
{
for( int col = 0; col < sorted_weights.cols - 1; ++col )
{
float err, h_pos, h_neg;
// Direct polarity
float pos_wrong = pos_cum_weights.at<float>(row, col);
float pos_right = pos_total_weight - pos_wrong;
float neg_right = neg_cum_weights.at<float>(row, col);
float neg_wrong = neg_total_weight - neg_right;
h_pos = (float)(.5 * log((pos_right + eps) / (pos_wrong + eps)));
h_neg = (float)(.5 * log((neg_wrong + eps) / (neg_right + eps)));
err = sqrt(pos_right * neg_wrong) + sqrt(pos_wrong * neg_right);
if( err < min_err )
{
min_err = err;
min_row = row;
min_col = col;
min_polarity = +1;
min_pos_value = h_pos;
min_neg_value = h_neg;
}
// Opposite polarity
swap(pos_right, pos_wrong);
swap(neg_right, neg_wrong);
h_pos = -h_pos;
h_neg = -h_neg;
err = sqrt(pos_right * neg_wrong) + sqrt(pos_wrong * neg_right);
if( err < min_err )
{
min_err = err;
min_row = row;
min_col = col;
min_polarity = -1;
min_pos_value = h_pos;
min_neg_value = h_neg;
}
}
}
/* Compute threshold, store found values in fields */
threshold_ = ( sorted_data.at<int>(min_row, min_col) +
sorted_data.at<int>(min_row, min_col + 1) ) / 2;
polarity_ = min_polarity;
pos_value_ = min_pos_value;
neg_value_ = min_neg_value;
return min_row;
}
float Stump::predict(int value) const
{
return polarity_ * (value - threshold_) > 0 ? pos_value_ : neg_value_;
}
} /* namespace xobjdetect */
} /* namespace cv */

@ -0,0 +1,187 @@
/*
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
(3-clause BSD License)
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:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions 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.
* Neither the names of the copyright holders nor the names of the contributors
may 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 copyright holders 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.
*/
#include "precomp.hpp"
using std::swap;
using std::vector;
namespace cv
{
namespace xobjdetect
{
class WaldBoostImpl : public WaldBoost
{
public:
/* Initialize WaldBoost cascade with default of specified parameters */
WaldBoostImpl(const WaldBoostParams& params):
params_(params)
{}
virtual std::vector<int> train(const Mat& data,
const Mat& labels);
virtual float predict(
const Ptr<ACFFeatureEvaluator>& feature_evaluator) const;
private:
/* Parameters for cascade training */
WaldBoostParams params_;
/* Stumps in cascade */
std::vector<Stump> stumps_;
/* Rejection thresholds for linear combination at every stump evaluation */
std::vector<float> thresholds_;
};
vector<int> WaldBoostImpl::train(const Mat& data, const Mat& labels)
{
CV_Assert(labels.rows == 1 && labels.cols == data.cols);
int pos_count = 0, neg_count = 0;
for( int col = 0; col < labels.cols; ++col )
{
if( labels.at<int>(0, col) == +1 )
pos_count += 1;
else
neg_count += 1;
}
Mat_<float> weights(labels.rows, labels.cols);
float pos_weight = 1.0f / (2 * pos_count);
float neg_weight = 1.0f / (2 * neg_count);
for( int col = 0; col < weights.cols; ++col )
{
if( labels.at<int>(0, col) == +1 )
weights.at<float>(0, col) = pos_weight;
else
weights.at<float>(0, col) = neg_weight;
}
vector<int> feature_indices;
Mat_<float> trace = Mat_<float>::zeros(labels.rows, labels.cols);
stumps_.clear();
thresholds_.clear();
for( int i = 0; i < params_.weak_count; ++i)
{
Stump s;
int feature_ind = s.train(data, labels, weights);
stumps_.push_back(s);
feature_indices.push_back(feature_ind);
// Recompute weights
for( int col = 0; col < weights.cols; ++col )
{
float h = s.predict(data.at<int>(feature_ind, col));
trace(0, col) += h;
int label = labels.at<int>(0, col);
weights.at<float>(0, col) *= exp(-label * h);
}
// Normalize weights
float z = (float)sum(weights)[0];
for( int col = 0; col < weights.cols; ++col)
{
weights.at<float>(0, col) /= z;
}
// Sort trace
Mat indices;
sortIdx(trace, indices, cv::SORT_EVERY_ROW | cv::SORT_ASCENDING);
Mat new_weights = Mat_<float>::zeros(weights.rows, weights.cols);
Mat new_labels = Mat_<int>::zeros(labels.rows, labels.cols);
Mat new_trace;
for( int col = 0; col < new_weights.cols; ++col )
{
new_weights.at<float>(0, col) =
weights.at<float>(0, indices.at<int>(0, col));
new_labels.at<int>(0, col) =
labels.at<int>(0, indices.at<int>(0, col));
}
sort(trace, new_trace, cv::SORT_EVERY_ROW | cv::SORT_ASCENDING);
// Compute threshold for trace
int col = 0;
for( int pos_i = 0;
pos_i < pos_count * params_.alpha && col < weights.cols;
++col )
{
if( labels.at<int>(0, col) == +1 )
++pos_i;
}
thresholds_.push_back(new_trace.at<float>(0, col));
// Drop samples below threshold
new_trace.colRange(col, new_trace.cols).copyTo(trace);
new_weights.colRange(col, new_weights.cols).copyTo(weights);
new_labels.colRange(col, new_labels.cols).copyTo(labels);
}
return feature_indices;
}
float WaldBoostImpl::predict(
const Ptr<ACFFeatureEvaluator>& feature_evaluator) const
{
float trace = 0;
for( size_t i = 0; i < stumps_.size(); ++i )
{
int value = feature_evaluator->evaluate(i);
trace += stumps_[i].predict(value);
if( trace < thresholds_[i] )
return -1;
}
return trace;
}
Ptr<WaldBoost>
createWaldBoost(const WaldBoostParams& params)
{
return Ptr<WaldBoost>(new WaldBoostImpl(params));
}
} /* namespace xobjdetect */
} /* namespace cv */
Loading…
Cancel
Save