mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Set stricter warning rules for gcc
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -55,12 +55,12 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector<std::pair<float, int> >& quads, int class_id)
|
||||
static void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector<std::pair<float, int> >& quads, int class_id)
|
||||
{
|
||||
const float min_aspect_ratio = 0.3f;
|
||||
const float max_aspect_ratio = 3.0f;
|
||||
const float min_box_size = 10.0f;
|
||||
|
||||
|
||||
for(CvSeq* seq = contours; seq != NULL; seq = seq->h_next)
|
||||
{
|
||||
CvBox2D box = cvMinAreaRect2(seq);
|
||||
@@ -75,12 +75,12 @@ void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector<std::pair<float, in
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
quads.push_back(std::pair<float, int>(box_size, class_id));
|
||||
}
|
||||
}
|
||||
|
||||
void countClasses(const std::vector<std::pair<float, int> >& pairs, size_t idx1, size_t idx2, std::vector<int>& counts)
|
||||
static void countClasses(const std::vector<std::pair<float, int> >& pairs, size_t idx1, size_t idx2, std::vector<int>& counts)
|
||||
{
|
||||
counts.assign(2, 0);
|
||||
for(size_t i = idx1; i != idx2; i++)
|
||||
@@ -89,36 +89,36 @@ void countClasses(const std::vector<std::pair<float, int> >& pairs, size_t idx1,
|
||||
}
|
||||
}
|
||||
|
||||
bool less_pred(const std::pair<float, int>& p1, const std::pair<float, int>& p2)
|
||||
inline bool less_pred(const std::pair<float, int>& p1, const std::pair<float, int>& p2)
|
||||
{
|
||||
return p1.first < p2.first;
|
||||
}
|
||||
|
||||
// does a fast check if a chessboard is in the input image. This is a workaround to
|
||||
// does a fast check if a chessboard is in the input image. This is a workaround to
|
||||
// a problem of cvFindChessboardCorners being slow on images with no chessboard
|
||||
// - src: input image
|
||||
// - size: chessboard size
|
||||
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
|
||||
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
|
||||
// 0 if there is no chessboard, -1 in case of error
|
||||
int cvCheckChessboard(IplImage* src, CvSize size)
|
||||
{
|
||||
if(src->nChannels > 1)
|
||||
{
|
||||
cvError(CV_BadNumChannels, "cvCheckChessboard", "supports single-channel images only",
|
||||
cvError(CV_BadNumChannels, "cvCheckChessboard", "supports single-channel images only",
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
if(src->depth != 8)
|
||||
{
|
||||
cvError(CV_BadDepth, "cvCheckChessboard", "supports depth=8 images only",
|
||||
cvError(CV_BadDepth, "cvCheckChessboard", "supports depth=8 images only",
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
const int erosion_count = 1;
|
||||
const float black_level = 20.f;
|
||||
const float white_level = 130.f;
|
||||
const float black_white_gap = 70.f;
|
||||
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
cvNamedWindow("1", 1);
|
||||
cvShowImage("1", src);
|
||||
@@ -126,46 +126,46 @@ int cvCheckChessboard(IplImage* src, CvSize size)
|
||||
#endif //DEBUG_WINDOWS
|
||||
|
||||
CvMemStorage* storage = cvCreateMemStorage();
|
||||
|
||||
|
||||
IplImage* white = cvCloneImage(src);
|
||||
IplImage* black = cvCloneImage(src);
|
||||
|
||||
|
||||
cvErode(white, white, NULL, erosion_count);
|
||||
cvDilate(black, black, NULL, erosion_count);
|
||||
IplImage* thresh = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
|
||||
|
||||
|
||||
int result = 0;
|
||||
for(float thresh_level = black_level; thresh_level < white_level && !result; thresh_level += 20.0f)
|
||||
{
|
||||
cvThreshold(white, thresh, thresh_level + black_white_gap, 255, CV_THRESH_BINARY);
|
||||
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
cvShowImage("1", thresh);
|
||||
cvWaitKey(0);
|
||||
#endif //DEBUG_WINDOWS
|
||||
|
||||
|
||||
CvSeq* first = 0;
|
||||
std::vector<std::pair<float, int> > quads;
|
||||
cvFindContours(thresh, storage, &first, sizeof(CvContour), CV_RETR_CCOMP);
|
||||
cvFindContours(thresh, storage, &first, sizeof(CvContour), CV_RETR_CCOMP);
|
||||
icvGetQuadrangleHypotheses(first, quads, 1);
|
||||
|
||||
|
||||
cvThreshold(black, thresh, thresh_level, 255, CV_THRESH_BINARY_INV);
|
||||
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
cvShowImage("1", thresh);
|
||||
cvWaitKey(0);
|
||||
#endif //DEBUG_WINDOWS
|
||||
|
||||
|
||||
cvFindContours(thresh, storage, &first, sizeof(CvContour), CV_RETR_CCOMP);
|
||||
icvGetQuadrangleHypotheses(first, quads, 0);
|
||||
|
||||
|
||||
const size_t min_quads_count = size.width*size.height/2;
|
||||
std::sort(quads.begin(), quads.end(), less_pred);
|
||||
|
||||
|
||||
// now check if there are many hypotheses with similar sizes
|
||||
// do this by floodfill-style algorithm
|
||||
const float size_rel_dev = 0.4f;
|
||||
|
||||
|
||||
for(size_t i = 0; i < quads.size(); i++)
|
||||
{
|
||||
size_t j = i + 1;
|
||||
@@ -176,7 +176,7 @@ int cvCheckChessboard(IplImage* src, CvSize size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(j + 1 > min_quads_count + i)
|
||||
{
|
||||
// check the number of black and white squares
|
||||
@@ -194,12 +194,12 @@ int cvCheckChessboard(IplImage* src, CvSize size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
cvReleaseImage(&thresh);
|
||||
cvReleaseImage(&white);
|
||||
cvReleaseImage(&black);
|
||||
cvReleaseMemStorage(&storage);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1223,7 +1223,7 @@ void computePredecessorMatrix(const Mat &dm, int verticesCount, Mat &predecessor
|
||||
}
|
||||
}
|
||||
|
||||
void computeShortestPath(Mat &predecessorMatrix, size_t v1, size_t v2, vector<size_t> &path)
|
||||
static void computeShortestPath(Mat &predecessorMatrix, size_t v1, size_t v2, vector<size_t> &path)
|
||||
{
|
||||
if (predecessorMatrix.at<int> ((int)v1, (int)v2) < 0)
|
||||
{
|
||||
@@ -1403,7 +1403,7 @@ void CirclesGridFinder::getHoles(vector<Point2f> &outHoles) const
|
||||
}
|
||||
}
|
||||
|
||||
bool areIndicesCorrect(Point pos, vector<vector<size_t> > *points)
|
||||
static bool areIndicesCorrect(Point pos, vector<vector<size_t> > *points)
|
||||
{
|
||||
if (pos.y < 0 || pos.x < 0)
|
||||
return false;
|
||||
|
||||
@@ -42,11 +42,11 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -52,41 +52,41 @@
|
||||
#undef max
|
||||
|
||||
namespace cv {
|
||||
|
||||
|
||||
void drawCircles(Mat& img, const vector<Point2f>& corners, const vector<float>& radius)
|
||||
{
|
||||
for(size_t i = 0; i < corners.size(); i++)
|
||||
{
|
||||
circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
int histQuantile(const Mat& hist, float quantile)
|
||||
{
|
||||
if(hist.dims > 1) return -1; // works for 1D histograms only
|
||||
|
||||
float cur_sum = 0;
|
||||
float total_sum = (float)sum(hist).val[0];
|
||||
float quantile_sum = total_sum*quantile;
|
||||
for(int j = 0; j < hist.size[0]; j++)
|
||||
{
|
||||
cur_sum += (float)hist.at<float>(j);
|
||||
if(cur_sum > quantile_sum)
|
||||
{
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
return hist.size[0] - 1;
|
||||
}
|
||||
|
||||
bool is_smaller(const std::pair<int, float>& p1, const std::pair<int, float>& p2)
|
||||
|
||||
|
||||
// static void drawCircles(Mat& img, const vector<Point2f>& corners, const vector<float>& radius)
|
||||
// {
|
||||
// for(size_t i = 0; i < corners.size(); i++)
|
||||
// {
|
||||
// circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0));
|
||||
// }
|
||||
// }
|
||||
|
||||
// static int histQuantile(const Mat& hist, float quantile)
|
||||
// {
|
||||
// if(hist.dims > 1) return -1; // works for 1D histograms only
|
||||
|
||||
// float cur_sum = 0;
|
||||
// float total_sum = (float)sum(hist).val[0];
|
||||
// float quantile_sum = total_sum*quantile;
|
||||
// for(int j = 0; j < hist.size[0]; j++)
|
||||
// {
|
||||
// cur_sum += (float)hist.at<float>(j);
|
||||
// if(cur_sum > quantile_sum)
|
||||
// {
|
||||
// return j;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return hist.size[0] - 1;
|
||||
// }
|
||||
|
||||
inline bool is_smaller(const std::pair<int, float>& p1, const std::pair<int, float>& p2)
|
||||
{
|
||||
return p1.second < p2.second;
|
||||
}
|
||||
|
||||
void orderContours(const vector<vector<Point> >& contours, Point2f point, vector<std::pair<int, float> >& order)
|
||||
static void orderContours(const vector<vector<Point> >& contours, Point2f point, vector<std::pair<int, float> >& order)
|
||||
{
|
||||
order.clear();
|
||||
size_t i, j, n = contours.size();
|
||||
@@ -101,58 +101,58 @@ void orderContours(const vector<vector<Point> >& contours, Point2f point, vector
|
||||
}
|
||||
order.push_back(std::pair<int, float>((int)i, (float)min_dist));
|
||||
}
|
||||
|
||||
|
||||
std::sort(order.begin(), order.end(), is_smaller);
|
||||
}
|
||||
|
||||
// fit second order curve to a set of 2D points
|
||||
void fitCurve2Order(const vector<Point2f>& /*points*/, vector<float>& /*curve*/)
|
||||
inline void fitCurve2Order(const vector<Point2f>& /*points*/, vector<float>& /*curve*/)
|
||||
{
|
||||
// TBD
|
||||
}
|
||||
|
||||
void findCurvesCross(const vector<float>& /*curve1*/, const vector<float>& /*curve2*/, Point2f& /*cross_point*/)
|
||||
|
||||
inline void findCurvesCross(const vector<float>& /*curve1*/, const vector<float>& /*curve2*/, Point2f& /*cross_point*/)
|
||||
{
|
||||
}
|
||||
|
||||
void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f dir2, Point2f& cross_point)
|
||||
|
||||
static void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f dir2, Point2f& cross_point)
|
||||
{
|
||||
float det = dir2.x*dir1.y - dir2.y*dir1.x;
|
||||
Point2f offset = origin2 - origin1;
|
||||
|
||||
|
||||
float alpha = (dir2.x*offset.y - dir2.y*offset.x)/det;
|
||||
cross_point = origin1 + dir1*alpha;
|
||||
}
|
||||
|
||||
void findCorner(const vector<Point>& contour, Point2f point, Point2f& corner)
|
||||
{
|
||||
// find the nearest point
|
||||
double min_dist = std::numeric_limits<double>::max();
|
||||
int min_idx = -1;
|
||||
|
||||
// find corner idx
|
||||
for(size_t i = 0; i < contour.size(); i++)
|
||||
{
|
||||
double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point);
|
||||
if(dist < min_dist)
|
||||
{
|
||||
min_dist = dist;
|
||||
min_idx = (int)i;
|
||||
}
|
||||
}
|
||||
assert(min_idx >= 0);
|
||||
|
||||
// temporary solution, have to make something more precise
|
||||
corner = contour[min_idx];
|
||||
return;
|
||||
}
|
||||
|
||||
void findCorner(const vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
// static void findCorner(const vector<Point>& contour, Point2f point, Point2f& corner)
|
||||
// {
|
||||
// // find the nearest point
|
||||
// double min_dist = std::numeric_limits<double>::max();
|
||||
// int min_idx = -1;
|
||||
|
||||
// // find corner idx
|
||||
// for(size_t i = 0; i < contour.size(); i++)
|
||||
// {
|
||||
// double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point);
|
||||
// if(dist < min_dist)
|
||||
// {
|
||||
// min_dist = dist;
|
||||
// min_idx = (int)i;
|
||||
// }
|
||||
// }
|
||||
// assert(min_idx >= 0);
|
||||
|
||||
// // temporary solution, have to make something more precise
|
||||
// corner = contour[min_idx];
|
||||
// return;
|
||||
// }
|
||||
|
||||
static void findCorner(const vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
{
|
||||
// find the nearest point
|
||||
double min_dist = std::numeric_limits<double>::max();
|
||||
int min_idx = -1;
|
||||
|
||||
|
||||
// find corner idx
|
||||
for(size_t i = 0; i < contour.size(); i++)
|
||||
{
|
||||
@@ -164,23 +164,23 @@ void findCorner(const vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
}
|
||||
}
|
||||
assert(min_idx >= 0);
|
||||
|
||||
|
||||
// temporary solution, have to make something more precise
|
||||
corner = contour[min_idx];
|
||||
return;
|
||||
}
|
||||
|
||||
int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
|
||||
static int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
{
|
||||
Mat bw;
|
||||
//const double max_bell_width = 20; // we expect two bells with width bounded above
|
||||
//const double min_bell_width = 5; // and below
|
||||
|
||||
|
||||
double total_sum = sum(hist).val[0];
|
||||
//double thresh = total_sum/(2*max_bell_width)*0.25f; // quarter of a bar inside a bell
|
||||
|
||||
|
||||
// threshold(hist, bw, thresh, 255.0, CV_THRESH_BINARY);
|
||||
|
||||
|
||||
double quantile_sum = 0.0;
|
||||
//double min_quantile = 0.2;
|
||||
double low_sum = 0;
|
||||
@@ -193,7 +193,7 @@ int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
{
|
||||
quantile_sum += hist.at<float>(x);
|
||||
if(quantile_sum < 0.2*total_sum) continue;
|
||||
|
||||
|
||||
if(quantile_sum - low_sum > out_of_bells_fraction*total_sum)
|
||||
{
|
||||
if(max_segment_length < x - start_x)
|
||||
@@ -207,7 +207,7 @@ int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
start_x = x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(start_x == -1)
|
||||
{
|
||||
return 0;
|
||||
@@ -219,9 +219,9 @@ int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size region_size)
|
||||
{
|
||||
Mat img = _img.getMat(), cornersM = _corners.getMat();
|
||||
@@ -232,22 +232,22 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
float ranges[] = {0, 256};
|
||||
const float* _ranges = ranges;
|
||||
Mat hist;
|
||||
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
vector<float> radius;
|
||||
radius.assign(corners.size(), 0.0f);
|
||||
#endif //_SUBPIX_VERBOSE
|
||||
|
||||
|
||||
|
||||
|
||||
Mat black_comp, white_comp;
|
||||
for(int i = 0; i < ncorners; i++)
|
||||
{
|
||||
{
|
||||
int channels = 0;
|
||||
Rect roi(cvRound(corners[i].x - region_size.width), cvRound(corners[i].y - region_size.height),
|
||||
region_size.width*2 + 1, region_size.height*2 + 1);
|
||||
Mat img_roi = img(roi);
|
||||
calcHist(&img_roi, 1, &channels, Mat(), hist, 1, &nbins, &_ranges);
|
||||
|
||||
|
||||
#if 0
|
||||
int black_thresh = histQuantile(hist, 0.45f);
|
||||
int white_thresh = histQuantile(hist, 0.55f);
|
||||
@@ -255,10 +255,10 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
int black_thresh, white_thresh;
|
||||
segment_hist_max(hist, black_thresh, white_thresh);
|
||||
#endif
|
||||
|
||||
|
||||
threshold(img, black_comp, black_thresh, 255.0, CV_THRESH_BINARY_INV);
|
||||
threshold(img, white_comp, white_thresh, 255.0, CV_THRESH_BINARY);
|
||||
|
||||
|
||||
const int erode_count = 1;
|
||||
erode(black_comp, black_comp, Mat(), Point(-1, -1), erode_count);
|
||||
erode(white_comp, white_comp, Mat(), Point(-1, -1), erode_count);
|
||||
@@ -275,28 +275,28 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
imwrite("black.jpg", black_comp);
|
||||
imwrite("white.jpg", white_comp);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
vector<vector<Point> > white_contours, black_contours;
|
||||
vector<Vec4i> white_hierarchy, black_hierarchy;
|
||||
findContours(black_comp, black_contours, black_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
|
||||
findContours(white_comp, white_contours, white_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
|
||||
|
||||
|
||||
if(black_contours.size() < 5 || white_contours.size() < 5) continue;
|
||||
|
||||
|
||||
// find two white and black blobs that are close to the input point
|
||||
vector<std::pair<int, float> > white_order, black_order;
|
||||
orderContours(black_contours, corners[i], black_order);
|
||||
orderContours(white_contours, corners[i], white_order);
|
||||
|
||||
const float max_dist = 10.0f;
|
||||
if(black_order[0].second > max_dist || black_order[1].second > max_dist ||
|
||||
if(black_order[0].second > max_dist || black_order[1].second > max_dist ||
|
||||
white_order[0].second > max_dist || white_order[1].second > max_dist)
|
||||
{
|
||||
continue; // there will be no improvement in this corner position
|
||||
}
|
||||
|
||||
const vector<Point>* quads[4] = {&black_contours[black_order[0].first], &black_contours[black_order[1].first],
|
||||
|
||||
const vector<Point>* quads[4] = {&black_contours[black_order[0].first], &black_contours[black_order[1].first],
|
||||
&white_contours[white_order[0].first], &white_contours[white_order[1].first]};
|
||||
vector<Point2f> quads_approx[4];
|
||||
Point2f quad_corners[4];
|
||||
@@ -306,14 +306,14 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
vector<Point2f> temp;
|
||||
for(size_t j = 0; j < quads[k]->size(); j++) temp.push_back((*quads[k])[j]);
|
||||
approxPolyDP(Mat(temp), quads_approx[k], 0.5, true);
|
||||
|
||||
|
||||
findCorner(quads_approx[k], corners[i], quad_corners[k]);
|
||||
#else
|
||||
findCorner(*quads[k], corners[i], quad_corners[k]);
|
||||
#endif
|
||||
quad_corners[k] += Point2f(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
|
||||
// cross two lines
|
||||
Point2f origin1 = quad_corners[0];
|
||||
Point2f dir1 = quad_corners[1] - quad_corners[0];
|
||||
@@ -321,12 +321,12 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
Point2f dir2 = quad_corners[3] - quad_corners[2];
|
||||
double angle = acos(dir1.dot(dir2)/(norm(dir1)*norm(dir2)));
|
||||
if(cvIsNaN(angle) || cvIsInf(angle) || angle < 0.5 || angle > CV_PI - 0.5) continue;
|
||||
|
||||
|
||||
findLinesCrossPoint(origin1, dir1, origin2, dir2, corners[i]);
|
||||
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
radius[i] = norm(corners[i] - ground_truth_corners[ground_truth_idx])*6;
|
||||
|
||||
|
||||
#if 1
|
||||
Mat test(img.size(), CV_32FC3);
|
||||
cvtColor(img, test, CV_GRAY2RGB);
|
||||
@@ -349,9 +349,9 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
waitKey(0);
|
||||
#endif
|
||||
#endif //_SUBPIX_VERBOSE
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
Mat test(img.size(), CV_32FC3);
|
||||
cvtColor(img, test, CV_GRAY2RGB);
|
||||
@@ -361,6 +361,6 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
imshow("corners", test);
|
||||
waitKey();
|
||||
#endif //_SUBPIX_VERBOSE
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,48 +52,48 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
{
|
||||
Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat();
|
||||
int npoints = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F));
|
||||
CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) );
|
||||
CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) );
|
||||
_rvec.create(3, 1, CV_64F);
|
||||
_tvec.create(3, 1, CV_64F);
|
||||
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
|
||||
|
||||
if (flags == CV_EPNP)
|
||||
{
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
epnp PnP(cameraMatrix, opoints, undistortedPoints);
|
||||
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
epnp PnP(cameraMatrix, opoints, undistortedPoints);
|
||||
|
||||
cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat();
|
||||
PnP.compute_pose(R, tvec);
|
||||
cv::Rodrigues(R, rvec);
|
||||
return true;
|
||||
}
|
||||
else if (flags == CV_P3P)
|
||||
{
|
||||
CV_Assert( npoints == 4);
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
p3p P3Psolver(cameraMatrix);
|
||||
return true;
|
||||
}
|
||||
else if (flags == CV_P3P)
|
||||
{
|
||||
CV_Assert( npoints == 4);
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
p3p P3Psolver(cameraMatrix);
|
||||
|
||||
cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat();
|
||||
bool result = P3Psolver.solve(R, tvec, opoints, undistortedPoints);
|
||||
if (result)
|
||||
cv::Rodrigues(R, rvec);
|
||||
return result;
|
||||
}
|
||||
else if (flags == CV_ITERATIVE)
|
||||
{
|
||||
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
|
||||
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
|
||||
CvMat c_rvec = _rvec.getMat(), c_tvec = _tvec.getMat();
|
||||
cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix,
|
||||
c_distCoeffs.rows*c_distCoeffs.cols ? &c_distCoeffs : 0,
|
||||
&c_rvec, &c_tvec, useExtrinsicGuess );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
cv::Rodrigues(R, rvec);
|
||||
return result;
|
||||
}
|
||||
else if (flags == CV_ITERATIVE)
|
||||
{
|
||||
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
|
||||
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
|
||||
CvMat c_rvec = _rvec.getMat(), c_tvec = _tvec.getMat();
|
||||
cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix,
|
||||
c_distCoeffs.rows*c_distCoeffs.cols ? &c_distCoeffs : 0,
|
||||
&c_rvec, &c_tvec, useExtrinsicGuess );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
CV_Error(CV_StsBadArg, "The flags argument must be one of CV_ITERATIVE or CV_EPNP");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace cv
|
||||
@@ -101,8 +101,8 @@ namespace cv
|
||||
namespace pnpransac
|
||||
{
|
||||
const int MIN_POINTS_COUNT = 4;
|
||||
|
||||
void project3dPoints(const Mat& points, const Mat& rvec, const Mat& tvec, Mat& modif_points)
|
||||
|
||||
static void project3dPoints(const Mat& points, const Mat& rvec, const Mat& tvec, Mat& modif_points)
|
||||
{
|
||||
modif_points.create(1, points.cols, CV_32FC3);
|
||||
Mat R(3, 3, CV_64FC1);
|
||||
@@ -114,32 +114,32 @@ namespace cv
|
||||
tvec.copyTo(t);
|
||||
transform(points, modif_points, transformation);
|
||||
}
|
||||
|
||||
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
Mutex() {
|
||||
}
|
||||
}
|
||||
void lock()
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
resultsMutex.lock();
|
||||
resultsMutex.lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
resultsMutex.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
#ifdef HAVE_TBB
|
||||
tbb::mutex resultsMutex;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct CameraParameters
|
||||
{
|
||||
void init(Mat _intrinsics, Mat _distCoeffs)
|
||||
@@ -147,22 +147,22 @@ namespace cv
|
||||
_intrinsics.copyTo(intrinsics);
|
||||
_distCoeffs.copyTo(distortion);
|
||||
}
|
||||
|
||||
|
||||
Mat intrinsics;
|
||||
Mat distortion;
|
||||
};
|
||||
|
||||
|
||||
struct Parameters
|
||||
{
|
||||
int iterationsCount;
|
||||
float reprojectionError;
|
||||
int minInliersCount;
|
||||
bool useExtrinsicGuess;
|
||||
int flags;
|
||||
int flags;
|
||||
CameraParameters camera;
|
||||
};
|
||||
|
||||
void pnpTask(const vector<char>& pointsMask, const Mat& objectPoints, const Mat& imagePoints,
|
||||
|
||||
static void pnpTask(const vector<char>& pointsMask, const Mat& objectPoints, const Mat& imagePoints,
|
||||
const Parameters& params, vector<int>& inliers, Mat& rvec, Mat& tvec,
|
||||
const Mat& rvecInit, const Mat& tvecInit, Mutex& resultsMutex)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ namespace cv
|
||||
colIndex = colIndex+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//filter same 3d points, hang in solvePnP
|
||||
double eps = 1e-10;
|
||||
int num_same_points = 0;
|
||||
@@ -190,22 +190,22 @@ namespace cv
|
||||
}
|
||||
if (num_same_points > 0)
|
||||
return;
|
||||
|
||||
|
||||
Mat localRvec, localTvec;
|
||||
rvecInit.copyTo(localRvec);
|
||||
tvecInit.copyTo(localTvec);
|
||||
|
||||
solvePnP(modelObjectPoints, modelImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec,
|
||||
params.useExtrinsicGuess, params.flags);
|
||||
|
||||
|
||||
|
||||
solvePnP(modelObjectPoints, modelImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec,
|
||||
params.useExtrinsicGuess, params.flags);
|
||||
|
||||
|
||||
vector<Point2f> projected_points;
|
||||
projected_points.resize(objectPoints.cols);
|
||||
projectPoints(objectPoints, localRvec, localTvec, params.camera.intrinsics, params.camera.distortion, projected_points);
|
||||
|
||||
|
||||
Mat rotatedPoints;
|
||||
project3dPoints(objectPoints, localRvec, localTvec, rotatedPoints);
|
||||
|
||||
|
||||
vector<int> localInliers;
|
||||
for (int i = 0; i < objectPoints.cols; i++)
|
||||
{
|
||||
@@ -216,21 +216,21 @@ namespace cv
|
||||
localInliers.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (localInliers.size() > inliers.size())
|
||||
{
|
||||
resultsMutex.lock();
|
||||
|
||||
|
||||
inliers.clear();
|
||||
inliers.resize(localInliers.size());
|
||||
memcpy(&inliers[0], &localInliers[0], sizeof(int) * localInliers.size());
|
||||
localRvec.copyTo(rvec);
|
||||
localTvec.copyTo(tvec);
|
||||
|
||||
|
||||
resultsMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PnPSolver
|
||||
{
|
||||
public:
|
||||
@@ -262,18 +262,18 @@ namespace cv
|
||||
tvec.copyTo(initTvec);
|
||||
}
|
||||
private:
|
||||
PnPSolver& operator=(const PnPSolver&);
|
||||
|
||||
PnPSolver& operator=(const PnPSolver&);
|
||||
|
||||
const Mat& objectPoints;
|
||||
const Mat& imagePoints;
|
||||
const Parameters& parameters;
|
||||
Mat &rvec, &tvec;
|
||||
vector<int>& inliers;
|
||||
Mat initRvec, initTvec;
|
||||
|
||||
|
||||
static RNG generator;
|
||||
static Mutex syncMutex;
|
||||
|
||||
|
||||
void generateVar(vector<char>& mask) const
|
||||
{
|
||||
int size = (int)mask.size();
|
||||
@@ -287,10 +287,10 @@ namespace cv
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Mutex PnPSolver::syncMutex;
|
||||
RNG PnPSolver::generator;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,21 +302,21 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
{
|
||||
Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat();
|
||||
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
|
||||
|
||||
|
||||
CV_Assert(opoints.isContinuous());
|
||||
CV_Assert(opoints.depth() == CV_32F);
|
||||
CV_Assert((opoints.rows == 1 && opoints.channels() == 3) || opoints.cols*opoints.channels() == 3);
|
||||
CV_Assert(ipoints.isContinuous());
|
||||
CV_Assert(ipoints.depth() == CV_32F);
|
||||
CV_Assert((ipoints.rows == 1 && ipoints.channels() == 2) || ipoints.cols*ipoints.channels() == 2);
|
||||
|
||||
|
||||
_rvec.create(3, 1, CV_64FC1);
|
||||
_tvec.create(3, 1, CV_64FC1);
|
||||
Mat rvec = _rvec.getMat();
|
||||
Mat tvec = _tvec.getMat();
|
||||
|
||||
|
||||
Mat objectPoints = opoints.reshape(3, 1), imagePoints = ipoints.reshape(2, 1);
|
||||
|
||||
|
||||
if (minInliersCount <= 0)
|
||||
minInliersCount = objectPoints.cols;
|
||||
cv::pnpransac::Parameters params;
|
||||
@@ -325,36 +325,36 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
params.reprojectionError = reprojectionError;
|
||||
params.useExtrinsicGuess = useExtrinsicGuess;
|
||||
params.camera.init(cameraMatrix, distCoeffs);
|
||||
params.flags = flags;
|
||||
|
||||
params.flags = flags;
|
||||
|
||||
vector<int> localInliers;
|
||||
Mat localRvec, localTvec;
|
||||
rvec.copyTo(localRvec);
|
||||
tvec.copyTo(localTvec);
|
||||
|
||||
|
||||
if (objectPoints.cols >= pnpransac::MIN_POINTS_COUNT)
|
||||
{
|
||||
parallel_for(BlockedRange(0,iterationsCount), cv::pnpransac::PnPSolver(objectPoints, imagePoints, params,
|
||||
localRvec, localTvec, localInliers));
|
||||
}
|
||||
|
||||
|
||||
if (localInliers.size() >= (size_t)pnpransac::MIN_POINTS_COUNT)
|
||||
{
|
||||
if (flags != CV_P3P)
|
||||
{
|
||||
int i, pointsCount = (int)localInliers.size();
|
||||
Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2);
|
||||
for (i = 0; i < pointsCount; i++)
|
||||
{
|
||||
int index = localInliers[i];
|
||||
Mat colInlierImagePoints = inlierImagePoints(Rect(i, 0, 1, 1));
|
||||
imagePoints.col(index).copyTo(colInlierImagePoints);
|
||||
Mat colInlierObjectPoints = inlierObjectPoints(Rect(i, 0, 1, 1));
|
||||
objectPoints.col(index).copyTo(colInlierObjectPoints);
|
||||
}
|
||||
solvePnP(inlierObjectPoints, inlierImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, true, flags);
|
||||
}
|
||||
localRvec.copyTo(rvec);
|
||||
if (flags != CV_P3P)
|
||||
{
|
||||
int i, pointsCount = (int)localInliers.size();
|
||||
Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2);
|
||||
for (i = 0; i < pointsCount; i++)
|
||||
{
|
||||
int index = localInliers[i];
|
||||
Mat colInlierImagePoints = inlierImagePoints(Rect(i, 0, 1, 1));
|
||||
imagePoints.col(index).copyTo(colInlierImagePoints);
|
||||
Mat colInlierObjectPoints = inlierObjectPoints(Rect(i, 0, 1, 1));
|
||||
objectPoints.col(index).copyTo(colInlierObjectPoints);
|
||||
}
|
||||
solvePnP(inlierObjectPoints, inlierImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, true, flags);
|
||||
}
|
||||
localRvec.copyTo(rvec);
|
||||
localTvec.copyTo(tvec);
|
||||
if (_inliers.needed())
|
||||
Mat(localInliers).copyTo(_inliers);
|
||||
|
||||
+391
-391
File diff suppressed because it is too large
Load Diff
@@ -81,6 +81,7 @@ private:
|
||||
{
|
||||
public:
|
||||
virtual ImageIterator* iterator() const = 0;
|
||||
virtual ~ImageRange() {}
|
||||
};
|
||||
|
||||
// Sliding window
|
||||
|
||||
@@ -59,8 +59,8 @@ static Mat sortMatrixRowsByIndices(InputArray src, InputArray indices)
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
Mat argsort(InputArray _src, bool ascending=true)
|
||||
|
||||
static Mat argsort(InputArray _src, bool ascending=true)
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
if (src.rows != 1 && src.cols != 1)
|
||||
@@ -70,14 +70,14 @@ Mat argsort(InputArray _src, bool ascending=true)
|
||||
sortIdx(src.reshape(1,1),sorted_indices,flags);
|
||||
return sorted_indices;
|
||||
}
|
||||
|
||||
|
||||
template <typename _Tp> static
|
||||
Mat interp1_(const Mat& X_, const Mat& Y_, const Mat& XI)
|
||||
{
|
||||
int n = XI.rows;
|
||||
// sort input table
|
||||
vector<int> sort_indices = argsort(X_);
|
||||
|
||||
|
||||
Mat X = sortMatrixRowsByIndices(X_,sort_indices);
|
||||
Mat Y = sortMatrixRowsByIndices(Y_,sort_indices);
|
||||
// interpolated values
|
||||
@@ -131,7 +131,7 @@ static Mat interp1(InputArray _x, InputArray _Y, InputArray _xi)
|
||||
}
|
||||
return Mat();
|
||||
}
|
||||
|
||||
|
||||
namespace colormap
|
||||
{
|
||||
|
||||
@@ -531,7 +531,7 @@ namespace colormap
|
||||
n); // number of sample points
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void ColorMap::operator()(InputArray _src, OutputArray _dst) const
|
||||
{
|
||||
if(_lut.total() != 256)
|
||||
@@ -550,7 +550,7 @@ namespace colormap
|
||||
// Apply the ColorMap.
|
||||
LUT(src, _lut, _dst);
|
||||
}
|
||||
|
||||
|
||||
Mat ColorMap::linear_colormap(InputArray X,
|
||||
InputArray r, InputArray g, InputArray b,
|
||||
InputArray xi) {
|
||||
@@ -581,12 +581,12 @@ namespace colormap
|
||||
colormap == COLORMAP_HOT ? (colormap::ColorMap*)(new colormap::Hot) :
|
||||
colormap == COLORMAP_MKPJ1 ? (colormap::ColorMap*)(new colormap::MKPJ1) :
|
||||
colormap == COLORMAP_MKPJ2 ? (colormap::ColorMap*)(new colormap::MKPJ2) : 0;
|
||||
|
||||
|
||||
if( !cm )
|
||||
CV_Error( CV_StsBadArg, "Unknown colormap id; use one of COLORMAP_*");
|
||||
|
||||
|
||||
(*cm)(src, dst);
|
||||
|
||||
|
||||
delete cm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define DEBUGLOGS 1
|
||||
|
||||
#if ANDROID
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "OBJECT_DETECTOR"
|
||||
#define LOGD0(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
@@ -25,7 +25,7 @@
|
||||
#define LOGI(_str, ...) LOGI0(_str , ## __VA_ARGS__)
|
||||
#define LOGW(_str, ...) LOGW0(_str , ## __VA_ARGS__)
|
||||
#define LOGE(_str, ...) LOGE0(_str , ## __VA_ARGS__)
|
||||
#else
|
||||
#else
|
||||
#define LOGD(...) do{} while(0)
|
||||
#define LOGI(...) do{} while(0)
|
||||
#define LOGW(...) do{} while(0)
|
||||
@@ -193,7 +193,7 @@ do {
|
||||
} catch(...) { \
|
||||
LOGE0("\n ERROR: UNKNOWN Exception caught\n\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
void* workcycleObjectDetectorFunction(void* p)
|
||||
@@ -214,7 +214,7 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()
|
||||
vector<Rect> objects;
|
||||
|
||||
CV_Assert(stateThread==STATE_THREAD_WORKING_SLEEPING);
|
||||
pthread_mutex_lock(&mutex);
|
||||
pthread_mutex_lock(&mutex);
|
||||
{
|
||||
pthread_cond_signal(&objectDetectorThreadStartStop);
|
||||
|
||||
@@ -268,7 +268,7 @@ void DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()
|
||||
LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- imageSeparateDetecting is empty, continue");
|
||||
continue;
|
||||
}
|
||||
LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start handling imageSeparateDetecting, img.size=%dx%d, img.data=0x%p",
|
||||
LOGD("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start handling imageSeparateDetecting, img.size=%dx%d, img.data=0x%p",
|
||||
imageSeparateDetecting.size().width, imageSeparateDetecting.size().height, (void*)imageSeparateDetecting.data);
|
||||
|
||||
|
||||
@@ -368,7 +368,7 @@ void DetectionBasedTracker::SeparateDetectionWork::resetTracking()
|
||||
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread(const Mat& imageGray, vector<Rect>& rectsWhereRegions)
|
||||
@@ -398,7 +398,7 @@ bool DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThrea
|
||||
if (timeWhenDetectingThreadStartedWork > 0) {
|
||||
double time_from_previous_launch_in_ms=1000.0 * (((double)(getTickCount() - timeWhenDetectingThreadStartedWork )) / freq); //the same formula as for lastBigDetectionDuration
|
||||
shouldSendNewDataToWorkThread = (time_from_previous_launch_in_ms >= detectionBasedTracker.parameters.minDetectionPeriod);
|
||||
LOGD("DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: shouldSendNewDataToWorkThread was 1, now it is %d, since time_from_previous_launch_in_ms=%.2f, minDetectionPeriod=%d",
|
||||
LOGD("DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: shouldSendNewDataToWorkThread was 1, now it is %d, since time_from_previous_launch_in_ms=%.2f, minDetectionPeriod=%d",
|
||||
(shouldSendNewDataToWorkThread?1:0), time_from_previous_launch_in_ms, detectionBasedTracker.parameters.minDetectionPeriod);
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ DetectionBasedTracker::DetectionBasedTracker(const std::string& cascadeFilename,
|
||||
&& (params.scaleFactor > 1.0)
|
||||
&& (params.maxTrackLifetime >= 0) );
|
||||
|
||||
if (!cascadeForTracking.load(cascadeFilename)) {
|
||||
if (!cascadeForTracking.load(cascadeFilename)) {
|
||||
CV_Error(CV_StsBadArg, "DetectionBasedTracker::DetectionBasedTracker: Cannot load a cascade from the file '"+cascadeFilename+"'");
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ void DetectionBasedTracker::process(const Mat& imageGray)
|
||||
Mat imageDetect=imageGray;
|
||||
|
||||
int D=parameters.minObjectSize;
|
||||
if (D < 1)
|
||||
if (D < 1)
|
||||
D=1;
|
||||
|
||||
vector<Rect> rectsWhereRegions;
|
||||
@@ -633,7 +633,7 @@ void DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detectedObj
|
||||
LOGD("DetectionBasedTracker::updateTrackedObjects: j=%d is rejected, because it is intersected with another rectangle", j);
|
||||
continue;
|
||||
}
|
||||
LOGD("DetectionBasedTracker::updateTrackedObjects: detectedObjects[%d]={%d, %d, %d x %d}",
|
||||
LOGD("DetectionBasedTracker::updateTrackedObjects: detectedObjects[%d]={%d, %d, %d x %d}",
|
||||
j, detectedObjects[j].x, detectedObjects[j].y, detectedObjects[j].width, detectedObjects[j].height);
|
||||
|
||||
Rect r=prevRect & detectedObjects[j];
|
||||
@@ -691,9 +691,9 @@ void DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detectedObj
|
||||
|
||||
std::vector<TrackedObject>::iterator it=trackedObjects.begin();
|
||||
while( it != trackedObjects.end() ) {
|
||||
if ( (it->numFramesNotDetected > parameters.maxTrackLifetime)
|
||||
if ( (it->numFramesNotDetected > parameters.maxTrackLifetime)
|
||||
||
|
||||
(
|
||||
(
|
||||
(it->numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow)
|
||||
&&
|
||||
(it->numFramesNotDetected > innerParameters.numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown)
|
||||
@@ -718,7 +718,7 @@ Rect DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const
|
||||
return Rect();
|
||||
}
|
||||
if (trackedObjects[i].numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow){
|
||||
LOGI("DetectionBasedTracker::calcTrackedObjectPositionToShow: trackedObjects[%d].numDetectedFrames=%d <= numStepsToWaitBeforeFirstShow=%d --- return empty Rect()",
|
||||
LOGI("DetectionBasedTracker::calcTrackedObjectPositionToShow: trackedObjects[%d].numDetectedFrames=%d <= numStepsToWaitBeforeFirstShow=%d --- return empty Rect()",
|
||||
i, trackedObjects[i].numDetectedFrames, innerParameters.numStepsToWaitBeforeFirstShow);
|
||||
return Rect();
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
using namespace cv;
|
||||
|
||||
void downsamplePoints( const Mat& src, Mat& dst, size_t count )
|
||||
static void downsamplePoints( const Mat& src, Mat& dst, size_t count )
|
||||
{
|
||||
CV_Assert( count >= 2 );
|
||||
CV_Assert( src.cols == 1 || src.rows == 1 );
|
||||
|
||||
+102
-102
@@ -28,7 +28,7 @@ using std::map;
|
||||
using std::set;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
// Removes duplicate elements in a given vector.
|
||||
template<typename _Tp>
|
||||
inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
||||
@@ -42,7 +42,7 @@ inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
||||
elems.push_back(*it);
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
static Mat argsort(InputArray _src, bool ascending=true)
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
@@ -72,8 +72,8 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) {
|
||||
|
||||
static void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) {
|
||||
if(_indices.getMat().type() != CV_32SC1)
|
||||
CV_Error(CV_StsUnsupportedFormat, "cv::sortColumnsByIndices only works on integer indices!");
|
||||
Mat src = _src.getMat();
|
||||
@@ -87,13 +87,13 @@ void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArra
|
||||
}
|
||||
}
|
||||
|
||||
Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices) {
|
||||
static Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices) {
|
||||
Mat dst;
|
||||
sortMatrixColumnsByIndices(src, indices, dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename _Tp> static bool
|
||||
isSymmetric_(InputArray src) {
|
||||
Mat _src = src.getMat();
|
||||
@@ -151,7 +151,7 @@ static bool isSymmetric(InputArray src, double eps=1e-16)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// subspace::project
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -198,32 +198,32 @@ Mat subspaceReconstruct(InputArray _W, InputArray _mean, InputArray _src)
|
||||
return X;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class EigenvalueDecomposition {
|
||||
private:
|
||||
|
||||
|
||||
// Holds the data dimension.
|
||||
int n;
|
||||
|
||||
|
||||
// Stores real/imag part of a complex division.
|
||||
double cdivr, cdivi;
|
||||
|
||||
|
||||
// Pointer to internal memory.
|
||||
double *d, *e, *ort;
|
||||
double **V, **H;
|
||||
|
||||
|
||||
// Holds the computed eigenvalues.
|
||||
Mat _eigenvalues;
|
||||
|
||||
|
||||
// Holds the computed eigenvectors.
|
||||
Mat _eigenvectors;
|
||||
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp *alloc_1d(int m) {
|
||||
return new _Tp[m];
|
||||
}
|
||||
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp *alloc_1d(int m, _Tp val) {
|
||||
@@ -232,7 +232,7 @@ private:
|
||||
arr[i] = val;
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp **alloc_2d(int m, int n) {
|
||||
@@ -241,7 +241,7 @@ private:
|
||||
arr[i] = new _Tp[n];
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp **alloc_2d(int m, int n, _Tp val) {
|
||||
@@ -253,7 +253,7 @@ private:
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
void cdiv(double xr, double xi, double yr, double yi) {
|
||||
double r, d;
|
||||
if (std::abs(yr) > std::abs(yi)) {
|
||||
@@ -268,16 +268,16 @@ private:
|
||||
cdivi = (r * xi - xr) / d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Nonsymmetric reduction from Hessenberg to real Schur form.
|
||||
|
||||
|
||||
void hqr2() {
|
||||
|
||||
|
||||
// This is derived from the Algol procedure hqr2,
|
||||
// by Martin and Wilkinson, Handbook for Auto. Comp.,
|
||||
// Vol.ii-Linear Algebra, and the corresponding
|
||||
// Fortran subroutine in EISPACK.
|
||||
|
||||
|
||||
// Initialize
|
||||
int nn = this->n;
|
||||
int n = nn - 1;
|
||||
@@ -286,9 +286,9 @@ private:
|
||||
double eps = pow(2.0, -52.0);
|
||||
double exshift = 0.0;
|
||||
double p = 0, q = 0, r = 0, s = 0, z = 0, t, w, x, y;
|
||||
|
||||
|
||||
// Store roots isolated by balanc and compute matrix norm
|
||||
|
||||
|
||||
double norm = 0.0;
|
||||
for (int i = 0; i < nn; i++) {
|
||||
if (i < low || i > high) {
|
||||
@@ -299,11 +299,11 @@ private:
|
||||
norm = norm + std::abs(H[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Outer loop over eigenvalue index
|
||||
int iter = 0;
|
||||
while (n >= low) {
|
||||
|
||||
|
||||
// Look for single small sub-diagonal element
|
||||
int l = n;
|
||||
while (l > low) {
|
||||
@@ -316,19 +316,19 @@ private:
|
||||
}
|
||||
l--;
|
||||
}
|
||||
|
||||
|
||||
// Check for convergence
|
||||
// One root found
|
||||
|
||||
|
||||
if (l == n) {
|
||||
H[n][n] = H[n][n] + exshift;
|
||||
d[n] = H[n][n];
|
||||
e[n] = 0.0;
|
||||
n--;
|
||||
iter = 0;
|
||||
|
||||
|
||||
// Two roots found
|
||||
|
||||
|
||||
} else if (l == n - 1) {
|
||||
w = H[n][n - 1] * H[n - 1][n];
|
||||
p = (H[n - 1][n - 1] - H[n][n]) / 2.0;
|
||||
@@ -337,9 +337,9 @@ private:
|
||||
H[n][n] = H[n][n] + exshift;
|
||||
H[n - 1][n - 1] = H[n - 1][n - 1] + exshift;
|
||||
x = H[n][n];
|
||||
|
||||
|
||||
// Real pair
|
||||
|
||||
|
||||
if (q >= 0) {
|
||||
if (p >= 0) {
|
||||
z = p + z;
|
||||
@@ -360,33 +360,33 @@ private:
|
||||
r = sqrt(p * p + q * q);
|
||||
p = p / r;
|
||||
q = q / r;
|
||||
|
||||
|
||||
// Row modification
|
||||
|
||||
|
||||
for (int j = n - 1; j < nn; j++) {
|
||||
z = H[n - 1][j];
|
||||
H[n - 1][j] = q * z + p * H[n][j];
|
||||
H[n][j] = q * H[n][j] - p * z;
|
||||
}
|
||||
|
||||
|
||||
// Column modification
|
||||
|
||||
|
||||
for (int i = 0; i <= n; i++) {
|
||||
z = H[i][n - 1];
|
||||
H[i][n - 1] = q * z + p * H[i][n];
|
||||
H[i][n] = q * H[i][n] - p * z;
|
||||
}
|
||||
|
||||
|
||||
// Accumulate transformations
|
||||
|
||||
|
||||
for (int i = low; i <= high; i++) {
|
||||
z = V[i][n - 1];
|
||||
V[i][n - 1] = q * z + p * V[i][n];
|
||||
V[i][n] = q * V[i][n] - p * z;
|
||||
}
|
||||
|
||||
|
||||
// Complex pair
|
||||
|
||||
|
||||
} else {
|
||||
d[n - 1] = x + p;
|
||||
d[n] = x + p;
|
||||
@@ -395,13 +395,13 @@ private:
|
||||
}
|
||||
n = n - 2;
|
||||
iter = 0;
|
||||
|
||||
|
||||
// No convergence yet
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// Form shift
|
||||
|
||||
|
||||
x = H[n][n];
|
||||
y = 0.0;
|
||||
w = 0.0;
|
||||
@@ -409,9 +409,9 @@ private:
|
||||
y = H[n - 1][n - 1];
|
||||
w = H[n][n - 1] * H[n - 1][n];
|
||||
}
|
||||
|
||||
|
||||
// Wilkinson's original ad hoc shift
|
||||
|
||||
|
||||
if (iter == 10) {
|
||||
exshift += x;
|
||||
for (int i = low; i <= n; i++) {
|
||||
@@ -421,9 +421,9 @@ private:
|
||||
x = y = 0.75 * s;
|
||||
w = -0.4375 * s * s;
|
||||
}
|
||||
|
||||
|
||||
// MATLAB's new ad hoc shift
|
||||
|
||||
|
||||
if (iter == 30) {
|
||||
s = (y - x) / 2.0;
|
||||
s = s * s + w;
|
||||
@@ -440,9 +440,9 @@ private:
|
||||
x = y = w = 0.964;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
iter = iter + 1; // (Could check iteration count here.)
|
||||
|
||||
|
||||
// Look for two consecutive small sub-diagonal elements
|
||||
int m = n - 2;
|
||||
while (m >= l) {
|
||||
@@ -466,16 +466,16 @@ private:
|
||||
}
|
||||
m--;
|
||||
}
|
||||
|
||||
|
||||
for (int i = m + 2; i <= n; i++) {
|
||||
H[i][i - 2] = 0.0;
|
||||
if (i > m + 2) {
|
||||
H[i][i - 3] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Double QR step involving rows l:n and columns m:n
|
||||
|
||||
|
||||
for (int k = m; k <= n - 1; k++) {
|
||||
bool notlast = (k != n - 1);
|
||||
if (k != m) {
|
||||
@@ -508,9 +508,9 @@ private:
|
||||
z = r / s;
|
||||
q = q / p;
|
||||
r = r / p;
|
||||
|
||||
|
||||
// Row modification
|
||||
|
||||
|
||||
for (int j = k; j < nn; j++) {
|
||||
p = H[k][j] + q * H[k + 1][j];
|
||||
if (notlast) {
|
||||
@@ -520,9 +520,9 @@ private:
|
||||
H[k][j] = H[k][j] - p * x;
|
||||
H[k + 1][j] = H[k + 1][j] - p * y;
|
||||
}
|
||||
|
||||
|
||||
// Column modification
|
||||
|
||||
|
||||
for (int i = 0; i <= min(n, k + 3); i++) {
|
||||
p = x * H[i][k] + y * H[i][k + 1];
|
||||
if (notlast) {
|
||||
@@ -532,9 +532,9 @@ private:
|
||||
H[i][k] = H[i][k] - p;
|
||||
H[i][k + 1] = H[i][k + 1] - p * q;
|
||||
}
|
||||
|
||||
|
||||
// Accumulate transformations
|
||||
|
||||
|
||||
for (int i = low; i <= high; i++) {
|
||||
p = x * V[i][k] + y * V[i][k + 1];
|
||||
if (notlast) {
|
||||
@@ -548,19 +548,19 @@ private:
|
||||
} // k loop
|
||||
} // check convergence
|
||||
} // while (n >= low)
|
||||
|
||||
|
||||
// Backsubstitute to find vectors of upper triangular form
|
||||
|
||||
|
||||
if (norm == 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (n = nn - 1; n >= 0; n--) {
|
||||
p = d[n];
|
||||
q = e[n];
|
||||
|
||||
|
||||
// Real vector
|
||||
|
||||
|
||||
if (q == 0) {
|
||||
int l = n;
|
||||
H[n][n] = 1.0;
|
||||
@@ -581,9 +581,9 @@ private:
|
||||
} else {
|
||||
H[i][n] = -r / (eps * norm);
|
||||
}
|
||||
|
||||
|
||||
// Solve real equations
|
||||
|
||||
|
||||
} else {
|
||||
x = H[i][i + 1];
|
||||
y = H[i + 1][i];
|
||||
@@ -596,9 +596,9 @@ private:
|
||||
H[i + 1][n] = (-s - y * t) / z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Overflow control
|
||||
|
||||
|
||||
t = std::abs(H[i][n]);
|
||||
if ((eps * t) * t > 1) {
|
||||
for (int j = i; j <= n; j++) {
|
||||
@@ -607,14 +607,14 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Complex vector
|
||||
|
||||
|
||||
} else if (q < 0) {
|
||||
int l = n - 1;
|
||||
|
||||
|
||||
// Last vector component imaginary so matrix is triangular
|
||||
|
||||
|
||||
if (std::abs(H[n][n - 1]) > std::abs(H[n - 1][n])) {
|
||||
H[n - 1][n - 1] = q / H[n][n - 1];
|
||||
H[n - 1][n] = -(H[n][n] - p) / H[n][n - 1];
|
||||
@@ -634,7 +634,7 @@ private:
|
||||
sa = sa + H[i][j] * H[j][n];
|
||||
}
|
||||
w = H[i][i] - p;
|
||||
|
||||
|
||||
if (e[i] < 0.0) {
|
||||
z = w;
|
||||
r = ra;
|
||||
@@ -646,9 +646,9 @@ private:
|
||||
H[i][n - 1] = cdivr;
|
||||
H[i][n] = cdivi;
|
||||
} else {
|
||||
|
||||
|
||||
// Solve complex equations
|
||||
|
||||
|
||||
x = H[i][i + 1];
|
||||
y = H[i + 1][i];
|
||||
vr = (d[i] - p) * (d[i] - p) + e[i] * e[i] - q * q;
|
||||
@@ -673,9 +673,9 @@ private:
|
||||
H[i + 1][n] = cdivi;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Overflow control
|
||||
|
||||
|
||||
t = max(std::abs(H[i][n - 1]), std::abs(H[i][n]));
|
||||
if ((eps * t) * t > 1) {
|
||||
for (int j = i; j <= n; j++) {
|
||||
@@ -687,9 +687,9 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Vectors of isolated roots
|
||||
|
||||
|
||||
for (int i = 0; i < nn; i++) {
|
||||
if (i < low || i > high) {
|
||||
for (int j = i; j < nn; j++) {
|
||||
@@ -697,9 +697,9 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Back transformation to get eigenvectors of original matrix
|
||||
|
||||
|
||||
for (int j = nn - 1; j >= low; j--) {
|
||||
for (int i = low; i <= high; i++) {
|
||||
z = 0.0;
|
||||
@@ -710,7 +710,7 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Nonsymmetric reduction to Hessenberg form.
|
||||
void orthes() {
|
||||
// This is derived from the Algol procedures orthes and ortran,
|
||||
@@ -719,19 +719,19 @@ private:
|
||||
// Fortran subroutines in EISPACK.
|
||||
int low = 0;
|
||||
int high = n - 1;
|
||||
|
||||
|
||||
for (int m = low + 1; m <= high - 1; m++) {
|
||||
|
||||
|
||||
// Scale column.
|
||||
|
||||
|
||||
double scale = 0.0;
|
||||
for (int i = m; i <= high; i++) {
|
||||
scale = scale + std::abs(H[i][m - 1]);
|
||||
}
|
||||
if (scale != 0.0) {
|
||||
|
||||
|
||||
// Compute Householder transformation.
|
||||
|
||||
|
||||
double h = 0.0;
|
||||
for (int i = high; i >= m; i--) {
|
||||
ort[i] = H[i][m - 1] / scale;
|
||||
@@ -743,10 +743,10 @@ private:
|
||||
}
|
||||
h = h - ort[m] * g;
|
||||
ort[m] = ort[m] - g;
|
||||
|
||||
|
||||
// Apply Householder similarity transformation
|
||||
// H = (I-u*u'/h)*H*(I-u*u')/h)
|
||||
|
||||
|
||||
for (int j = m; j < n; j++) {
|
||||
double f = 0.0;
|
||||
for (int i = high; i >= m; i--) {
|
||||
@@ -757,7 +757,7 @@ private:
|
||||
H[i][j] -= f * ort[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i <= high; i++) {
|
||||
double f = 0.0;
|
||||
for (int j = high; j >= m; j--) {
|
||||
@@ -772,15 +772,15 @@ private:
|
||||
H[m][m - 1] = scale * g;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Accumulate transformations (Algol's ortran).
|
||||
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
V[i][j] = (i == j ? 1.0 : 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int m = high - 1; m >= low + 1; m--) {
|
||||
if (H[m][m - 1] != 0.0) {
|
||||
for (int i = m + 1; i <= high; i++) {
|
||||
@@ -800,7 +800,7 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Releases all internal working memory.
|
||||
void release() {
|
||||
// releases the working data
|
||||
@@ -814,7 +814,7 @@ private:
|
||||
delete[] H;
|
||||
delete[] V;
|
||||
}
|
||||
|
||||
|
||||
// Computes the Eigenvalue Decomposition for a matrix given in H.
|
||||
void compute() {
|
||||
// Allocate memory for the working data.
|
||||
@@ -839,11 +839,11 @@ private:
|
||||
// Deallocate the memory by releasing all internal working data.
|
||||
release();
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
EigenvalueDecomposition()
|
||||
: n(0) { }
|
||||
|
||||
|
||||
// Initializes & computes the Eigenvalue Decomposition for a general matrix
|
||||
// given in src. This function is a port of the EigenvalueSolver in JAMA,
|
||||
// which has been released to public domain by The MathWorks and the
|
||||
@@ -851,7 +851,7 @@ public:
|
||||
EigenvalueDecomposition(InputArray src) {
|
||||
compute(src);
|
||||
}
|
||||
|
||||
|
||||
// This function computes the Eigenvalue Decomposition for a general matrix
|
||||
// given in src. This function is a port of the EigenvalueSolver in JAMA,
|
||||
// which has been released to public domain by The MathWorks and the
|
||||
@@ -883,9 +883,9 @@ public:
|
||||
compute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
~EigenvalueDecomposition() {}
|
||||
|
||||
|
||||
// Returns the eigenvalues of the Eigenvalue Decomposition.
|
||||
Mat eigenvalues() { return _eigenvalues; }
|
||||
// Returns the eigenvectors of the Eigenvalue Decomposition.
|
||||
@@ -1045,6 +1045,6 @@ Mat LDA::project(InputArray src) {
|
||||
Mat LDA::reconstruct(InputArray src) {
|
||||
return subspaceReconstruct(_eigenvectors, Mat(), _dataAsRow ? src : src.getMat().t());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,98 +43,99 @@
|
||||
#include "precomp.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace cv
|
||||
namespace
|
||||
{
|
||||
using namespace cv;
|
||||
const size_t MAX_STACK_SIZE = 255;
|
||||
const size_t MAX_LEAFS = 8;
|
||||
|
||||
|
||||
bool checkIfNodeOutsideSphere(const Octree::Node& node, const Point3f& c, float r)
|
||||
{
|
||||
if (node.x_max < (c.x - r) || node.y_max < (c.y - r) || node.z_max < (c.z - r))
|
||||
return true;
|
||||
|
||||
|
||||
if ((c.x + r) < node.x_min || (c.y + r) < node.y_min || (c.z + r) < node.z_min)
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool checkIfNodeInsideSphere(const Octree::Node& node, const Point3f& c, float r)
|
||||
{
|
||||
r *= r;
|
||||
|
||||
|
||||
float d2_xmin = (node.x_min - c.x) * (node.x_min - c.x);
|
||||
float d2_ymin = (node.y_min - c.y) * (node.y_min - c.y);
|
||||
float d2_zmin = (node.z_min - c.z) * (node.z_min - c.z);
|
||||
|
||||
|
||||
if (d2_xmin + d2_ymin + d2_zmin > r)
|
||||
return false;
|
||||
|
||||
|
||||
float d2_zmax = (node.z_max - c.z) * (node.z_max - c.z);
|
||||
|
||||
|
||||
if (d2_xmin + d2_ymin + d2_zmax > r)
|
||||
return false;
|
||||
|
||||
|
||||
float d2_ymax = (node.y_max - c.y) * (node.y_max - c.y);
|
||||
|
||||
|
||||
if (d2_xmin + d2_ymax + d2_zmin > r)
|
||||
return false;
|
||||
|
||||
|
||||
if (d2_xmin + d2_ymax + d2_zmax > r)
|
||||
return false;
|
||||
|
||||
|
||||
float d2_xmax = (node.x_max - c.x) * (node.x_max - c.x);
|
||||
|
||||
|
||||
if (d2_xmax + d2_ymin + d2_zmin > r)
|
||||
return false;
|
||||
|
||||
|
||||
if (d2_xmax + d2_ymin + d2_zmax > r)
|
||||
return false;
|
||||
|
||||
|
||||
if (d2_xmax + d2_ymax + d2_zmin > r)
|
||||
return false;
|
||||
|
||||
|
||||
if (d2_xmax + d2_ymax + d2_zmax > r)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void fillMinMax(const vector<Point3f>& points, Octree::Node& node)
|
||||
{
|
||||
node.x_max = node.y_max = node.z_max = std::numeric_limits<float>::min();
|
||||
node.x_min = node.y_min = node.z_min = std::numeric_limits<float>::max();
|
||||
|
||||
|
||||
for (size_t i = 0; i < points.size(); ++i)
|
||||
{
|
||||
const Point3f& point = points[i];
|
||||
|
||||
|
||||
if (node.x_max < point.x)
|
||||
node.x_max = point.x;
|
||||
|
||||
|
||||
if (node.y_max < point.y)
|
||||
node.y_max = point.y;
|
||||
|
||||
|
||||
if (node.z_max < point.z)
|
||||
node.z_max = point.z;
|
||||
|
||||
|
||||
if (node.x_min > point.x)
|
||||
node.x_min = point.x;
|
||||
|
||||
|
||||
if (node.y_min > point.y)
|
||||
node.y_min = point.y;
|
||||
|
||||
|
||||
if (node.z_min > point.z)
|
||||
node.z_min = point.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t findSubboxForPoint(const Point3f& point, const Octree::Node& node)
|
||||
{
|
||||
size_t ind_x = point.x < (node.x_max + node.x_min) / 2 ? 0 : 1;
|
||||
size_t ind_y = point.y < (node.y_max + node.y_min) / 2 ? 0 : 1;
|
||||
size_t ind_z = point.z < (node.z_max + node.z_min) / 2 ? 0 : 1;
|
||||
|
||||
|
||||
return (ind_x << 2) + (ind_y << 1) + (ind_z << 0);
|
||||
}
|
||||
void initChildBox(const Octree::Node& parent, size_t boxIndex, Octree::Node& child)
|
||||
@@ -142,58 +143,61 @@ namespace cv
|
||||
child.x_min = child.x_max = (parent.x_max + parent.x_min) / 2;
|
||||
child.y_min = child.y_max = (parent.y_max + parent.y_min) / 2;
|
||||
child.z_min = child.z_max = (parent.z_max + parent.z_min) / 2;
|
||||
|
||||
|
||||
if ((boxIndex >> 0) & 1)
|
||||
child.z_max = parent.z_max;
|
||||
else
|
||||
child.z_min = parent.z_min;
|
||||
|
||||
|
||||
if ((boxIndex >> 1) & 1)
|
||||
child.y_max = parent.y_max;
|
||||
else
|
||||
child.y_min = parent.y_min;
|
||||
|
||||
|
||||
if ((boxIndex >> 2) & 1)
|
||||
child.x_max = parent.x_max;
|
||||
else
|
||||
child.x_min = parent.x_min;
|
||||
}
|
||||
|
||||
|
||||
}//namespace
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////// Octree //////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace cv
|
||||
{
|
||||
Octree::Octree()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Octree::Octree(const vector<Point3f>& points3d, int maxLevels, int minPoints)
|
||||
{
|
||||
buildTree(points3d, maxLevels, minPoints);
|
||||
}
|
||||
|
||||
|
||||
Octree::~Octree()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Octree::getPointsWithinSphere(const Point3f& center, float radius, vector<Point3f>& out) const
|
||||
{
|
||||
out.clear();
|
||||
|
||||
|
||||
if (nodes.empty())
|
||||
return;
|
||||
|
||||
|
||||
int stack[MAX_STACK_SIZE];
|
||||
int pos = 0;
|
||||
stack[pos] = 0;
|
||||
|
||||
|
||||
while (pos >= 0)
|
||||
{
|
||||
const Node& cur = nodes[stack[pos--]];
|
||||
|
||||
|
||||
if (checkIfNodeOutsideSphere(cur, center, radius))
|
||||
continue;
|
||||
|
||||
|
||||
if (checkIfNodeInsideSphere(cur, center, radius))
|
||||
{
|
||||
size_t sz = out.size();
|
||||
@@ -202,133 +206,133 @@ namespace cv
|
||||
out[sz++] = points[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (cur.isLeaf)
|
||||
{
|
||||
double r2 = radius * radius;
|
||||
size_t sz = out.size();
|
||||
out.resize(sz + (cur.end - cur.begin));
|
||||
|
||||
|
||||
for (int i = cur.begin; i < cur.end; ++i)
|
||||
{
|
||||
const Point3f& point = points[i];
|
||||
|
||||
|
||||
double dx = (point.x - center.x);
|
||||
double dy = (point.y - center.y);
|
||||
double dz = (point.z - center.z);
|
||||
|
||||
|
||||
double dist2 = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
|
||||
if (dist2 < r2)
|
||||
out[sz++] = point;
|
||||
};
|
||||
out.resize(sz);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (cur.children[0])
|
||||
stack[++pos] = cur.children[0];
|
||||
|
||||
|
||||
if (cur.children[1])
|
||||
stack[++pos] = cur.children[1];
|
||||
|
||||
|
||||
if (cur.children[2])
|
||||
stack[++pos] = cur.children[2];
|
||||
|
||||
|
||||
if (cur.children[3])
|
||||
stack[++pos] = cur.children[3];
|
||||
|
||||
|
||||
if (cur.children[4])
|
||||
stack[++pos] = cur.children[4];
|
||||
|
||||
|
||||
if (cur.children[5])
|
||||
stack[++pos] = cur.children[5];
|
||||
|
||||
|
||||
if (cur.children[6])
|
||||
stack[++pos] = cur.children[6];
|
||||
|
||||
|
||||
if (cur.children[7])
|
||||
stack[++pos] = cur.children[7];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Octree::buildTree(const vector<Point3f>& points3d, int maxLevels, int minPoints)
|
||||
{
|
||||
assert((size_t)maxLevels * 8 < MAX_STACK_SIZE);
|
||||
points.resize(points3d.size());
|
||||
std::copy(points3d.begin(), points3d.end(), points.begin());
|
||||
this->minPoints = minPoints;
|
||||
|
||||
|
||||
nodes.clear();
|
||||
nodes.push_back(Node());
|
||||
Node& root = nodes[0];
|
||||
fillMinMax(points, root);
|
||||
|
||||
|
||||
root.isLeaf = true;
|
||||
root.maxLevels = maxLevels;
|
||||
root.begin = 0;
|
||||
root.end = (int)points.size();
|
||||
for (size_t i = 0; i < MAX_LEAFS; i++)
|
||||
root.children[i] = 0;
|
||||
|
||||
|
||||
if (maxLevels != 1 && (root.end - root.begin) > minPoints)
|
||||
{
|
||||
root.isLeaf = false;
|
||||
buildNext(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Octree::buildNext(size_t nodeInd)
|
||||
{
|
||||
size_t size = nodes[nodeInd].end - nodes[nodeInd].begin;
|
||||
|
||||
|
||||
vector<size_t> boxBorders(MAX_LEAFS+1, 0);
|
||||
vector<size_t> boxIndices(size);
|
||||
vector<Point3f> tempPoints(size);
|
||||
|
||||
|
||||
for (int i = nodes[nodeInd].begin, j = 0; i < nodes[nodeInd].end; ++i, ++j)
|
||||
{
|
||||
const Point3f& p = points[i];
|
||||
|
||||
|
||||
size_t subboxInd = findSubboxForPoint(p, nodes[nodeInd]);
|
||||
|
||||
|
||||
boxBorders[subboxInd+1]++;
|
||||
boxIndices[j] = subboxInd;
|
||||
tempPoints[j] = p;
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 1; i < boxBorders.size(); ++i)
|
||||
boxBorders[i] += boxBorders[i-1];
|
||||
|
||||
|
||||
vector<size_t> writeInds(boxBorders.begin(), boxBorders.end());
|
||||
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
size_t boxIndex = boxIndices[i];
|
||||
Point3f& curPoint = tempPoints[i];
|
||||
|
||||
|
||||
size_t copyTo = nodes[nodeInd].begin + writeInds[boxIndex]++;
|
||||
points[copyTo] = curPoint;
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 0; i < MAX_LEAFS; ++i)
|
||||
{
|
||||
if (boxBorders[i] == boxBorders[i+1])
|
||||
continue;
|
||||
|
||||
|
||||
nodes.push_back(Node());
|
||||
Node& child = nodes.back();
|
||||
initChildBox(nodes[nodeInd], i, child);
|
||||
|
||||
|
||||
child.isLeaf = true;
|
||||
child.maxLevels = nodes[nodeInd].maxLevels - 1;
|
||||
child.begin = nodes[nodeInd].begin + (int)boxBorders[i+0];
|
||||
child.end = nodes[nodeInd].begin + (int)boxBorders[i+1];
|
||||
for (size_t k = 0; k < MAX_LEAFS; k++)
|
||||
child.children[k] = 0;
|
||||
|
||||
|
||||
nodes[nodeInd].children[i] = (int)(nodes.size() - 1);
|
||||
|
||||
|
||||
if (child.maxLevels != 1 && (child.end - child.begin) > minPoints)
|
||||
{
|
||||
child.isLeaf = false;
|
||||
@@ -336,5 +340,5 @@ namespace cv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1299,6 +1299,7 @@ public:
|
||||
GPU_MAT = 9 << KIND_SHIFT
|
||||
};
|
||||
_InputArray();
|
||||
|
||||
_InputArray(const Mat& m);
|
||||
_InputArray(const MatExpr& expr);
|
||||
template<typename _Tp> _InputArray(const _Tp* vec, int n);
|
||||
@@ -1328,6 +1329,8 @@ public:
|
||||
virtual int channels(int i=-1) const;
|
||||
virtual bool empty() const;
|
||||
|
||||
virtual ~_InputArray();
|
||||
|
||||
int flags;
|
||||
void* obj;
|
||||
Size sz;
|
||||
@@ -1384,6 +1387,8 @@ public:
|
||||
virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void release() const;
|
||||
virtual void clear() const;
|
||||
|
||||
virtual ~_OutputArray();
|
||||
};
|
||||
|
||||
typedef const _InputArray& InputArray;
|
||||
@@ -3977,7 +3982,7 @@ public:
|
||||
CV_WRAP virtual bool isOpened() const;
|
||||
//! closes the file and releases all the memory buffers
|
||||
CV_WRAP virtual void release();
|
||||
//! closes the file, releases all the memory buffers and returns the text string
|
||||
//! closes the file, releases all the memory buffers and returns the text string
|
||||
CV_WRAP virtual string releaseAndGetString();
|
||||
|
||||
//! returns the first element of the top-level mapping
|
||||
|
||||
@@ -60,34 +60,34 @@
|
||||
#endif
|
||||
|
||||
#if defined WIN32 || defined WINCE
|
||||
#ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)
|
||||
#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#undef small
|
||||
#undef min
|
||||
#undef max
|
||||
# ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)
|
||||
# define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# undef small
|
||||
# undef min
|
||||
# undef max
|
||||
#else
|
||||
#include <pthread.h>
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#ifndef WIN32
|
||||
#define WIN32
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#define _WIN32
|
||||
#endif
|
||||
#define CV_DLL
|
||||
#undef _CV_ALWAYS_PROFILE_
|
||||
#define _CV_ALWAYS_NO_PROFILE_
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
# ifndef _WIN32
|
||||
# define _WIN32
|
||||
# endif
|
||||
# define CV_DLL
|
||||
# undef _CV_ALWAYS_PROFILE_
|
||||
# define _CV_ALWAYS_NO_PROFILE_
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
# define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
# define TRUE 1
|
||||
#endif
|
||||
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
@@ -95,7 +95,7 @@
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
#include "ipp.h"
|
||||
# include "ipp.h"
|
||||
|
||||
CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
{
|
||||
@@ -104,137 +104,132 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined __SSE2__ || _MSC_VER >= 1300
|
||||
#include "emmintrin.h"
|
||||
#define CV_SSE 1
|
||||
#define CV_SSE2 1
|
||||
#if defined __SSE3__ || _MSC_VER >= 1500
|
||||
#include "pmmintrin.h"
|
||||
#define CV_SSE3 1
|
||||
#endif
|
||||
#if defined __SSSE3__
|
||||
#include "tmmintrin.h"
|
||||
#define CV_SSSE3 1
|
||||
#endif
|
||||
#if defined __SSE2__ || (defined _MSC_VER && _MSC_VER >= 1300)
|
||||
# include "emmintrin.h"
|
||||
# define CV_SSE 1
|
||||
# define CV_SSE2 1
|
||||
# if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include "pmmintrin.h"
|
||||
# define CV_SSE3 1
|
||||
# else
|
||||
# define CV_SSE3 0
|
||||
# endif
|
||||
# if defined __SSSE3__
|
||||
# include "tmmintrin.h"
|
||||
# define CV_SSSE3 1
|
||||
# else
|
||||
# define CV_SSSE3 0
|
||||
# endif
|
||||
#else
|
||||
#define CV_SSE 0
|
||||
#define CV_SSE2 0
|
||||
#define CV_SSE3 0
|
||||
#define CV_SSSE3 0
|
||||
# define CV_SSE 0
|
||||
# define CV_SSE2 0
|
||||
# define CV_SSE3 0
|
||||
# define CV_SSSE3 0
|
||||
#endif
|
||||
|
||||
#if defined ANDROID && defined __ARM_NEON__ && defined __GNUC__
|
||||
#include "arm_neon.h"
|
||||
#define CV_NEON 1
|
||||
#if defined ANDROID && defined __ARM_NEON__
|
||||
# include "arm_neon.h"
|
||||
# define CV_NEON 1
|
||||
|
||||
#define CPU_HAS_NEON_FEATURE (true)
|
||||
# define CPU_HAS_NEON_FEATURE (true)
|
||||
//TODO: make real check using stuff from "cpu-features.h"
|
||||
//((bool)android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON)
|
||||
#else
|
||||
#define CV_NEON 0
|
||||
#define CPU_HAS_NEON_FEATURE (false)
|
||||
#endif
|
||||
|
||||
#ifdef CV_ICC
|
||||
#define CV_ENABLE_UNROLLED 0
|
||||
#else
|
||||
#define CV_ENABLE_UNROLLED 1
|
||||
# define CV_NEON 0
|
||||
# define CPU_HAS_NEON_FEATURE (false)
|
||||
#endif
|
||||
|
||||
#ifndef IPPI_CALL
|
||||
#define IPPI_CALL(func) CV_Assert((func) >= 0)
|
||||
# define IPPI_CALL(func) CV_Assert((func) >= 0)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/tbb_stddef.h"
|
||||
#if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
|
||||
#include "tbb/tbb.h"
|
||||
#include "tbb/task.h"
|
||||
#undef min
|
||||
#undef max
|
||||
#else
|
||||
#undef HAVE_TBB
|
||||
#endif
|
||||
# include "tbb/tbb_stddef.h"
|
||||
# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
|
||||
# include "tbb/tbb.h"
|
||||
# include "tbb/task.h"
|
||||
# undef min
|
||||
# undef max
|
||||
# else
|
||||
# undef HAVE_TBB
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
#include <Eigen/Core>
|
||||
#include "opencv2/core/eigen.hpp"
|
||||
# include <Eigen/Core>
|
||||
# include "opencv2/core/eigen.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace cv
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
namespace cv
|
||||
{
|
||||
typedef tbb::blocked_range<int> BlockedRange;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
tbb::parallel_for(range, body);
|
||||
}
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
tbb::parallel_do(first, last, body);
|
||||
}
|
||||
|
||||
typedef tbb::split Split;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
tbb::parallel_reduce(range, body);
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
|
||||
typedef tbb::concurrent_vector<double> ConcurrentDoubleVector;
|
||||
}
|
||||
#else
|
||||
namespace cv
|
||||
{
|
||||
class BlockedRange
|
||||
{
|
||||
public:
|
||||
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
|
||||
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
|
||||
int begin() const { return _begin; }
|
||||
int end() const { return _end; }
|
||||
int grainsize() const { return _grainsize; }
|
||||
|
||||
protected:
|
||||
int _begin, _end, _grainsize;
|
||||
};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
typedef std::vector<Rect> ConcurrentRectVector;
|
||||
typedef std::vector<double> ConcurrentDoubleVector;
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
for( ; first != last; ++first )
|
||||
body(*first);
|
||||
}
|
||||
|
||||
class Split {};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
|
||||
typedef tbb::blocked_range<int> BlockedRange;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
tbb::parallel_for(range, body);
|
||||
}
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
tbb::parallel_do(first, last, body);
|
||||
}
|
||||
|
||||
typedef tbb::split Split;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
tbb::parallel_reduce(range, body);
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
|
||||
typedef tbb::concurrent_vector<double> ConcurrentDoubleVector;
|
||||
#else
|
||||
class BlockedRange
|
||||
{
|
||||
public:
|
||||
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
|
||||
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
|
||||
int begin() const { return _begin; }
|
||||
int end() const { return _end; }
|
||||
int grainsize() const { return _grainsize; }
|
||||
|
||||
protected:
|
||||
int _begin, _end, _grainsize;
|
||||
};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
typedef std::vector<Rect> ConcurrentRectVector;
|
||||
typedef std::vector<double> ConcurrentDoubleVector;
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
for( ; first != last; ++first )
|
||||
body(*first);
|
||||
}
|
||||
|
||||
class Split {};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
#endif
|
||||
} //namespace cv
|
||||
|
||||
#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
|
||||
#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
|
||||
static Algorithm* create##classname() \
|
||||
{ \
|
||||
return new classname; \
|
||||
@@ -261,7 +256,7 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
return &classname##_info(); \
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif //__cplusplus
|
||||
|
||||
/* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */
|
||||
#define CV_MAX_INLINE_MAT_OP_SIZE 10
|
||||
@@ -305,9 +300,9 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
#define CV_MAX_STRLEN 1024
|
||||
|
||||
#if 0 /*def CV_CHECK_FOR_NANS*/
|
||||
#define CV_CHECK_NANS( arr ) cvCheckArray((arr))
|
||||
# define CV_CHECK_NANS( arr ) cvCheckArray((arr))
|
||||
#else
|
||||
#define CV_CHECK_NANS( arr )
|
||||
# define CV_CHECK_NANS( arr )
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
@@ -316,38 +311,38 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
|
||||
/* get alloca declaration */
|
||||
#ifdef __GNUC__
|
||||
#undef alloca
|
||||
#define alloca __builtin_alloca
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# undef alloca
|
||||
# define alloca __builtin_alloca
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#elif defined WIN32 || defined _WIN32 || \
|
||||
defined WINCE || defined _MSC_VER || defined __BORLANDC__
|
||||
#include <malloc.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# include <malloc.h>
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#elif defined HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# include <alloca.h>
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#elif defined HAVE_ALLOCA
|
||||
#include <stdlib.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# include <stdlib.h>
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#else
|
||||
#undef CV_HAVE_ALLOCA
|
||||
# undef CV_HAVE_ALLOCA
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
|
||||
# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
|
||||
#elif defined _MSC_VER
|
||||
#define CV_DECL_ALIGNED(x) __declspec(align(x))
|
||||
# define CV_DECL_ALIGNED(x) __declspec(align(x))
|
||||
#else
|
||||
#define CV_DECL_ALIGNED(x)
|
||||
# define CV_DECL_ALIGNED(x)
|
||||
#endif
|
||||
|
||||
#if CV_HAVE_ALLOCA
|
||||
/* ! DO NOT make it an inline function */
|
||||
#define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
|
||||
# define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
|
||||
#endif
|
||||
|
||||
#ifndef CV_IMPL
|
||||
#define CV_IMPL CV_EXTERN_C
|
||||
# define CV_IMPL CV_EXTERN_C
|
||||
#endif
|
||||
|
||||
#define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; }
|
||||
@@ -687,25 +682,25 @@ typedef enum CvStatus
|
||||
CV_UNSUPPORTED_DEPTH_ERR = -101,
|
||||
CV_UNSUPPORTED_FORMAT_ERR = -100,
|
||||
|
||||
CV_BADARG_ERR = -49, //ipp comp
|
||||
CV_NOTDEFINED_ERR = -48, //ipp comp
|
||||
CV_BADARG_ERR = -49, //ipp comp
|
||||
CV_NOTDEFINED_ERR = -48, //ipp comp
|
||||
|
||||
CV_BADCHANNELS_ERR = -47, //ipp comp
|
||||
CV_BADRANGE_ERR = -44, //ipp comp
|
||||
CV_BADSTEP_ERR = -29, //ipp comp
|
||||
CV_BADCHANNELS_ERR = -47, //ipp comp
|
||||
CV_BADRANGE_ERR = -44, //ipp comp
|
||||
CV_BADSTEP_ERR = -29, //ipp comp
|
||||
|
||||
CV_BADFLAG_ERR = -12,
|
||||
CV_DIV_BY_ZERO_ERR = -11, //ipp comp
|
||||
CV_BADCOEF_ERR = -10,
|
||||
CV_BADFLAG_ERR = -12,
|
||||
CV_DIV_BY_ZERO_ERR = -11, //ipp comp
|
||||
CV_BADCOEF_ERR = -10,
|
||||
|
||||
CV_BADFACTOR_ERR = -7,
|
||||
CV_BADPOINT_ERR = -6,
|
||||
CV_BADSCALE_ERR = -4,
|
||||
CV_OUTOFMEM_ERR = -3,
|
||||
CV_NULLPTR_ERR = -2,
|
||||
CV_BADSIZE_ERR = -1,
|
||||
CV_NO_ERR = 0,
|
||||
CV_OK = CV_NO_ERR
|
||||
CV_BADFACTOR_ERR = -7,
|
||||
CV_BADPOINT_ERR = -6,
|
||||
CV_BADSCALE_ERR = -4,
|
||||
CV_OUTOFMEM_ERR = -3,
|
||||
CV_NULLPTR_ERR = -2,
|
||||
CV_BADSIZE_ERR = -1,
|
||||
CV_NO_ERR = 0,
|
||||
CV_OK = CV_NO_ERR
|
||||
}
|
||||
CvStatus;
|
||||
|
||||
@@ -720,8 +715,7 @@ CvFuncTable;
|
||||
typedef struct CvBigFuncTable
|
||||
{
|
||||
void* fn_2d[CV_DEPTH_MAX*4];
|
||||
}
|
||||
CvBigFuncTable;
|
||||
} CvBigFuncTable;
|
||||
|
||||
#define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \
|
||||
(tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \
|
||||
@@ -732,13 +726,14 @@ CvBigFuncTable;
|
||||
(tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
|
||||
(tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
|
||||
|
||||
#ifdef __cplusplus
|
||||
//! OpenGL extension table
|
||||
class CV_EXPORTS CvOpenGlFuncTab
|
||||
{
|
||||
public:
|
||||
virtual ~CvOpenGlFuncTab();
|
||||
|
||||
virtual void genBuffers(int n, unsigned int* buffers) const = 0;
|
||||
virtual void genBuffers(int n, unsigned int* buffers) const = 0;
|
||||
virtual void deleteBuffers(int n, const unsigned int* buffers) const = 0;
|
||||
|
||||
virtual void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const = 0;
|
||||
@@ -764,4 +759,6 @@ CV_EXPORTS bool icvCheckGlError(const char* file, const int line, const char* fu
|
||||
#define CV_CheckGlError() CV_DbgAssert( (::icvCheckGlError(__FILE__, __LINE__)) )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif //__cplusplus
|
||||
|
||||
#endif // __OPENCV_CORE_INTERNAL_HPP__
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,122 +43,132 @@
|
||||
#ifndef __OPENCV_CORE_TYPES_H__
|
||||
#define __OPENCV_CORE_TYPES_H__
|
||||
|
||||
#if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
|
||||
#define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
|
||||
#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER
|
||||
# if _MSC_VER > 1300
|
||||
# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SKIP_INCLUDES
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
|
||||
#if !defined _MSC_VER && !defined __BORLANDC__
|
||||
#include <stdint.h>
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined __ICL
|
||||
#define CV_ICC __ICL
|
||||
#elif defined __ICC
|
||||
#define CV_ICC __ICC
|
||||
#elif defined __ECL
|
||||
#define CV_ICC __ECL
|
||||
#elif defined __ECC
|
||||
#define CV_ICC __ECC
|
||||
#elif defined __INTEL_COMPILER
|
||||
#define CV_ICC __INTEL_COMPILER
|
||||
#endif
|
||||
#if defined __ICL
|
||||
# define CV_ICC __ICL
|
||||
#elif defined __ICC
|
||||
# define CV_ICC __ICC
|
||||
#elif defined __ECL
|
||||
# define CV_ICC __ECL
|
||||
#elif defined __ECC
|
||||
# define CV_ICC __ECC
|
||||
#elif defined __INTEL_COMPILER
|
||||
# define CV_ICC __INTEL_COMPILER
|
||||
#endif
|
||||
|
||||
#if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
|
||||
#if defined WIN32
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
#if __SSE2__ || !defined __GNUC__
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
#endif
|
||||
#if defined CV_ICC && !defined CV_ENABLE_UNROLLED
|
||||
# define CV_ENABLE_UNROLLED 0
|
||||
#else
|
||||
# define CV_ENABLE_UNROLLED 1
|
||||
#endif
|
||||
|
||||
#if defined __BORLANDC__
|
||||
#include <fastmath.h>
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
#if (defined _M_X64 && _MSC_VER >= 1400) || (__GNUC__ >= 4 && defined __x86_64__)
|
||||
# if defined WIN32
|
||||
# include <intrin.h>
|
||||
# endif
|
||||
# if __SSE2__ || !defined __GNUC__
|
||||
# include <emmintrin.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined __BORLANDC__
|
||||
# include <fastmath.h>
|
||||
#else
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IPL
|
||||
# ifndef __IPL_H__
|
||||
# if defined WIN32 || defined _WIN32
|
||||
# include <ipl.h>
|
||||
# else
|
||||
# include <ipl/ipl.h>
|
||||
# endif
|
||||
# endif
|
||||
#elif defined __IPL_H__
|
||||
# define HAVE_IPL
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IPL
|
||||
#ifndef __IPL_H__
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#include <ipl.h>
|
||||
#else
|
||||
#include <ipl/ipl.h>
|
||||
#endif
|
||||
#endif
|
||||
#elif defined __IPL_H__
|
||||
#define HAVE_IPL
|
||||
#endif
|
||||
#endif // SKIP_INCLUDES
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#define CV_CDECL __cdecl
|
||||
#define CV_STDCALL __stdcall
|
||||
# define CV_CDECL __cdecl
|
||||
# define CV_STDCALL __stdcall
|
||||
#else
|
||||
#define CV_CDECL
|
||||
#define CV_STDCALL
|
||||
# define CV_CDECL
|
||||
# define CV_STDCALL
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C
|
||||
#ifdef __cplusplus
|
||||
#define CV_EXTERN_C extern "C"
|
||||
#define CV_DEFAULT(val) = val
|
||||
#else
|
||||
#define CV_EXTERN_C
|
||||
#define CV_DEFAULT(val)
|
||||
#endif
|
||||
# ifdef __cplusplus
|
||||
# define CV_EXTERN_C extern "C"
|
||||
# define CV_DEFAULT(val) = val
|
||||
# else
|
||||
# define CV_EXTERN_C
|
||||
# define CV_DEFAULT(val)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C_FUNCPTR
|
||||
#ifdef __cplusplus
|
||||
#define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
|
||||
#else
|
||||
#define CV_EXTERN_C_FUNCPTR(x) typedef x
|
||||
#endif
|
||||
# ifdef __cplusplus
|
||||
# define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
|
||||
# else
|
||||
# define CV_EXTERN_C_FUNCPTR(x) typedef x
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_INLINE
|
||||
#if defined __cplusplus
|
||||
#define CV_INLINE inline
|
||||
#elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__
|
||||
#define CV_INLINE __inline
|
||||
#else
|
||||
#define CV_INLINE static
|
||||
#endif
|
||||
# if defined __cplusplus
|
||||
# define CV_INLINE inline
|
||||
# elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__
|
||||
# define CV_INLINE __inline
|
||||
# else
|
||||
# define CV_INLINE static
|
||||
# endif
|
||||
#endif /* CV_INLINE */
|
||||
|
||||
#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
|
||||
#define CV_EXPORTS __declspec(dllexport)
|
||||
# define CV_EXPORTS __declspec(dllexport)
|
||||
#else
|
||||
#define CV_EXPORTS
|
||||
# define CV_EXPORTS
|
||||
#endif
|
||||
|
||||
#ifndef CVAPI
|
||||
#define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
|
||||
# define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER || defined __BORLANDC__
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#define CV_BIG_INT(n) n##I64
|
||||
#define CV_BIG_UINT(n) n##UI64
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
# define CV_BIG_INT(n) n##I64
|
||||
# define CV_BIG_UINT(n) n##UI64
|
||||
#else
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
#define CV_BIG_INT(n) n##LL
|
||||
#define CV_BIG_UINT(n) n##ULL
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
# define CV_BIG_INT(n) n##LL
|
||||
# define CV_BIG_UINT(n) n##ULL
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_IPL
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
#endif
|
||||
|
||||
typedef signed char schar;
|
||||
@@ -203,7 +213,7 @@ Cv64suf;
|
||||
|
||||
typedef int CVStatus;
|
||||
|
||||
enum {
|
||||
enum {
|
||||
CV_StsOk= 0, /* everithing is ok */
|
||||
CV_StsBackTrace= -1, /* pseudo error for back trace */
|
||||
CV_StsError= -2, /* unknown /unspecified error */
|
||||
@@ -241,8 +251,8 @@ enum {
|
||||
CV_StsInplaceNotSupported= -203, /* in-place operation is not supported */
|
||||
CV_StsObjectNotFound= -204, /* request can't be completed */
|
||||
CV_StsUnmatchedFormats= -205, /* formats of input/output arrays differ */
|
||||
CV_StsBadFlag= -206, /* flag is wrong or not supported */
|
||||
CV_StsBadPoint= -207, /* bad CvPoint */
|
||||
CV_StsBadFlag= -206, /* flag is wrong or not supported */
|
||||
CV_StsBadPoint= -207, /* bad CvPoint */
|
||||
CV_StsBadMask= -208, /* bad format of mask (neither 8uC1 nor 8sC1)*/
|
||||
CV_StsUnmatchedSizes= -209, /* sizes of input/output structures do not match */
|
||||
CV_StsUnsupportedFormat= -210, /* the data format/type is not supported by the function*/
|
||||
@@ -250,8 +260,8 @@ enum {
|
||||
CV_StsParseError= -212, /* invalid syntax/structure of the parsed file */
|
||||
CV_StsNotImplemented= -213, /* the requested function/feature is not implemented */
|
||||
CV_StsBadMemBlock= -214, /* an allocated block has been corrupted */
|
||||
CV_StsAssert= -215, /* assertion failed */
|
||||
CV_GpuNotSupported= -216,
|
||||
CV_StsAssert= -215, /* assertion failed */
|
||||
CV_GpuNotSupported= -216,
|
||||
CV_GpuApiCallError= -217,
|
||||
CV_OpenGlNotSupported= -218,
|
||||
CV_OpenGlApiCallError= -219
|
||||
@@ -262,7 +272,7 @@ enum {
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# include "tegra_round.hpp"
|
||||
# include "tegra_round.hpp"
|
||||
#endif
|
||||
|
||||
#define CV_PI 3.1415926535897932384626433832795
|
||||
@@ -271,11 +281,11 @@ enum {
|
||||
#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
# define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
# define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
/* min & max without jumps */
|
||||
@@ -285,9 +295,9 @@ enum {
|
||||
|
||||
/* absolute value without jumps */
|
||||
#ifndef __cplusplus
|
||||
#define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
|
||||
# define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
|
||||
#else
|
||||
#define CV_IABS(a) abs(a)
|
||||
# define CV_IABS(a) abs(a)
|
||||
#endif
|
||||
#define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
|
||||
#define CV_SIGN(a) CV_CMP((a),0)
|
||||
@@ -306,11 +316,11 @@ CV_INLINE int cvRound( double value )
|
||||
}
|
||||
return t;
|
||||
#elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
|
||||
# ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
TEGRA_ROUND(value);
|
||||
# else
|
||||
# else
|
||||
return (int)lrint(value);
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
// while this is not IEEE754-compliant rounding, it's usually a good enough approximation
|
||||
return (int)(value + (value >= 0 ? 0.5 : -0.5));
|
||||
@@ -318,7 +328,7 @@ CV_INLINE int cvRound( double value )
|
||||
}
|
||||
|
||||
#if defined __SSE2__ || (defined _M_IX86_FP && 2 == _M_IX86_FP)
|
||||
#include "emmintrin.h"
|
||||
# include "emmintrin.h"
|
||||
#endif
|
||||
|
||||
CV_INLINE int cvFloor( double value )
|
||||
@@ -1886,6 +1896,6 @@ typedef struct CvModuleInfo
|
||||
}
|
||||
CvModuleInfo;
|
||||
|
||||
#endif /*_CXCORE_TYPES_H_*/
|
||||
#endif /*__OPENCV_CORE_TYPES_H__*/
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "opencv2/ts/ts.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ PERF_TEST_P(Size_MatType, mean, TYPICAL_MATS)
|
||||
|
||||
Mat src(sz, type);
|
||||
Scalar s;
|
||||
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(s);
|
||||
|
||||
|
||||
TEST_CYCLE() s = mean(src);
|
||||
|
||||
|
||||
SANITY_CHECK(s, 1e-6);
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ PERF_TEST_P(Size_MatType, mean_mask, TYPICAL_MATS)
|
||||
Mat src(sz, type);
|
||||
Mat mask = Mat::ones(src.size(), CV_8U);
|
||||
Scalar s;
|
||||
|
||||
|
||||
declare.in(src, WARMUP_RNG).in(mask).out(s);
|
||||
|
||||
|
||||
TEST_CYCLE() s = mean(src, mask);
|
||||
|
||||
|
||||
SANITY_CHECK(s, 1e-6);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ PERF_TEST_P(Size_MatType, meanStdDev, TYPICAL_MATS)
|
||||
declare.in(src, WARMUP_RNG).out(mean, dev);
|
||||
|
||||
TEST_CYCLE() meanStdDev(src, mean, dev);
|
||||
|
||||
|
||||
SANITY_CHECK(mean, 1e-6);
|
||||
SANITY_CHECK(dev, 1e-6);
|
||||
}
|
||||
@@ -80,9 +80,9 @@ PERF_TEST_P(Size_MatType, meanStdDev_mask, TYPICAL_MATS)
|
||||
Scalar dev;
|
||||
|
||||
declare.in(src, WARMUP_RNG).in(mask).out(mean, dev);
|
||||
|
||||
|
||||
TEST_CYCLE() meanStdDev(src, mean, dev, mask);
|
||||
|
||||
|
||||
SANITY_CHECK(mean, 1e-6);
|
||||
SANITY_CHECK(dev, 1e-6);
|
||||
}
|
||||
@@ -96,8 +96,8 @@ PERF_TEST_P(Size_MatType, countNonZero, testing::Combine( testing::Values( TYPIC
|
||||
int cnt = 0;
|
||||
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
|
||||
TEST_CYCLE() cnt = countNonZero(src);
|
||||
|
||||
|
||||
SANITY_CHECK(cnt);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ static void* OutOfMemoryError(size_t size)
|
||||
|
||||
#if CV_USE_SYSTEM_MALLOC
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
void deleteThreadAllocData() {}
|
||||
#endif
|
||||
|
||||
void* fastMalloc( size_t size )
|
||||
{
|
||||
@@ -66,14 +68,14 @@ void* fastMalloc( size_t size )
|
||||
adata[-1] = udata;
|
||||
return adata;
|
||||
}
|
||||
|
||||
|
||||
void fastFree(void* ptr)
|
||||
{
|
||||
if(ptr)
|
||||
{
|
||||
uchar* udata = ((uchar**)ptr)[-1];
|
||||
CV_DbgAssert(udata < (uchar*)ptr &&
|
||||
((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+CV_MALLOC_ALIGN));
|
||||
((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+CV_MALLOC_ALIGN));
|
||||
free(udata);
|
||||
}
|
||||
}
|
||||
@@ -388,7 +390,7 @@ struct ThreadData
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef WINCE
|
||||
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
|
||||
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
|
||||
#endif //WINCE
|
||||
|
||||
static DWORD tlsKey;
|
||||
@@ -535,7 +537,7 @@ void* fastMalloc( size_t size )
|
||||
freePtr = block;
|
||||
if( !data )
|
||||
{
|
||||
block = gcPtr;
|
||||
block = gcPtr;
|
||||
for( int k = 0; k < 2; k++ )
|
||||
{
|
||||
SANITY_CHECK(block);
|
||||
@@ -620,7 +622,7 @@ void fastFree( void* ptr )
|
||||
Block*& startPtr = tls->bins[idx][START];
|
||||
Block*& freePtr = tls->bins[idx][FREE];
|
||||
Block*& gcPtr = tls->bins[idx][GC];
|
||||
|
||||
|
||||
if( block == block->next )
|
||||
{
|
||||
CV_DbgAssert( startPtr == block && freePtr == block && gcPtr == block );
|
||||
|
||||
@@ -974,7 +974,7 @@ void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t bl
|
||||
scbuf[i] = scbuf[i - esz];
|
||||
}
|
||||
|
||||
void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
static void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
InputArray _mask, const BinaryFunc* tab, bool bitwise)
|
||||
{
|
||||
int kind1 = _src1.kind(), kind2 = _src2.kind();
|
||||
@@ -1216,7 +1216,7 @@ void cv::min(const Mat& src1, double src2, Mat& dst)
|
||||
namespace cv
|
||||
{
|
||||
|
||||
void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
InputArray _mask, int dtype, BinaryFunc* tab, bool muldiv=false, void* usrdata=0)
|
||||
{
|
||||
int kind1 = _src1.kind(), kind2 = _src2.kind();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace {
|
||||
void helpParser()
|
||||
{
|
||||
printf("\nThe CommandLineParser class is designed for command line arguments parsing\n"
|
||||
@@ -89,6 +90,8 @@ string del_space(string name)
|
||||
return name;
|
||||
}
|
||||
|
||||
}//namespace
|
||||
|
||||
CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys)
|
||||
{
|
||||
std::string keys_buffer;
|
||||
|
||||
+222
-222
File diff suppressed because it is too large
Load Diff
+307
-305
File diff suppressed because it is too large
Load Diff
+12
-12
@@ -116,13 +116,13 @@ static void writeMat(std::ostream& out, const Mat& m, char rowsep, char elembrac
|
||||
{
|
||||
CV_Assert(m.dims <= 2);
|
||||
int type = m.type();
|
||||
|
||||
|
||||
char crowbrace = getCloseBrace(rowsep);
|
||||
char orowbrace = crowbrace ? rowsep : '\0';
|
||||
|
||||
|
||||
if( orowbrace || isspace(rowsep) )
|
||||
rowsep = '\0';
|
||||
|
||||
|
||||
for( int i = 0; i < m.rows; i++ )
|
||||
{
|
||||
if(orowbrace)
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
writeMat(out, m, ';', ' ', m.cols == 1);
|
||||
out << "]";
|
||||
}
|
||||
|
||||
|
||||
void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const
|
||||
{
|
||||
writeElems(out, data, nelems, type, ' ');
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.cols*m.channels() == 1);
|
||||
out << "]";
|
||||
}
|
||||
|
||||
|
||||
void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const
|
||||
{
|
||||
writeElems(out, data, nelems, type, '[');
|
||||
@@ -190,7 +190,7 @@ public:
|
||||
writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.cols*m.channels() == 1);
|
||||
out << "], type='" << numpyTypes[m.depth()] << "')";
|
||||
}
|
||||
|
||||
|
||||
void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const
|
||||
{
|
||||
writeElems(out, data, nelems, type, '[');
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
if(m.rows > 1)
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
|
||||
void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const
|
||||
{
|
||||
writeElems(out, data, nelems, type, ' ');
|
||||
@@ -226,7 +226,7 @@ public:
|
||||
writeMat(out, m, ',', ' ', m.cols==1);
|
||||
out << "}";
|
||||
}
|
||||
|
||||
|
||||
void write(std::ostream& out, const void* data, int nelems, int type, const int*, int) const
|
||||
{
|
||||
writeElems(out, data, nelems, type, ' ');
|
||||
@@ -243,7 +243,7 @@ static CFormatter cFormatter;
|
||||
static const Formatter* g_defaultFormatter0 = &matlabFormatter;
|
||||
static const Formatter* g_defaultFormatter = &matlabFormatter;
|
||||
|
||||
bool my_streq(const char* a, const char* b)
|
||||
static bool my_streq(const char* a, const char* b)
|
||||
{
|
||||
size_t i, alen = strlen(a), blen = strlen(b);
|
||||
if( alen != blen )
|
||||
@@ -280,7 +280,7 @@ const Formatter* Formatter::setDefault(const Formatter* fmt)
|
||||
g_defaultFormatter = fmt;
|
||||
return prevFmt;
|
||||
}
|
||||
|
||||
|
||||
Formatted::Formatted(const Mat& _m, const Formatter* _fmt,
|
||||
const vector<int>& _params)
|
||||
{
|
||||
@@ -288,12 +288,12 @@ Formatted::Formatted(const Mat& _m, const Formatter* _fmt,
|
||||
fmt = _fmt ? _fmt : Formatter::get();
|
||||
std::copy(_params.begin(), _params.end(), back_inserter(params));
|
||||
}
|
||||
|
||||
|
||||
Formatted::Formatted(const Mat& _m, const Formatter* _fmt, const int* _params)
|
||||
{
|
||||
mtx = _m;
|
||||
fmt = _fmt ? _fmt : Formatter::get();
|
||||
|
||||
|
||||
if( _params )
|
||||
{
|
||||
int i, maxParams = 100;
|
||||
|
||||
+112
-112
@@ -54,7 +54,7 @@ template<typename T> static inline Scalar rawToScalar(const T& v)
|
||||
for( i = 0; i < n; i++ )
|
||||
s.val[i] = ((T1*)&v)[i];
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* sum *
|
||||
@@ -72,7 +72,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn )
|
||||
{
|
||||
ST s0 = dst[0];
|
||||
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= len - 4; i += 4, src += cn*4 )
|
||||
s0 += src[0] + src[cn] + src[cn*2] + src[cn*3];
|
||||
#endif
|
||||
@@ -104,7 +104,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn )
|
||||
dst[1] = s1;
|
||||
dst[2] = s2;
|
||||
}
|
||||
|
||||
|
||||
for( ; k < cn; k += 4 )
|
||||
{
|
||||
src = src0 + k;
|
||||
@@ -121,7 +121,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn )
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int i, nzm = 0;
|
||||
if( cn == 1 )
|
||||
{
|
||||
@@ -155,7 +155,7 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn )
|
||||
if( mask[i] )
|
||||
{
|
||||
int k = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; k <= cn - 4; k += 4 )
|
||||
{
|
||||
ST s0, s1;
|
||||
@@ -212,7 +212,7 @@ template<typename T>
|
||||
static int countNonZero_(const T* src, int len )
|
||||
{
|
||||
int i=0, nz = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= len - 4; i += 4 )
|
||||
nz += (src[i] != 0) + (src[i+1] != 0) + (src[i+2] != 0) + (src[i+3] != 0);
|
||||
#endif
|
||||
@@ -251,12 +251,12 @@ template<typename T, typename ST, typename SQT>
|
||||
static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int len, int cn )
|
||||
{
|
||||
const T* src = src0;
|
||||
|
||||
|
||||
if( !mask )
|
||||
{
|
||||
int i;
|
||||
int k = cn % 4;
|
||||
|
||||
|
||||
if( k == 1 )
|
||||
{
|
||||
ST s0 = sum[0];
|
||||
@@ -296,7 +296,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
||||
sum[0] = s0; sum[1] = s1; sum[2] = s2;
|
||||
sqsum[0] = sq0; sqsum[1] = sq1; sqsum[2] = sq2;
|
||||
}
|
||||
|
||||
|
||||
for( ; k < cn; k += 4 )
|
||||
{
|
||||
src = src0 + k;
|
||||
@@ -319,7 +319,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int i, nzm = 0;
|
||||
|
||||
if( cn == 1 )
|
||||
@@ -368,7 +368,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
||||
}
|
||||
}
|
||||
return nzm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int sqsum8u( const uchar* src, const uchar* mask, int* sum, int* sqsum, int len, int cn )
|
||||
@@ -407,9 +407,9 @@ cv::Scalar cv::sum( InputArray _src )
|
||||
Mat src = _src.getMat();
|
||||
int k, cn = src.channels(), depth = src.depth();
|
||||
SumFunc func = sumTab[depth];
|
||||
|
||||
|
||||
CV_Assert( cn <= 4 && func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, 0};
|
||||
uchar* ptrs[1];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
@@ -420,7 +420,7 @@ cv::Scalar cv::sum( InputArray _src )
|
||||
int* buf = (int*)&s[0];
|
||||
size_t esz = 0;
|
||||
bool blockSum = depth < CV_32S;
|
||||
|
||||
|
||||
if( blockSum )
|
||||
{
|
||||
intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15);
|
||||
@@ -459,30 +459,30 @@ int cv::countNonZero( InputArray _src )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
CountNonZeroFunc func = countNonZeroTab[src.depth()];
|
||||
|
||||
|
||||
CV_Assert( src.channels() == 1 && func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, 0};
|
||||
uchar* ptrs[1];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int total = (int)it.size, nz = 0;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
nz += func( ptrs[0], total );
|
||||
|
||||
|
||||
return nz;
|
||||
}
|
||||
}
|
||||
|
||||
cv::Scalar cv::mean( InputArray _src, InputArray _mask )
|
||||
{
|
||||
Mat src = _src.getMat(), mask = _mask.getMat();
|
||||
CV_Assert( mask.empty() || mask.type() == CV_8U );
|
||||
|
||||
|
||||
int k, cn = src.channels(), depth = src.depth();
|
||||
SumFunc func = sumTab[depth];
|
||||
|
||||
|
||||
CV_Assert( cn <= 4 && func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &mask, 0};
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
@@ -493,19 +493,19 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask )
|
||||
int* buf = (int*)&s[0];
|
||||
bool blockSum = depth <= CV_16S;
|
||||
size_t esz = 0, nz0 = 0;
|
||||
|
||||
|
||||
if( blockSum )
|
||||
{
|
||||
intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15);
|
||||
blockSize = std::min(blockSize, intSumBlockSize);
|
||||
_buf.allocate(cn);
|
||||
buf = _buf;
|
||||
|
||||
|
||||
for( k = 0; k < cn; k++ )
|
||||
buf[k] = 0;
|
||||
esz = src.elemSize();
|
||||
}
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
for( j = 0; j < total; j += blockSize )
|
||||
@@ -529,19 +529,19 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask )
|
||||
}
|
||||
}
|
||||
return s*(nz0 ? 1./nz0 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray _mask )
|
||||
{
|
||||
Mat src = _src.getMat(), mask = _mask.getMat();
|
||||
CV_Assert( mask.empty() || mask.type() == CV_8U );
|
||||
|
||||
|
||||
int k, cn = src.channels(), depth = src.depth();
|
||||
SumSqrFunc func = sumSqrTab[depth];
|
||||
|
||||
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &mask, 0};
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
@@ -552,10 +552,10 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input
|
||||
int *sbuf = (int*)s, *sqbuf = (int*)sq;
|
||||
bool blockSum = depth <= CV_16S, blockSqSum = depth <= CV_8S;
|
||||
size_t esz = 0;
|
||||
|
||||
|
||||
for( k = 0; k < cn; k++ )
|
||||
s[k] = sq[k] = 0;
|
||||
|
||||
|
||||
if( blockSum )
|
||||
{
|
||||
intSumBlockSize = 1 << 15;
|
||||
@@ -567,7 +567,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input
|
||||
sbuf[k] = sqbuf[k] = 0;
|
||||
esz = src.elemSize();
|
||||
}
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
for( j = 0; j < total; j += blockSize )
|
||||
@@ -598,14 +598,14 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input
|
||||
ptrs[1] += bsz;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double scale = nz0 ? 1./nz0 : 0.;
|
||||
for( k = 0; k < cn; k++ )
|
||||
{
|
||||
s[k] *= scale;
|
||||
sq[k] = std::sqrt(std::max(sq[k]*scale - s[k]*s[k], 0.));
|
||||
}
|
||||
|
||||
|
||||
for( j = 0; j < 2; j++ )
|
||||
{
|
||||
const double* sptr = j == 0 ? s : sq;
|
||||
@@ -640,7 +640,7 @@ minMaxIdx_( const T* src, const uchar* mask, WT* _minVal, WT* _maxVal,
|
||||
{
|
||||
WT minVal = *_minVal, maxVal = *_maxVal;
|
||||
size_t minIdx = *_minIdx, maxIdx = *_maxIdx;
|
||||
|
||||
|
||||
if( !mask )
|
||||
{
|
||||
for( int i = 0; i < len; i++ )
|
||||
@@ -708,7 +708,7 @@ static void minMaxIdx_32f(const float* src, const uchar* mask, float* minval, fl
|
||||
|
||||
static void minMaxIdx_64f(const double* src, const uchar* mask, double* minval, double* maxval,
|
||||
size_t* minidx, size_t* maxidx, int len, size_t startidx )
|
||||
{ minMaxIdx_(src, mask, minval, maxval, minidx, maxidx, len, startidx ); }
|
||||
{ minMaxIdx_(src, mask, minval, maxval, minidx, maxidx, len, startidx ); }
|
||||
|
||||
typedef void (*MinMaxIdxFunc)(const uchar*, const uchar*, int*, int*, size_t*, size_t*, int, size_t);
|
||||
|
||||
@@ -749,16 +749,16 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
|
||||
{
|
||||
Mat src = _src.getMat(), mask = _mask.getMat();
|
||||
int depth = src.depth(), cn = src.channels();
|
||||
|
||||
|
||||
CV_Assert( (cn == 1 && (mask.empty() || mask.type() == CV_8U)) ||
|
||||
(cn >= 1 && mask.empty() && !minIdx && !maxIdx) );
|
||||
MinMaxIdxFunc func = minmaxTab[depth];
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &mask, 0};
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
|
||||
|
||||
size_t minidx = 0, maxidx = 0;
|
||||
int iminval = INT_MAX, imaxval = INT_MIN;
|
||||
float fminval = FLT_MAX, fmaxval = -FLT_MAX;
|
||||
@@ -766,39 +766,39 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
|
||||
size_t startidx = 1;
|
||||
int *minval = &iminval, *maxval = &imaxval;
|
||||
int planeSize = (int)it.size*cn;
|
||||
|
||||
|
||||
if( depth == CV_32F )
|
||||
minval = (int*)&fminval, maxval = (int*)&fmaxval;
|
||||
else if( depth == CV_64F )
|
||||
minval = (int*)&dminval, maxval = (int*)&dmaxval;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it, startidx += planeSize )
|
||||
func( ptrs[0], ptrs[1], minval, maxval, &minidx, &maxidx, planeSize, startidx );
|
||||
|
||||
|
||||
if( minidx == 0 )
|
||||
dminval = dmaxval = 0;
|
||||
else if( depth == CV_32F )
|
||||
dminval = fminval, dmaxval = fmaxval;
|
||||
else if( depth <= CV_32S )
|
||||
dminval = iminval, dmaxval = imaxval;
|
||||
|
||||
|
||||
if( minVal )
|
||||
*minVal = dminval;
|
||||
if( maxVal )
|
||||
*maxVal = dmaxval;
|
||||
|
||||
|
||||
if( minIdx )
|
||||
ofs2idx(src, minidx, minIdx);
|
||||
if( maxIdx )
|
||||
ofs2idx(src, maxidx, maxIdx);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::minMaxLoc( InputArray _img, double* minVal, double* maxVal,
|
||||
Point* minLoc, Point* maxLoc, InputArray mask )
|
||||
{
|
||||
Mat img = _img.getMat();
|
||||
CV_Assert(img.dims <= 2);
|
||||
|
||||
|
||||
minMaxIdx(_img, minVal, maxVal, (int*)minLoc, (int*)maxLoc, mask);
|
||||
if( minLoc )
|
||||
std::swap(minLoc->x, minLoc->y);
|
||||
@@ -821,7 +821,7 @@ float normL2Sqr_(const float* a, const float* b, int n)
|
||||
{
|
||||
float CV_DECL_ALIGNED(16) buf[4];
|
||||
__m128 d0 = _mm_setzero_ps(), d1 = _mm_setzero_ps();
|
||||
|
||||
|
||||
for( ; j <= n - 8; j += 8 )
|
||||
{
|
||||
__m128 t0 = _mm_sub_ps(_mm_loadu_ps(a + j), _mm_loadu_ps(b + j));
|
||||
@@ -834,14 +834,14 @@ float normL2Sqr_(const float* a, const float* b, int n)
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
for( ; j <= n - 4; j += 4 )
|
||||
{
|
||||
float t0 = a[j] - b[j], t1 = a[j+1] - b[j+1], t2 = a[j+2] - b[j+2], t3 = a[j+3] - b[j+3];
|
||||
d += t0*t0 + t1*t1 + t2*t2 + t3*t3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for( ; j < n; j++ )
|
||||
{
|
||||
float t = a[j] - b[j];
|
||||
@@ -861,7 +861,7 @@ float normL1_(const float* a, const float* b, int n)
|
||||
static const int CV_DECL_ALIGNED(16) absbuf[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
|
||||
__m128 d0 = _mm_setzero_ps(), d1 = _mm_setzero_ps();
|
||||
__m128 absmask = _mm_load_ps((const float*)absbuf);
|
||||
|
||||
|
||||
for( ; j <= n - 8; j += 8 )
|
||||
{
|
||||
__m128 t0 = _mm_sub_ps(_mm_loadu_ps(a + j), _mm_loadu_ps(b + j));
|
||||
@@ -894,12 +894,12 @@ int normL1_(const uchar* a, const uchar* b, int n)
|
||||
if( USE_SSE2 )
|
||||
{
|
||||
__m128i d0 = _mm_setzero_si128();
|
||||
|
||||
|
||||
for( ; j <= n - 16; j += 16 )
|
||||
{
|
||||
__m128i t0 = _mm_loadu_si128((const __m128i*)(a + j));
|
||||
__m128i t1 = _mm_loadu_si128((const __m128i*)(b + j));
|
||||
|
||||
|
||||
d0 = _mm_add_epi32(d0, _mm_sad_epu8(t0, t1));
|
||||
}
|
||||
|
||||
@@ -907,7 +907,7 @@ int normL1_(const uchar* a, const uchar* b, int n)
|
||||
{
|
||||
__m128i t0 = _mm_cvtsi32_si128(*(const int*)(a + j));
|
||||
__m128i t1 = _mm_cvtsi32_si128(*(const int*)(b + j));
|
||||
|
||||
|
||||
d0 = _mm_add_epi32(d0, _mm_sad_epu8(t0, t1));
|
||||
}
|
||||
d = _mm_cvtsi128_si32(_mm_add_epi32(d0, _mm_unpackhi_epi64(d0, d0)));
|
||||
@@ -926,7 +926,7 @@ int normL1_(const uchar* a, const uchar* b, int n)
|
||||
return d;
|
||||
}
|
||||
|
||||
static const uchar popCountTable[] =
|
||||
static const uchar popCountTable[] =
|
||||
{
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
@@ -962,7 +962,7 @@ static const uchar popCountTable4[] =
|
||||
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
|
||||
};
|
||||
|
||||
int normHamming(const uchar* a, int n)
|
||||
static int normHamming(const uchar* a, int n)
|
||||
{
|
||||
int i = 0, result = 0;
|
||||
#if CV_NEON
|
||||
@@ -989,7 +989,7 @@ int normHamming(const uchar* a, int n)
|
||||
result += popCountTable[a[i]];
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int normHamming(const uchar* a, const uchar* b, int n)
|
||||
{
|
||||
int i = 0, result = 0;
|
||||
@@ -1020,7 +1020,7 @@ int normHamming(const uchar* a, const uchar* b, int n)
|
||||
return result;
|
||||
}
|
||||
|
||||
int normHamming(const uchar* a, int n, int cellSize)
|
||||
static int normHamming(const uchar* a, int n, int cellSize)
|
||||
{
|
||||
if( cellSize == 1 )
|
||||
return normHamming(a, n);
|
||||
@@ -1039,8 +1039,8 @@ int normHamming(const uchar* a, int n, int cellSize)
|
||||
for( ; i < n; i++ )
|
||||
result += tab[a[i]];
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int normHamming(const uchar* a, const uchar* b, int n, int cellSize)
|
||||
{
|
||||
if( cellSize == 1 )
|
||||
@@ -1053,7 +1053,7 @@ int normHamming(const uchar* a, const uchar* b, int n, int cellSize)
|
||||
else
|
||||
CV_Error( CV_StsBadSize, "bad cell size (not 1, 2 or 4) in normHamming" );
|
||||
int i = 0, result = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= n - 4; i += 4 )
|
||||
result += tab[a[i] ^ b[i]] + tab[a[i+1] ^ b[i+1]] +
|
||||
tab[a[i+2] ^ b[i+2]] + tab[a[i+3] ^ b[i+3]];
|
||||
@@ -1128,7 +1128,7 @@ normL2_(const T* src, const uchar* mask, ST* _result, int len, int cn)
|
||||
}
|
||||
*_result = result;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename ST> int
|
||||
normDiffInf_(const T* src1, const T* src2, const uchar* mask, ST* _result, int len, int cn)
|
||||
@@ -1194,7 +1194,7 @@ normDiffL2_(const T* src1, const T* src2, const uchar* mask, ST* _result, int le
|
||||
}
|
||||
*_result = result;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define CV_DEF_NORM_FUNC(L, suffix, type, ntype) \
|
||||
@@ -1219,7 +1219,7 @@ CV_DEF_NORM_ALL(64f, double, double, double, double)
|
||||
|
||||
|
||||
typedef int (*NormFunc)(const uchar*, const uchar*, uchar*, int, int);
|
||||
typedef int (*NormDiffFunc)(const uchar*, const uchar*, const uchar*, uchar*, int, int);
|
||||
typedef int (*NormDiffFunc)(const uchar*, const uchar*, const uchar*, uchar*, int, int);
|
||||
|
||||
static NormFunc normTab[3][8] =
|
||||
{
|
||||
@@ -1265,11 +1265,11 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
{
|
||||
Mat src = _src.getMat(), mask = _mask.getMat();
|
||||
int depth = src.depth(), cn = src.channels();
|
||||
|
||||
|
||||
normType &= 7;
|
||||
CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR ||
|
||||
((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src.type() == CV_8U) );
|
||||
|
||||
|
||||
if( src.isContinuous() && mask.empty() )
|
||||
{
|
||||
size_t len = src.total()*cn;
|
||||
@@ -1278,7 +1278,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
if( depth == CV_32F )
|
||||
{
|
||||
const float* data = src.ptr<float>();
|
||||
|
||||
|
||||
if( normType == NORM_L2 )
|
||||
{
|
||||
double result = 0;
|
||||
@@ -1307,18 +1307,18 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* data = src.ptr<uchar>();
|
||||
|
||||
|
||||
if( normType == NORM_HAMMING )
|
||||
return normHamming(data, (int)len);
|
||||
|
||||
|
||||
if( normType == NORM_HAMMING2 )
|
||||
return normHamming(data, (int)len, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_Assert( mask.empty() || mask.type() == CV_8U );
|
||||
|
||||
|
||||
if( normType == NORM_HAMMING || normType == NORM_HAMMING2 )
|
||||
{
|
||||
if( !mask.empty() )
|
||||
@@ -1328,22 +1328,22 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
return norm(temp, normType);
|
||||
}
|
||||
int cellSize = normType == NORM_HAMMING ? 1 : 2;
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, 0};
|
||||
uchar* ptrs[1];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int total = (int)it.size;
|
||||
int result = 0;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
result += normHamming(ptrs[0], total, cellSize);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NormFunc func = normTab[normType >> 1][depth];
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &mask, 0};
|
||||
uchar* ptrs[2];
|
||||
union
|
||||
@@ -1361,7 +1361,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
int isum = 0;
|
||||
int *ibuf = &result.i;
|
||||
size_t esz = 0;
|
||||
|
||||
|
||||
if( blockSum )
|
||||
{
|
||||
intSumBlockSize = (normType == NORM_L1 && depth <= CV_8S ? (1 << 23) : (1 << 15))/cn;
|
||||
@@ -1369,7 +1369,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
ibuf = &isum;
|
||||
esz = src.elemSize();
|
||||
}
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
for( j = 0; j < total; j += blockSize )
|
||||
@@ -1388,7 +1388,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
ptrs[1] += bsz;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( normType == NORM_INF )
|
||||
{
|
||||
if( depth == CV_64F )
|
||||
@@ -1400,7 +1400,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
}
|
||||
else if( normType == NORM_L2 )
|
||||
result.d = std::sqrt(result.d);
|
||||
|
||||
|
||||
return result.d;
|
||||
}
|
||||
|
||||
@@ -1409,16 +1409,16 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
{
|
||||
if( normType & CV_RELATIVE )
|
||||
return norm(_src1, _src2, normType & ~CV_RELATIVE, _mask)/(norm(_src2, normType, _mask) + DBL_EPSILON);
|
||||
|
||||
|
||||
Mat src1 = _src1.getMat(), src2 = _src2.getMat(), mask = _mask.getMat();
|
||||
int depth = src1.depth(), cn = src1.channels();
|
||||
|
||||
|
||||
CV_Assert( src1.size == src2.size && src1.type() == src2.type() );
|
||||
|
||||
|
||||
normType &= 7;
|
||||
CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR ||
|
||||
((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U) );
|
||||
|
||||
|
||||
if( src1.isContinuous() && src2.isContinuous() && mask.empty() )
|
||||
{
|
||||
size_t len = src1.total()*src1.channels();
|
||||
@@ -1428,7 +1428,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
{
|
||||
const float* data1 = src1.ptr<float>();
|
||||
const float* data2 = src2.ptr<float>();
|
||||
|
||||
|
||||
if( normType == NORM_L2 )
|
||||
{
|
||||
double result = 0;
|
||||
@@ -1456,9 +1456,9 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_Assert( mask.empty() || mask.type() == CV_8U );
|
||||
|
||||
|
||||
if( normType == NORM_HAMMING || normType == NORM_HAMMING2 )
|
||||
{
|
||||
if( !mask.empty() )
|
||||
@@ -1469,22 +1469,22 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
return norm(temp, normType);
|
||||
}
|
||||
int cellSize = normType == NORM_HAMMING ? 1 : 2;
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src1, &src2, 0};
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int total = (int)it.size;
|
||||
int result = 0;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
result += normHamming(ptrs[0], ptrs[1], total, cellSize);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NormDiffFunc func = normDiffTab[normType >> 1][depth];
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src1, &src2, &mask, 0};
|
||||
uchar* ptrs[3];
|
||||
union
|
||||
@@ -1503,7 +1503,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
unsigned isum = 0;
|
||||
unsigned *ibuf = &result.u;
|
||||
size_t esz = 0;
|
||||
|
||||
|
||||
if( blockSum )
|
||||
{
|
||||
intSumBlockSize = normType == NORM_L1 && depth <= CV_8S ? (1 << 23) : (1 << 15);
|
||||
@@ -1511,7 +1511,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
ibuf = &isum;
|
||||
esz = src1.elemSize();
|
||||
}
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
for( j = 0; j < total; j += blockSize )
|
||||
@@ -1531,7 +1531,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
ptrs[2] += bsz;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( normType == NORM_INF )
|
||||
{
|
||||
if( depth == CV_64F )
|
||||
@@ -1543,7 +1543,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
}
|
||||
else if( normType == NORM_L2 )
|
||||
result.d = std::sqrt(result.d);
|
||||
|
||||
|
||||
return result.d;
|
||||
}
|
||||
|
||||
@@ -1692,7 +1692,7 @@ static void batchDistL2_32f(const float* src1, const float* src2, size_t step2,
|
||||
typedef void (*BatchDistFunc)(const uchar* src1, const uchar* src2, size_t step2,
|
||||
int nvecs, int len, uchar* dist, const uchar* mask);
|
||||
|
||||
|
||||
|
||||
struct BatchDistInvoker
|
||||
{
|
||||
BatchDistInvoker( const Mat& _src1, const Mat& _src2,
|
||||
@@ -1709,26 +1709,26 @@ struct BatchDistInvoker
|
||||
update = _update;
|
||||
func = _func;
|
||||
}
|
||||
|
||||
|
||||
void operator()(const BlockedRange& range) const
|
||||
{
|
||||
AutoBuffer<int> buf(src2->rows);
|
||||
int* bufptr = buf;
|
||||
|
||||
|
||||
for( int i = range.begin(); i < range.end(); i++ )
|
||||
{
|
||||
func(src1->ptr(i), src2->ptr(), src2->step, src2->rows, src2->cols,
|
||||
K > 0 ? (uchar*)bufptr : dist->ptr(i), mask->data ? mask->ptr(i) : 0);
|
||||
|
||||
|
||||
if( K > 0 )
|
||||
{
|
||||
int* nidxptr = nidx->ptr<int>(i);
|
||||
// since positive float's can be compared just like int's,
|
||||
// we handle both CV_32S and CV_32F cases with a single branch
|
||||
int* distptr = (int*)dist->ptr(i);
|
||||
|
||||
|
||||
int j, k;
|
||||
|
||||
|
||||
for( j = 0; j < src2->rows; j++ )
|
||||
{
|
||||
int d = bufptr[j];
|
||||
@@ -1746,7 +1746,7 @@ struct BatchDistInvoker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Mat *src1;
|
||||
const Mat *src2;
|
||||
Mat *dist;
|
||||
@@ -1756,9 +1756,9 @@ struct BatchDistInvoker
|
||||
int update;
|
||||
BatchDistFunc func;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
OutputArray _dist, int dtype, OutputArray _nidx,
|
||||
int normType, int K, InputArray _mask,
|
||||
@@ -1769,7 +1769,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
CV_Assert( type == src2.type() && src1.cols == src2.cols &&
|
||||
(type == CV_32F || type == CV_8U));
|
||||
CV_Assert( _nidx.needed() == (K > 0) );
|
||||
|
||||
|
||||
if( dtype == -1 )
|
||||
{
|
||||
dtype = normType == NORM_HAMMING || normType == NORM_HAMMING2 ? CV_32S : CV_32F;
|
||||
@@ -1777,7 +1777,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
CV_Assert( (type == CV_8U && dtype == CV_32S) || dtype == CV_32F);
|
||||
|
||||
K = std::min(K, src2.rows);
|
||||
|
||||
|
||||
_dist.create(src1.rows, (K > 0 ? K : src2.rows), dtype);
|
||||
Mat dist = _dist.getMat(), nidx;
|
||||
if( _nidx.needed() )
|
||||
@@ -1785,19 +1785,19 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
_nidx.create(dist.size(), CV_32S);
|
||||
nidx = _nidx.getMat();
|
||||
}
|
||||
|
||||
|
||||
if( update == 0 && K > 0 )
|
||||
{
|
||||
dist = Scalar::all(dtype == CV_32S ? (double)INT_MAX : (double)FLT_MAX);
|
||||
nidx = Scalar::all(-1);
|
||||
}
|
||||
|
||||
|
||||
if( crosscheck )
|
||||
{
|
||||
CV_Assert( K == 1 && update == 0 && mask.empty() );
|
||||
Mat tdist, tidx;
|
||||
batchDistance(src2, src1, tdist, dtype, tidx, normType, K, mask, 0, false);
|
||||
|
||||
|
||||
// if an idx-th element from src1 appeared to be the nearest to i-th element of src2,
|
||||
// we update the minimum mutual distance between idx-th element of src1 and the whole src2 set.
|
||||
// As a result, if nidx[idx] = i*, it means that idx-th element of src1 is the nearest
|
||||
@@ -1832,7 +1832,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BatchDistFunc func = 0;
|
||||
if( type == CV_8U )
|
||||
{
|
||||
@@ -1860,12 +1860,12 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
else if( normType == NORM_L2 )
|
||||
func = (BatchDistFunc)batchDistL2_32f;
|
||||
}
|
||||
|
||||
|
||||
if( func == 0 )
|
||||
CV_Error_(CV_StsUnsupportedFormat,
|
||||
("The combination of type=%d, dtype=%d and normType=%d is not supported",
|
||||
type, dtype, normType));
|
||||
|
||||
|
||||
parallel_for(BlockedRange(0, src1.rows),
|
||||
BatchDistInvoker(src1, src2, dist, nidx, K, mask, update, func));
|
||||
}
|
||||
|
||||
+15
-15
@@ -88,7 +88,7 @@
|
||||
#if defined __linux__ || defined __APPLE__
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#if defined ANDROID
|
||||
#include <sys/sysconf.h>
|
||||
#else
|
||||
@@ -111,7 +111,7 @@ Exception::~Exception() throw() {}
|
||||
|
||||
/*!
|
||||
\return the error description and the context as a text string.
|
||||
*/
|
||||
*/
|
||||
const char* Exception::what() const throw() { return msg.c_str(); }
|
||||
|
||||
void Exception::formatMessage()
|
||||
@@ -121,7 +121,7 @@ void Exception::formatMessage()
|
||||
else
|
||||
msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str());
|
||||
}
|
||||
|
||||
|
||||
struct HWFeatures
|
||||
{
|
||||
enum { MAX_FEATURE = CV_HARDWARE_MAX_FEATURE };
|
||||
@@ -374,7 +374,7 @@ int getThreadNum(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ANDROID
|
||||
#ifdef ANDROID
|
||||
static inline int getNumberOfCPUsImpl()
|
||||
{
|
||||
FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
|
||||
@@ -408,7 +408,7 @@ static inline int getNumberOfCPUsImpl()
|
||||
sscanf(pos, "%d-%d", &rstart, &rend);
|
||||
cpusAvailable += rend - rstart + 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return cpusAvailable ? cpusAvailable : 1;
|
||||
}
|
||||
@@ -419,9 +419,9 @@ int getNumberOfCPUs(void)
|
||||
#if defined WIN32 || defined _WIN32
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo( &sysinfo );
|
||||
|
||||
|
||||
return (int)sysinfo.dwNumberOfProcessors;
|
||||
#elif ANDROID
|
||||
#elif defined ANDROID
|
||||
static int ncpus = getNumberOfCPUsImpl();
|
||||
printf("CPUS= %d\n", ncpus);
|
||||
return ncpus;
|
||||
@@ -430,24 +430,24 @@ int getNumberOfCPUs(void)
|
||||
#elif defined __APPLE__
|
||||
int numCPU=0;
|
||||
int mib[4];
|
||||
size_t len = sizeof(numCPU);
|
||||
|
||||
size_t len = sizeof(numCPU);
|
||||
|
||||
/* set the mib for hw.ncpu */
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
|
||||
|
||||
|
||||
/* get the number of CPUs from the system */
|
||||
sysctl(mib, 2, &numCPU, &len, NULL, 0);
|
||||
|
||||
if( numCPU < 1 )
|
||||
|
||||
if( numCPU < 1 )
|
||||
{
|
||||
mib[1] = HW_NCPU;
|
||||
sysctl( mib, 2, &numCPU, &len, NULL, 0 );
|
||||
|
||||
|
||||
if( numCPU < 1 )
|
||||
numCPU = 1;
|
||||
}
|
||||
|
||||
|
||||
return (int)numCPU;
|
||||
#else
|
||||
return 1;
|
||||
@@ -475,7 +475,7 @@ string tempfile( const char* suffix )
|
||||
{
|
||||
char buf[L_tmpnam];
|
||||
char* name = 0;
|
||||
#if ANDROID
|
||||
#ifdef ANDROID
|
||||
strcpy(buf, "/sdcard/__opencv_temp_XXXXXX");
|
||||
name = mktemp(buf);
|
||||
#else
|
||||
|
||||
+273
-273
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ inline int smoothedSum(const Mat& sum, const KeyPoint& pt, int y, int x)
|
||||
+ sum.at<int>(img_y - HALF_KERNEL, img_x - HALF_KERNEL);
|
||||
}
|
||||
|
||||
void pixelTests16(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& descriptors)
|
||||
static void pixelTests16(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& descriptors)
|
||||
{
|
||||
for (int i = 0; i < (int)keypoints.size(); ++i)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ void pixelTests16(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& d
|
||||
}
|
||||
}
|
||||
|
||||
void pixelTests32(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& descriptors)
|
||||
static void pixelTests32(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& descriptors)
|
||||
{
|
||||
for (int i = 0; i < (int)keypoints.size(); ++i)
|
||||
{
|
||||
@@ -82,7 +82,7 @@ void pixelTests32(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& d
|
||||
}
|
||||
}
|
||||
|
||||
void pixelTests64(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& descriptors)
|
||||
static void pixelTests64(const Mat& sum, const std::vector<KeyPoint>& keypoints, Mat& descriptors)
|
||||
{
|
||||
for (int i = 0; i < (int)keypoints.size(); ++i)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ DescriptorExtractor::~DescriptorExtractor()
|
||||
{}
|
||||
|
||||
void DescriptorExtractor::compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const
|
||||
{
|
||||
{
|
||||
if( image.empty() || keypoints.empty() )
|
||||
{
|
||||
descriptors.release();
|
||||
@@ -102,7 +102,7 @@ Ptr<DescriptorExtractor> DescriptorExtractor::create(const string& descriptorExt
|
||||
string type = descriptorExtractorType.substr(pos);
|
||||
return new OpponentColorDescriptorExtractor(DescriptorExtractor::create(type));
|
||||
}
|
||||
|
||||
|
||||
return Algorithm::create<DescriptorExtractor>("Feature2D." + descriptorExtractorType);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor( const Ptr<De
|
||||
CV_Assert( !descriptorExtractor.empty() );
|
||||
}
|
||||
|
||||
void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, vector<Mat>& opponentChannels )
|
||||
static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, vector<Mat>& opponentChannels )
|
||||
{
|
||||
if( bgrImage.type() != CV_8UC3 )
|
||||
CV_Error( CV_StsBadArg, "input image must be an BGR image of type CV_8UC3" );
|
||||
@@ -227,7 +227,7 @@ void OpponentColorDescriptorExtractor::computeImpl( const Mat& bgrImage, vector<
|
||||
Mat mergedDescriptors( maxKeypointsCount, 3*descriptorSize, descriptorExtractor->descriptorType() );
|
||||
int mergedCount = 0;
|
||||
// cp - current channel position
|
||||
size_t cp[] = {0, 0, 0};
|
||||
size_t cp[] = {0, 0, 0};
|
||||
while( cp[0] < channelKeypoints[0].size() &&
|
||||
cp[1] < channelKeypoints[1].size() &&
|
||||
cp[2] < channelKeypoints[2].size() )
|
||||
|
||||
@@ -45,7 +45,7 @@ using namespace std;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* FeatureDetector
|
||||
*/
|
||||
@@ -95,19 +95,19 @@ Ptr<FeatureDetector> FeatureDetector::create( const string& detectorType )
|
||||
return new GridAdaptedFeatureDetector(FeatureDetector::create(
|
||||
detectorType.substr(strlen("Grid"))));
|
||||
}
|
||||
|
||||
|
||||
if( detectorType.find("Pyramid") == 0 )
|
||||
{
|
||||
return new PyramidAdaptedFeatureDetector(FeatureDetector::create(
|
||||
detectorType.substr(strlen("Pyramid"))));
|
||||
}
|
||||
|
||||
|
||||
if( detectorType.find("Dynamic") == 0 )
|
||||
{
|
||||
return new DynamicAdaptedFeatureDetector(AdjusterAdapter::create(
|
||||
detectorType.substr(strlen("Dynamic"))));
|
||||
}
|
||||
|
||||
|
||||
if( detectorType.compare( "HARRIS" ) == 0 )
|
||||
{
|
||||
Ptr<FeatureDetector> fd = FeatureDetector::create("GFTT");
|
||||
@@ -149,13 +149,13 @@ void GFTTDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, co
|
||||
/*
|
||||
* DenseFeatureDetector
|
||||
*/
|
||||
DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels,
|
||||
float _featureScaleMul, int _initXyStep,
|
||||
int _initImgBound, bool _varyXyStepWithScale,
|
||||
bool _varyImgBoundWithScale ) :
|
||||
initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels),
|
||||
featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound),
|
||||
varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale)
|
||||
DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels,
|
||||
float _featureScaleMul, int _initXyStep,
|
||||
int _initImgBound, bool _varyXyStepWithScale,
|
||||
bool _varyImgBoundWithScale ) :
|
||||
initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels),
|
||||
featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound),
|
||||
varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale)
|
||||
{}
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ struct ResponseComparator
|
||||
}
|
||||
};
|
||||
|
||||
void keepStrongest( int N, vector<KeyPoint>& keypoints )
|
||||
static void keepStrongest( int N, vector<KeyPoint>& keypoints )
|
||||
{
|
||||
if( (int)keypoints.size() > N )
|
||||
{
|
||||
|
||||
@@ -42,8 +42,7 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
using namespace cv;
|
||||
|
||||
/////////////////////// AlgorithmInfo for various detector & descriptors ////////////////////////////
|
||||
|
||||
@@ -54,7 +53,7 @@ namespace cv
|
||||
|
||||
CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF",
|
||||
obj.info()->addParam(obj, "bytes", obj.bytes_));
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST",
|
||||
@@ -69,7 +68,7 @@ CV_INIT_ALGORITHM(StarDetector, "Feature2D.STAR",
|
||||
obj.info()->addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected);
|
||||
obj.info()->addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized);
|
||||
obj.info()->addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize));
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_INIT_ALGORITHM(MSER, "Feature2D.MSER",
|
||||
@@ -81,8 +80,8 @@ CV_INIT_ALGORITHM(MSER, "Feature2D.MSER",
|
||||
obj.info()->addParam(obj, "maxEvolution", obj.maxEvolution);
|
||||
obj.info()->addParam(obj, "areaThreshold", obj.areaThreshold);
|
||||
obj.info()->addParam(obj, "minMargin", obj.minMargin);
|
||||
obj.info()->addParam(obj, "edgeBlurSize", obj.edgeBlurSize));
|
||||
|
||||
obj.info()->addParam(obj, "edgeBlurSize", obj.edgeBlurSize));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_INIT_ALGORITHM(ORB, "Feature2D.ORB",
|
||||
@@ -96,7 +95,7 @@ CV_INIT_ALGORITHM(ORB, "Feature2D.ORB",
|
||||
obj.info()->addParam(obj, "scoreType", obj.scoreType));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
CV_INIT_ALGORITHM(GFTTDetector, "Feature2D.GFTT",
|
||||
obj.info()->addParam(obj, "nfeatures", obj.nfeatures);
|
||||
obj.info()->addParam(obj, "qualityLevel", obj.qualityLevel);
|
||||
@@ -105,7 +104,7 @@ CV_INIT_ALGORITHM(GFTTDetector, "Feature2D.GFTT",
|
||||
obj.info()->addParam(obj, "k", obj.k));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class CV_EXPORTS HarrisDetector : public GFTTDetector
|
||||
{
|
||||
public:
|
||||
@@ -113,7 +112,7 @@ public:
|
||||
int blockSize=3, bool useHarrisDetector=true, double k=0.04 )
|
||||
: GFTTDetector( maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, k ) {}
|
||||
AlgorithmInfo* info() const;
|
||||
};
|
||||
};
|
||||
|
||||
CV_INIT_ALGORITHM(HarrisDetector, "Feature2D.HARRIS",
|
||||
obj.info()->addParam(obj, "nfeatures", obj.nfeatures);
|
||||
@@ -122,7 +121,7 @@ CV_INIT_ALGORITHM(HarrisDetector, "Feature2D.HARRIS",
|
||||
obj.info()->addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
|
||||
obj.info()->addParam(obj, "k", obj.k));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_INIT_ALGORITHM(DenseFeatureDetector, "Feature2D.Dense",
|
||||
obj.info()->addParam(obj, "initFeatureScale", obj.initFeatureScale);
|
||||
@@ -134,22 +133,23 @@ CV_INIT_ALGORITHM(DenseFeatureDetector, "Feature2D.Dense",
|
||||
obj.info()->addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale));
|
||||
|
||||
CV_INIT_ALGORITHM(GridAdaptedFeatureDetector, "Feature2D.Grid",
|
||||
obj.info()->addParam(obj, "detector", (Ptr<Algorithm>&)obj.detector);
|
||||
//obj.info()->addParam(obj, "detector", (Ptr<Algorithm>&)obj.detector);
|
||||
obj.info()->addParam(obj, "maxTotalKeypoints", obj.maxTotalKeypoints);
|
||||
obj.info()->addParam(obj, "gridRows", obj.gridRows);
|
||||
obj.info()->addParam(obj, "gridCols", obj.gridCols));
|
||||
|
||||
bool initModule_features2d(void)
|
||||
bool cv::initModule_features2d(void)
|
||||
{
|
||||
Ptr<Algorithm> brief = createBriefDescriptorExtractor(), orb = createORB(),
|
||||
star = createStarDetector(), fastd = createFastFeatureDetector(), mser = createMSER(),
|
||||
dense = createDenseFeatureDetector(), gftt = createGFTTDetector(),
|
||||
harris = createHarrisDetector(), grid = createGridAdaptedFeatureDetector();
|
||||
|
||||
return brief->info() != 0 && orb->info() != 0 && star->info() != 0 &&
|
||||
fastd->info() != 0 && mser->info() != 0 && dense->info() != 0 &&
|
||||
gftt->info() != 0 && harris->info() != 0 && grid->info() != 0;
|
||||
}
|
||||
bool all = true;
|
||||
all &= !BriefDescriptorExtractor_info_auto.name().empty();
|
||||
all &= !FastFeatureDetector_info_auto.name().empty();
|
||||
all &= !StarDetector_info_auto.name().empty();
|
||||
all &= !MSER_info_auto.name().empty();
|
||||
all &= !ORB_info_auto.name().empty();
|
||||
all &= !GFTTDetector_info_auto.name().empty();
|
||||
all &= !HarrisDetector_info_auto.name().empty();
|
||||
all &= !DenseFeatureDetector_info_auto.name().empty();
|
||||
all &= !GridAdaptedFeatureDetector_info_auto.name().empty();
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ int DescriptorMatcher::DescriptorCollection::size() const
|
||||
/*
|
||||
* DescriptorMatcher
|
||||
*/
|
||||
void convertMatches( const vector<vector<DMatch> >& knnMatches, vector<DMatch>& matches )
|
||||
static void convertMatches( const vector<vector<DMatch> >& knnMatches, vector<DMatch>& matches )
|
||||
{
|
||||
matches.clear();
|
||||
matches.reserve( knnMatches.size() );
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4512 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
|
||||
@@ -493,23 +493,6 @@ private:
|
||||
CV_DescriptorExtractorTest& operator=(const CV_DescriptorExtractorTest&) { return *this; }
|
||||
};
|
||||
|
||||
/*template<typename T, typename Distance>
|
||||
class CV_CalonderDescriptorExtractorTest : public CV_DescriptorExtractorTest<Distance>
|
||||
{
|
||||
public:
|
||||
CV_CalonderDescriptorExtractorTest( const char* testName, float _normDif, float _prevTime ) :
|
||||
CV_DescriptorExtractorTest<Distance>( testName, _normDif, Ptr<DescriptorExtractor>(), _prevTime )
|
||||
{}
|
||||
|
||||
protected:
|
||||
virtual void createDescriptorExtractor()
|
||||
{
|
||||
CV_DescriptorExtractorTest<Distance>::dextractor =
|
||||
new CalonderDescriptorExtractor<T>( string(CV_DescriptorExtractorTest<Distance>::ts->get_data_path()) +
|
||||
FEATURES2D_DIR + "/calonder_classifier.rtc");
|
||||
}
|
||||
};*/
|
||||
|
||||
/****************************************************************************************\
|
||||
* Algorithmic tests for descriptor matchers *
|
||||
\****************************************************************************************/
|
||||
@@ -1059,24 +1042,6 @@ TEST( Features2d_DescriptorExtractor_BRIEF, regression )
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
#if CV_SSE2
|
||||
TEST( Features2d_DescriptorExtractor_Calonder_uchar, regression )
|
||||
{
|
||||
CV_CalonderDescriptorExtractorTest<uchar, L2<uchar> > test( "descriptor-calonder-uchar",
|
||||
std::numeric_limits<float>::epsilon() + 1,
|
||||
0.0132175f );
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
TEST( Features2d_DescriptorExtractor_Calonder_float, regression )
|
||||
{
|
||||
CV_CalonderDescriptorExtractorTest<float, L2<float> > test( "descriptor-calonder-float",
|
||||
std::numeric_limits<float>::epsilon(),
|
||||
0.0221308f );
|
||||
test.safe_run();
|
||||
}
|
||||
#endif // CV_SSE2
|
||||
|
||||
/*
|
||||
* Matchers
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,7 @@ struct base_any_policy
|
||||
virtual ::size_t get_size() = 0;
|
||||
virtual const std::type_info& type() = 0;
|
||||
virtual void print(std::ostream& out, void* const* src) = 0;
|
||||
virtual ~base_any_policy() {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_
|
||||
#define OPENCV_FLANN_DYNAMIC_BITSET_H_
|
||||
|
||||
#ifndef FLANN_USE_BOOST
|
||||
# define FLANN_USE_BOOST 0
|
||||
#endif
|
||||
//#define FLANN_USE_BOOST 1
|
||||
#if FLANN_USE_BOOST
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
@@ -40,6 +40,11 @@
|
||||
#include <iomanip>
|
||||
#include <limits.h>
|
||||
// TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
# define USE_UNORDERED_MAP 1
|
||||
#else
|
||||
# define USE_UNORDERED_MAP 0
|
||||
#endif
|
||||
#if USE_UNORDERED_MAP
|
||||
#include <unordered_map>
|
||||
#else
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "perf_utility.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "perf_utility.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
|
||||
@@ -81,6 +81,10 @@ if(HAVE_QT)
|
||||
|
||||
list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
|
||||
list(APPEND highgui_srcs src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES} )
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS "-Wno-missing-declarations")
|
||||
endif()
|
||||
elseif(WIN32)
|
||||
list(APPEND highgui_srcs src/window_w32.cpp)
|
||||
elseif(HAVE_GTK)
|
||||
@@ -131,6 +135,10 @@ if(HAVE_OPENNI)
|
||||
list(APPEND highgui_srcs src/cap_openni.cpp)
|
||||
ocv_include_directories(${OPENNI_INCLUDE_DIR})
|
||||
list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY})
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set_source_files_properties(src/cap_openni.cpp PROPERTIES COMPILE_FLAGS "-Wno-unknown-pragmas -Wno-uninitialized -Wno-reorder -Wno-strict-aliasing")
|
||||
endif()
|
||||
endif(HAVE_OPENNI)
|
||||
|
||||
if(HAVE_opencv_androidcamera)
|
||||
|
||||
@@ -79,7 +79,7 @@ CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms C
|
||||
CVAPI(void) cvSaveWindowParameters(const char* name);
|
||||
CVAPI(void) cvLoadWindowParameters(const char* name);
|
||||
CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
||||
CVAPI(void) cvStopLoop();
|
||||
CVAPI(void) cvStopLoop( void );
|
||||
|
||||
typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata);
|
||||
enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1, CV_RADIOBOX = 2};
|
||||
@@ -90,7 +90,7 @@ CVAPI(int) cvCreateButton( const char* button_name CV_DEFAULT(NULL),CvButtonCall
|
||||
/* this function is used to set some external parameters in case of X Window */
|
||||
CVAPI(int) cvInitSystem( int argc, char** argv );
|
||||
|
||||
CVAPI(int) cvStartWindowThread();
|
||||
CVAPI(int) cvStartWindowThread( void );
|
||||
|
||||
// --------- YV ---------
|
||||
enum
|
||||
@@ -100,16 +100,16 @@ enum
|
||||
CV_WND_PROP_AUTOSIZE = 1, //to change/get window's autosize property
|
||||
CV_WND_PROP_ASPECTRATIO= 2, //to change/get window's aspectratio property
|
||||
CV_WND_PROP_OPENGL = 3, //to change/get window's opengl support
|
||||
|
||||
|
||||
//These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty
|
||||
CV_WINDOW_NORMAL = 0x00000000, //the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size
|
||||
CV_WINDOW_AUTOSIZE = 0x00000001, //the user cannot resize the window, the size is constrainted by the image displayed
|
||||
CV_WINDOW_OPENGL = 0x00001000, //window with opengl support
|
||||
|
||||
|
||||
//Those flags are only for Qt
|
||||
CV_GUI_EXPANDED = 0x00000000, //status bar and tool bar
|
||||
CV_GUI_NORMAL = 0x00000010, //old fashious way
|
||||
|
||||
|
||||
//These 3 flags are used by cvNamedWindow and cvSet/GetWindowProperty
|
||||
CV_WINDOW_FULLSCREEN = 1,//change the window to fullscreen
|
||||
CV_WINDOW_FREERATIO = 0x00000100,//the image expends as much as it can (no ratio constraint)
|
||||
@@ -303,10 +303,10 @@ enum
|
||||
CV_CAP_OPENNI_ASUS =910, // OpenNI (for Asus Xtion)
|
||||
|
||||
CV_CAP_ANDROID =1000, // Android
|
||||
|
||||
|
||||
CV_CAP_XIAPI =1100, // XIMEA Camera API
|
||||
|
||||
CV_CAP_AVFOUNDATION = 1200 // AVFoundation framework for iOS (OS X Lion will have the same API)
|
||||
|
||||
CV_CAP_AVFOUNDATION = 1200 // AVFoundation framework for iOS (OS X Lion will have the same API)
|
||||
};
|
||||
|
||||
/* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
|
||||
@@ -367,15 +367,15 @@ enum
|
||||
CV_CAP_PROP_TRIGGER_DELAY =25,
|
||||
CV_CAP_PROP_WHITE_BALANCE_RED_V =26,
|
||||
CV_CAP_PROP_ZOOM =27,
|
||||
CV_CAP_PROP_FOCUS =28,
|
||||
CV_CAP_PROP_GUID =29,
|
||||
CV_CAP_PROP_ISO_SPEED =30,
|
||||
CV_CAP_PROP_FOCUS =28,
|
||||
CV_CAP_PROP_GUID =29,
|
||||
CV_CAP_PROP_ISO_SPEED =30,
|
||||
CV_CAP_PROP_MAX_DC1394 =31,
|
||||
CV_CAP_PROP_BACKLIGHT =32,
|
||||
CV_CAP_PROP_PAN =33,
|
||||
CV_CAP_PROP_TILT =34,
|
||||
CV_CAP_PROP_ROLL =35,
|
||||
CV_CAP_PROP_IRIS =36,
|
||||
CV_CAP_PROP_BACKLIGHT =32,
|
||||
CV_CAP_PROP_PAN =33,
|
||||
CV_CAP_PROP_TILT =34,
|
||||
CV_CAP_PROP_ROLL =35,
|
||||
CV_CAP_PROP_IRIS =36,
|
||||
CV_CAP_PROP_SETTINGS =37,
|
||||
|
||||
CV_CAP_PROP_AUTOGRAB =1024, // property for highgui class CvCapture_Android only
|
||||
@@ -409,24 +409,24 @@ enum
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH,
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_REGISTRATION,
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION,
|
||||
|
||||
|
||||
// Properties of cameras available through GStreamer interface
|
||||
CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1
|
||||
CV_CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast
|
||||
|
||||
|
||||
// Properties of cameras available through XIMEA SDK interface
|
||||
CV_CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping.
|
||||
CV_CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping.
|
||||
CV_CAP_PROP_XI_DATA_FORMAT = 401, // Output data format.
|
||||
CV_CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels).
|
||||
CV_CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels).
|
||||
CV_CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger.
|
||||
CV_CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE.
|
||||
CV_CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input
|
||||
CV_CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input
|
||||
CV_CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode
|
||||
CV_CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level
|
||||
CV_CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output
|
||||
CV_CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output
|
||||
CV_CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode
|
||||
CV_CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED
|
||||
CV_CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED
|
||||
CV_CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality
|
||||
CV_CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition)
|
||||
CV_CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance
|
||||
@@ -436,7 +436,7 @@ enum
|
||||
CV_CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure
|
||||
CV_CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %)
|
||||
CV_CAP_PROP_XI_TIMEOUT = 420, // Image capture timeout in milliseconds
|
||||
|
||||
|
||||
// Properties for Android cameras
|
||||
CV_CAP_PROP_ANDROID_FLASH_MODE = 8001,
|
||||
CV_CAP_PROP_ANDROID_FOCUS_MODE = 8002,
|
||||
@@ -532,7 +532,7 @@ CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
|
||||
CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
|
||||
|
||||
// Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY
|
||||
CVAPI(int) cvGetCaptureDomain( CvCapture* capture);
|
||||
CVAPI(int) cvGetCaptureDomain( CvCapture* capture);
|
||||
|
||||
/* "black box" video file writer structure */
|
||||
typedef struct CvVideoWriter CvVideoWriter;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "opencv2/ts/ts.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
+38
-38
@@ -41,7 +41,7 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4711 )
|
||||
#endif
|
||||
|
||||
@@ -282,7 +282,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
|
||||
return capture;
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_PVAPI
|
||||
case CV_CAP_PVAPI:
|
||||
capture = cvCreateCameraCapture_PvAPI (index);
|
||||
@@ -306,7 +306,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
|
||||
return capture;
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_XIMEA
|
||||
case CV_CAP_XIAPI:
|
||||
capture = cvCreateCameraCapture_XIMEA (index);
|
||||
@@ -354,7 +354,7 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
|
||||
if (! result)
|
||||
result = cvCreateFileCapture_QT (filename);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_AVFOUNDATION
|
||||
if (! result)
|
||||
result = cvCreateFileCapture_AVFoundation (filename);
|
||||
@@ -364,7 +364,7 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
|
||||
if (! result)
|
||||
result = cvCreateFileCapture_OpenNI (filename);
|
||||
#endif
|
||||
|
||||
|
||||
if (! result)
|
||||
result = cvCreateFileCapture_Images (filename);
|
||||
|
||||
@@ -378,29 +378,29 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
|
||||
CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color )
|
||||
{
|
||||
//CV_FUNCNAME( "cvCreateVideoWriter" );
|
||||
//CV_FUNCNAME( "cvCreateVideoWriter" );
|
||||
|
||||
CvVideoWriter *result = 0;
|
||||
CvVideoWriter *result = 0;
|
||||
|
||||
if(!fourcc || !fps)
|
||||
result = cvCreateVideoWriter_Images(filename);
|
||||
if(!fourcc || !fps)
|
||||
result = cvCreateVideoWriter_Images(filename);
|
||||
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color);
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color);
|
||||
|
||||
/* #ifdef HAVE_XINE
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color);
|
||||
#endif
|
||||
/* #ifdef HAVE_XINE
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color);
|
||||
#endif
|
||||
*/
|
||||
#ifdef HAVE_AVFOUNDATION
|
||||
#ifdef HAVE_AVFOUNDATION
|
||||
if (! result)
|
||||
result = cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QUICKTIME
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color);
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GSTREAMER
|
||||
@@ -408,10 +408,10 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
|
||||
result = cvCreateVideoWriter_GStreamer(filename, fourcc, fps, frameSize, is_color);
|
||||
#endif
|
||||
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_Images(filename);
|
||||
if(!result)
|
||||
result = cvCreateVideoWriter_Images(filename);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
CV_IMPL int cvWriteFrame( CvVideoWriter* writer, const IplImage* image )
|
||||
@@ -434,12 +434,12 @@ namespace cv
|
||||
|
||||
VideoCapture::VideoCapture()
|
||||
{}
|
||||
|
||||
|
||||
VideoCapture::VideoCapture(const string& filename)
|
||||
{
|
||||
open(filename);
|
||||
}
|
||||
|
||||
|
||||
VideoCapture::VideoCapture(int device)
|
||||
{
|
||||
open(device);
|
||||
@@ -449,21 +449,21 @@ VideoCapture::~VideoCapture()
|
||||
{
|
||||
cap.release();
|
||||
}
|
||||
|
||||
|
||||
bool VideoCapture::open(const string& filename)
|
||||
{
|
||||
cap = cvCreateFileCapture(filename.c_str());
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
|
||||
bool VideoCapture::open(int device)
|
||||
{
|
||||
cap = cvCreateCameraCapture(device);
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
|
||||
bool VideoCapture::isOpened() const { return !cap.empty(); }
|
||||
|
||||
|
||||
void VideoCapture::release()
|
||||
{
|
||||
cap.release();
|
||||
@@ -473,7 +473,7 @@ bool VideoCapture::grab()
|
||||
{
|
||||
return cvGrabFrame(cap) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool VideoCapture::retrieve(Mat& image, int channel)
|
||||
{
|
||||
IplImage* _img = cvRetrieveFrame(cap, channel);
|
||||
@@ -500,18 +500,18 @@ bool VideoCapture::read(Mat& image)
|
||||
image.release();
|
||||
return !image.empty();
|
||||
}
|
||||
|
||||
|
||||
VideoCapture& VideoCapture::operator >> (Mat& image)
|
||||
{
|
||||
read(image);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool VideoCapture::set(int propId, double value)
|
||||
{
|
||||
return cvSetCaptureProperty(cap, propId, value) != 0;
|
||||
}
|
||||
|
||||
|
||||
double VideoCapture::get(int propId)
|
||||
{
|
||||
return cvGetCaptureProperty(cap, propId);
|
||||
@@ -519,7 +519,7 @@ double VideoCapture::get(int propId)
|
||||
|
||||
VideoWriter::VideoWriter()
|
||||
{}
|
||||
|
||||
|
||||
VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
open(filename, fourcc, fps, frameSize, isColor);
|
||||
@@ -528,13 +528,13 @@ VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size fr
|
||||
void VideoWriter::release()
|
||||
{
|
||||
writer.release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VideoWriter::~VideoWriter()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
|
||||
bool VideoWriter::open(const string& filename, int fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
writer = cvCreateVideoWriter(filename.c_str(), fourcc, fps, frameSize, isColor);
|
||||
@@ -544,18 +544,18 @@ bool VideoWriter::open(const string& filename, int fourcc, double fps, Size fram
|
||||
bool VideoWriter::isOpened() const
|
||||
{
|
||||
return !writer.empty();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoWriter::write(const Mat& image)
|
||||
{
|
||||
IplImage _img = image;
|
||||
cvWriteFrame(writer, &_img);
|
||||
}
|
||||
|
||||
|
||||
VideoWriter& VideoWriter::operator << (const Mat& image)
|
||||
{
|
||||
write(image);
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ icvInitFFMPEG(void)
|
||||
icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG;
|
||||
icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG;
|
||||
#endif
|
||||
|
||||
|
||||
ffmpegInitialized = 1;
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
{
|
||||
unsigned char* data = 0;
|
||||
int step=0, width=0, height=0, cn=0;
|
||||
|
||||
|
||||
if(!ffmpegCapture ||
|
||||
!icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn))
|
||||
return 0;
|
||||
@@ -193,7 +193,7 @@ CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename)
|
||||
return cvCreateFileCapture_VFW(filename);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -247,5 +247,5 @@ CvVideoWriter* cvCreateVideoWriter_FFMPEG_proxy( const char* filename, int fourc
|
||||
return cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, isColor);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ extern "C" {
|
||||
#ifndef HAVE_FFMPEG_SWSCALE
|
||||
#error "libswscale is necessary to build the newer OpenCV ffmpeg wrapper"
|
||||
#endif
|
||||
|
||||
|
||||
// if the header path is not specified explicitly, let's deduce it
|
||||
#if !defined HAVE_FFMPEG_AVCODEC_H && !defined HAVE_LIBAVCODEC_AVCODEC_H
|
||||
|
||||
@@ -140,7 +140,7 @@ extern "C" {
|
||||
#define AV_NOPTS_VALUE_ ((int64_t)AV_NOPTS_VALUE)
|
||||
#endif
|
||||
|
||||
int get_number_of_cpus(void)
|
||||
static int get_number_of_cpus(void)
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(52, 111, 0)
|
||||
return 1;
|
||||
@@ -210,7 +210,7 @@ struct CvCapture_FFMPEG
|
||||
|
||||
void seek(int64_t frame_number);
|
||||
void seek(double sec);
|
||||
bool slowSeek( int framenumber );
|
||||
bool slowSeek( int framenumber );
|
||||
|
||||
int64_t get_total_frames();
|
||||
double get_duration_sec();
|
||||
@@ -225,8 +225,8 @@ struct CvCapture_FFMPEG
|
||||
AVCodec * avcodec;
|
||||
int video_stream;
|
||||
AVStream * video_st;
|
||||
AVFrame * picture;
|
||||
AVFrame rgb_picture;
|
||||
AVFrame * picture;
|
||||
AVFrame rgb_picture;
|
||||
int64_t picture_pts;
|
||||
|
||||
AVPacket packet;
|
||||
@@ -274,7 +274,7 @@ void CvCapture_FFMPEG::close()
|
||||
sws_freeContext(img_convert_ctx);
|
||||
img_convert_ctx = 0;
|
||||
}
|
||||
|
||||
|
||||
if( picture )
|
||||
av_free(picture);
|
||||
|
||||
@@ -293,9 +293,9 @@ void CvCapture_FFMPEG::close()
|
||||
if( ic )
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
|
||||
av_close_input_file(ic);
|
||||
av_close_input_file(ic);
|
||||
#else
|
||||
avformat_close_input(&ic);
|
||||
avformat_close_input(&ic);
|
||||
#endif
|
||||
|
||||
ic = NULL;
|
||||
@@ -337,7 +337,7 @@ static void icvInitFFMPEG_internal()
|
||||
av_register_all();
|
||||
|
||||
av_log_set_level(AV_LOG_ERROR);
|
||||
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -345,18 +345,18 @@ static void icvInitFFMPEG_internal()
|
||||
bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
{
|
||||
icvInitFFMPEG_internal();
|
||||
|
||||
|
||||
unsigned i;
|
||||
bool valid = false;
|
||||
|
||||
close();
|
||||
|
||||
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
|
||||
int err = avformat_open_input(&ic, _filename, NULL, NULL);
|
||||
#else
|
||||
int err = av_open_input_file(&ic, _filename, NULL, 0, NULL);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (err < 0) {
|
||||
CV_WARN("Error opening file");
|
||||
goto exit_func;
|
||||
@@ -438,13 +438,13 @@ bool CvCapture_FFMPEG::grabFrame()
|
||||
const int max_number_of_attempts = 1 << 16;
|
||||
|
||||
if( !ic || !video_st ) return false;
|
||||
|
||||
|
||||
if( ic->streams[video_stream]->nb_frames > 0 &&
|
||||
frame_number > ic->streams[video_stream]->nb_frames )
|
||||
return false;
|
||||
|
||||
av_free_packet (&packet);
|
||||
|
||||
|
||||
picture_pts = AV_NOPTS_VALUE_;
|
||||
|
||||
// get the next frame
|
||||
@@ -463,7 +463,7 @@ bool CvCapture_FFMPEG::grabFrame()
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Decode video frame
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
|
||||
@@ -498,7 +498,7 @@ bool CvCapture_FFMPEG::grabFrame()
|
||||
|
||||
if( valid && first_frame_number < 0 )
|
||||
first_frame_number = dts_to_frame_number(picture_pts);
|
||||
|
||||
|
||||
// return if we have a new picture or not
|
||||
return valid;
|
||||
}
|
||||
@@ -518,7 +518,7 @@ bool CvCapture_FFMPEG::retrieveFrame(int, unsigned char** data, int* step, int*
|
||||
{
|
||||
if( img_convert_ctx )
|
||||
sws_freeContext(img_convert_ctx);
|
||||
|
||||
|
||||
frame.width = video_st->codec->width;
|
||||
frame.height = video_st->codec->height;
|
||||
|
||||
@@ -629,7 +629,7 @@ double CvCapture_FFMPEG::get_fps()
|
||||
{
|
||||
fps = r2d(ic->streams[video_stream]->avg_frame_rate);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (fps < eps_zero)
|
||||
{
|
||||
@@ -666,12 +666,12 @@ void CvCapture_FFMPEG::seek(int64_t _frame_number)
|
||||
{
|
||||
_frame_number = std::min(_frame_number, get_total_frames());
|
||||
int delta = 16;
|
||||
|
||||
|
||||
// if we have not grabbed a single frame before first seek, let's read the first frame
|
||||
// and get some valuable information during the process
|
||||
if( first_frame_number < 0 && get_total_frames() > 1 )
|
||||
grabFrame();
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int64_t _frame_number_temp = std::max(_frame_number-delta, (int64_t)0);
|
||||
@@ -684,13 +684,13 @@ void CvCapture_FFMPEG::seek(int64_t _frame_number)
|
||||
if( _frame_number > 0 )
|
||||
{
|
||||
grabFrame();
|
||||
|
||||
|
||||
if( _frame_number > 1 )
|
||||
{
|
||||
frame_number = dts_to_frame_number(picture_pts) - first_frame_number;
|
||||
//printf("_frame_number = %d, frame_number = %d, delta = %d\n",
|
||||
// (int)_frame_number, (int)frame_number, delta);
|
||||
|
||||
|
||||
if( frame_number < 0 || frame_number > _frame_number-1 )
|
||||
{
|
||||
if( _frame_number_temp == 0 || delta >= INT_MAX/4 )
|
||||
@@ -771,7 +771,7 @@ struct CvVideoWriter_FFMPEG
|
||||
|
||||
void init();
|
||||
|
||||
AVOutputFormat * fmt;
|
||||
AVOutputFormat * fmt;
|
||||
AVFormatContext * oc;
|
||||
uint8_t * outbuf;
|
||||
uint32_t outbuf_size;
|
||||
@@ -1010,7 +1010,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
|
||||
|
||||
static const int OPENCV_NO_FRAMES_WRITTEN_CODE = 1000;
|
||||
|
||||
int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture )
|
||||
static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture )
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext * c = video_st->codec;
|
||||
@@ -1046,7 +1046,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
if(c->coded_frame->pts != (int64_t)AV_NOPTS_VALUE)
|
||||
pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
|
||||
pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
|
||||
#else
|
||||
pkt.pts = c->coded_frame->pts;
|
||||
#endif
|
||||
@@ -1069,7 +1069,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
|
||||
bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int width, int height, int cn, int origin )
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
|
||||
if( (width & -2) != frame_width || (height & -2) != frame_height || !data )
|
||||
return false;
|
||||
width = frame_width;
|
||||
@@ -1180,7 +1180,7 @@ void CvVideoWriter_FFMPEG::close()
|
||||
// nothing to do if already released
|
||||
if ( !picture )
|
||||
return;
|
||||
|
||||
|
||||
/* no more frame to compress. The codec has a latency of a few
|
||||
frames if using B frames, so we get the last frames by
|
||||
passing the same picture again */
|
||||
@@ -1200,7 +1200,7 @@ void CvVideoWriter_FFMPEG::close()
|
||||
}
|
||||
av_write_trailer(oc);
|
||||
}
|
||||
|
||||
|
||||
if( img_convert_ctx )
|
||||
{
|
||||
sws_freeContext(img_convert_ctx);
|
||||
@@ -1272,7 +1272,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
double fps, int width, int height, bool is_color )
|
||||
{
|
||||
icvInitFFMPEG_internal();
|
||||
|
||||
|
||||
CodecID codec_id = CODEC_ID_NONE;
|
||||
int err, codec_pix_fmt;
|
||||
double bitrate_scale = 1;
|
||||
@@ -1284,7 +1284,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
return false;
|
||||
if(fps <= 0)
|
||||
return false;
|
||||
|
||||
|
||||
// we allow frames of odd width or height, but in this case we truncate
|
||||
// the rightmost column/the bottom row. Probably, this should be handled more elegantly,
|
||||
// but some internal functions inside FFMPEG swscale require even width/height.
|
||||
@@ -1363,7 +1363,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
codec_pix_fmt = PIX_FMT_YUV420P;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
double bitrate = MIN(bitrate_scale*fps*width*height, (double)INT_MAX/2);
|
||||
|
||||
// TODO -- safe to ignore output audio stream?
|
||||
@@ -1480,8 +1480,8 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
err=avformat_write_header(oc, NULL);
|
||||
#else
|
||||
err=av_write_header( oc );
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if(err < 0)
|
||||
{
|
||||
close();
|
||||
@@ -1579,7 +1579,7 @@ struct OutputMediaStream_FFMPEG
|
||||
{
|
||||
bool open(const char* fileName, int width, int height, double fps);
|
||||
void close();
|
||||
|
||||
|
||||
void write(unsigned char* data, int size, int keyFrame);
|
||||
|
||||
// add a video output stream to the container
|
||||
@@ -1692,7 +1692,7 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CodecID
|
||||
{
|
||||
AVRational error = av_sub_q(req, *p);
|
||||
|
||||
if (error.num < 0)
|
||||
if (error.num < 0)
|
||||
error.num *= -1;
|
||||
|
||||
if (av_cmp_q(error, best_error) < 0)
|
||||
@@ -1825,7 +1825,7 @@ bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height,
|
||||
void OutputMediaStream_FFMPEG::write(unsigned char* data, int size, int keyFrame)
|
||||
{
|
||||
// if zero size, it means the image was buffered
|
||||
if (size > 0)
|
||||
if (size > 0)
|
||||
{
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
@@ -1851,7 +1851,7 @@ struct OutputMediaStream_FFMPEG* create_OutputMediaStream_FFMPEG(const char* fil
|
||||
|
||||
stream->close();
|
||||
free(stream);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,20 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
|
||||
#ifndef i386
|
||||
# define i386 0
|
||||
#endif
|
||||
#ifndef __arm__
|
||||
# define __arm__ 0
|
||||
#endif
|
||||
#ifndef _ARC
|
||||
# define _ARC 0
|
||||
#endif
|
||||
#ifndef __APPLE__
|
||||
# define __APPLE__ 0
|
||||
#endif
|
||||
|
||||
#include "XnCppWrapper.h"
|
||||
|
||||
const std::string XMLConfig =
|
||||
@@ -169,6 +183,8 @@ private:
|
||||
approxSyncGrabber(approxSyncGrabber), isDepthFilled(false), isImageFilled(false)
|
||||
{}
|
||||
|
||||
virtual ~ApproximateSynchronizerBase() {}
|
||||
|
||||
virtual bool isSpinContinue() const = 0;
|
||||
virtual void pushDepthMetaData( xn::DepthMetaData& depthMetaData ) = 0;
|
||||
virtual void pushImageMetaData( xn::ImageMetaData& imageMetaData ) = 0;
|
||||
@@ -410,7 +426,7 @@ class CvCapture_OpenNI : public CvCapture
|
||||
{
|
||||
public:
|
||||
enum { DEVICE_DEFAULT=0, DEVICE_MS_KINECT=0, DEVICE_ASUS_XTION=1, DEVICE_MAX=1 };
|
||||
|
||||
|
||||
static const int INVALID_PIXEL_VAL = 0;
|
||||
static const int INVALID_COORDINATE_VAL = 0;
|
||||
|
||||
@@ -508,26 +524,26 @@ bool CvCapture_OpenNI::isOpened() const
|
||||
return isContextOpened;
|
||||
}
|
||||
|
||||
XnMapOutputMode defaultMapOutputMode()
|
||||
{
|
||||
XnMapOutputMode mode;
|
||||
mode.nXRes = XN_VGA_X_RES;
|
||||
mode.nYRes = XN_VGA_Y_RES;
|
||||
mode.nFPS = 30;
|
||||
return mode;
|
||||
}
|
||||
// static XnMapOutputMode defaultMapOutputMode()
|
||||
// {
|
||||
// XnMapOutputMode mode;
|
||||
// mode.nXRes = XN_VGA_X_RES;
|
||||
// mode.nYRes = XN_VGA_Y_RES;
|
||||
// mode.nFPS = 30;
|
||||
// return mode;
|
||||
// }
|
||||
|
||||
|
||||
CvCapture_OpenNI::CvCapture_OpenNI( int index )
|
||||
{
|
||||
int deviceType = DEVICE_DEFAULT;
|
||||
XnStatus status;
|
||||
|
||||
|
||||
isContextOpened = false;
|
||||
maxBufferSize = DEFAULT_MAX_BUFFER_SIZE;
|
||||
isCircleBuffer = DEFAULT_IS_CIRCLE_BUFFER;
|
||||
maxTimeDuration = DEFAULT_MAX_TIME_DURATION;
|
||||
|
||||
|
||||
if( index >= 10 )
|
||||
{
|
||||
deviceType = index / 10;
|
||||
@@ -1201,7 +1217,7 @@ IplImage* CvCapture_OpenNI::retrievePointCloudMap()
|
||||
return outputMaps[CV_CAP_OPENNI_POINT_CLOUD_MAP].getIplImagePtr();
|
||||
}
|
||||
|
||||
void computeDisparity_32F( const xn::DepthMetaData& depthMetaData, cv::Mat& disp, XnDouble baseline, XnUInt64 F,
|
||||
static void computeDisparity_32F( const xn::DepthMetaData& depthMetaData, cv::Mat& disp, XnDouble baseline, XnUInt64 F,
|
||||
XnUInt64 noSampleValue, XnUInt64 shadowValue )
|
||||
{
|
||||
cv::Mat depth;
|
||||
|
||||
@@ -126,8 +126,7 @@ skip_input_data(j_decompress_ptr cinfo, long num_bytes)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_buffer_src(j_decompress_ptr cinfo, JpegSource* source)
|
||||
static void jpeg_buffer_src(j_decompress_ptr cinfo, JpegSource* source)
|
||||
{
|
||||
cinfo->src = &source->pub;
|
||||
|
||||
@@ -498,8 +497,7 @@ empty_output_buffer (j_compress_ptr cinfo)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_buffer_dest(j_compress_ptr cinfo, JpegDestination* destination)
|
||||
static void jpeg_buffer_dest(j_compress_ptr cinfo, JpegDestination* destination)
|
||||
{
|
||||
cinfo->dest = &destination->pub;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace cv
|
||||
static vector<ImageDecoder> decoders;
|
||||
static vector<ImageEncoder> encoders;
|
||||
|
||||
ImageDecoder findDecoder( const string& filename )
|
||||
static ImageDecoder findDecoder( const string& filename )
|
||||
{
|
||||
size_t i, maxlen = 0;
|
||||
for( i = 0; i < decoders.size(); i++ )
|
||||
@@ -83,7 +83,7 @@ ImageDecoder findDecoder( const string& filename )
|
||||
return ImageDecoder();
|
||||
}
|
||||
|
||||
ImageDecoder findDecoder( const Mat& buf )
|
||||
static ImageDecoder findDecoder( const Mat& buf )
|
||||
{
|
||||
size_t i, maxlen = 0;
|
||||
|
||||
@@ -110,7 +110,7 @@ ImageDecoder findDecoder( const Mat& buf )
|
||||
return ImageDecoder();
|
||||
}
|
||||
|
||||
ImageEncoder findEncoder( const string& _ext )
|
||||
static ImageEncoder findEncoder( const string& _ext )
|
||||
{
|
||||
if( _ext.size() <= 1 )
|
||||
return ImageEncoder();
|
||||
@@ -395,7 +395,7 @@ Mat imdecode( InputArray _buf, int flags )
|
||||
imdecode_( buf, flags, LOAD_MAT, &img );
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
bool imencode( const string& ext, InputArray _image,
|
||||
vector<uchar>& buf, const vector<int>& params )
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#ifndef __HIGHGUI_H_
|
||||
#define __HIGHGUI_H_
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 )
|
||||
#endif
|
||||
|
||||
|
||||
+1480
-1480
File diff suppressed because it is too large
Load Diff
@@ -1372,17 +1372,17 @@ cvDestroyAllWindows( void )
|
||||
CV_UNLOCK_MUTEX();
|
||||
}
|
||||
|
||||
CvSize icvCalcOptimalWindowSize( CvWindow * window, CvSize new_image_size){
|
||||
CvSize window_size;
|
||||
GtkWidget * toplevel = gtk_widget_get_toplevel( window->frame );
|
||||
gdk_drawable_get_size( GDK_DRAWABLE(toplevel->window),
|
||||
&window_size.width, &window_size.height );
|
||||
// CvSize icvCalcOptimalWindowSize( CvWindow * window, CvSize new_image_size){
|
||||
// CvSize window_size;
|
||||
// GtkWidget * toplevel = gtk_widget_get_toplevel( window->frame );
|
||||
// gdk_drawable_get_size( GDK_DRAWABLE(toplevel->window),
|
||||
// &window_size.width, &window_size.height );
|
||||
|
||||
window_size.width = window_size.width + new_image_size.width - window->widget->allocation.width;
|
||||
window_size.height = window_size.height + new_image_size.height - window->widget->allocation.height;
|
||||
// window_size.width = window_size.width + new_image_size.width - window->widget->allocation.width;
|
||||
// window_size.height = window_size.height + new_image_size.height - window->widget->allocation.height;
|
||||
|
||||
return window_size;
|
||||
}
|
||||
// return window_size;
|
||||
// }
|
||||
|
||||
CV_IMPL void
|
||||
cvShowImage( const char* name, const CvArr* arr )
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ typedef struct _list _CVLIST;
|
||||
_LIST_INLINE CVPOS prefix##get_tail_pos_##type(_CVLIST*);\
|
||||
_LIST_INLINE type* prefix##get_next_##type(CVPOS*);\
|
||||
_LIST_INLINE type* prefix##get_prev_##type(CVPOS*);\
|
||||
_LIST_INLINE int prefix##is_pos_##type(CVPOS pos);\
|
||||
/* Modification functions*/\
|
||||
_LIST_INLINE void prefix##clear_list_##type(_CVLIST*);\
|
||||
_LIST_INLINE CVPOS prefix##add_head_##type(_CVLIST*, type*);\
|
||||
@@ -151,8 +152,8 @@ typedef struct _list _CVLIST;
|
||||
}\
|
||||
element->m_next = ((element_type*)l->m_head_free.m_pos);\
|
||||
l->m_head_free.m_pos = element;
|
||||
|
||||
|
||||
|
||||
|
||||
/*#define GET_FIRST_FREE(l) ((ELEMENT_##type*)(l->m_head_free.m_pos))*/
|
||||
|
||||
#define IMPLEMENT_LIST(type, prefix)\
|
||||
|
||||
@@ -233,7 +233,7 @@ typedef DiffC3<cv::Vec3i> Diff32sC3;
|
||||
typedef DiffC1<float> Diff32fC1;
|
||||
typedef DiffC3<cv::Vec3f> Diff32fC3;
|
||||
|
||||
cv::Vec3i& operator += (cv::Vec3i& a, const cv::Vec3b& b)
|
||||
static cv::Vec3i& operator += (cv::Vec3i& a, const cv::Vec3b& b)
|
||||
{
|
||||
a[0] += b[0];
|
||||
a[1] += b[1];
|
||||
@@ -440,7 +440,7 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
|
||||
{
|
||||
cv::Ptr<CvMat> tempMask;
|
||||
cv::AutoBuffer<CvFFillSegment> buffer;
|
||||
|
||||
|
||||
if( comp )
|
||||
memset( comp, 0, sizeof(*comp) );
|
||||
|
||||
@@ -491,16 +491,16 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
|
||||
{
|
||||
/*int elem_size = CV_ELEM_SIZE(type);
|
||||
const uchar* seed_ptr = img->data.ptr + img->step*seed_point.y + elem_size*seed_point.x;
|
||||
|
||||
|
||||
// check if the new value is different from the current value at the seed point.
|
||||
// if they are exactly the same, use the generic version with mask to avoid infinite loops.
|
||||
for( i = 0; i < elem_size; i++ )
|
||||
if( seed_ptr[i] != ((uchar*)nv_buf)[i] )
|
||||
break;
|
||||
|
||||
|
||||
if( i == elem_size )
|
||||
return;*/
|
||||
|
||||
|
||||
if( type == CV_8UC1 )
|
||||
icvFloodFill_CnIR(img->data.ptr, img->step, size, seed_point, nv_buf.b[0],
|
||||
comp, flags, buffer, buffer_size);
|
||||
@@ -632,7 +632,7 @@ int cv::floodFill( InputOutputArray _image, Point seedPoint,
|
||||
}
|
||||
|
||||
int cv::floodFill( InputOutputArray _image, InputOutputArray _mask,
|
||||
Point seedPoint, Scalar newVal, Rect* rect,
|
||||
Point seedPoint, Scalar newVal, Rect* rect,
|
||||
Scalar loDiff, Scalar upDiff, int flags )
|
||||
{
|
||||
CvConnectedComp ccomp;
|
||||
|
||||
@@ -230,7 +230,7 @@ void GMM::calcInverseCovAndDeterm( int ci )
|
||||
Calculate beta - parameter of GrabCut algorithm.
|
||||
beta = 1/(2*avg(sqr(||color[i] - color[j]||)))
|
||||
*/
|
||||
double calcBeta( const Mat& img )
|
||||
static double calcBeta( const Mat& img )
|
||||
{
|
||||
double beta = 0;
|
||||
for( int y = 0; y < img.rows; y++ )
|
||||
@@ -272,7 +272,7 @@ double calcBeta( const Mat& img )
|
||||
Calculate weights of noterminal vertices of graph.
|
||||
beta and gamma - parameters of GrabCut algorithm.
|
||||
*/
|
||||
void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& uprightW, double beta, double gamma )
|
||||
static void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& uprightW, double beta, double gamma )
|
||||
{
|
||||
const double gammaDivSqrt2 = gamma / std::sqrt(2.0f);
|
||||
leftW.create( img.rows, img.cols, CV_64FC1 );
|
||||
@@ -319,7 +319,7 @@ void calcNWeights( const Mat& img, Mat& leftW, Mat& upleftW, Mat& upW, Mat& upri
|
||||
/*
|
||||
Check size, type and element values of mask matrix.
|
||||
*/
|
||||
void checkMask( const Mat& img, const Mat& mask )
|
||||
static void checkMask( const Mat& img, const Mat& mask )
|
||||
{
|
||||
if( mask.empty() )
|
||||
CV_Error( CV_StsBadArg, "mask is empty" );
|
||||
@@ -342,7 +342,7 @@ void checkMask( const Mat& img, const Mat& mask )
|
||||
/*
|
||||
Initialize mask using rectangular.
|
||||
*/
|
||||
void initMaskWithRect( Mat& mask, Size imgSize, Rect rect )
|
||||
static void initMaskWithRect( Mat& mask, Size imgSize, Rect rect )
|
||||
{
|
||||
mask.create( imgSize, CV_8UC1 );
|
||||
mask.setTo( GC_BGD );
|
||||
@@ -358,7 +358,7 @@ void initMaskWithRect( Mat& mask, Size imgSize, Rect rect )
|
||||
/*
|
||||
Initialize GMM background and foreground models using kmeans algorithm.
|
||||
*/
|
||||
void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM )
|
||||
static void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM )
|
||||
{
|
||||
const int kMeansItCount = 10;
|
||||
const int kMeansType = KMEANS_PP_CENTERS;
|
||||
@@ -398,7 +398,7 @@ void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM )
|
||||
/*
|
||||
Assign GMMs components for each pixel.
|
||||
*/
|
||||
void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, Mat& compIdxs )
|
||||
static void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, Mat& compIdxs )
|
||||
{
|
||||
Point p;
|
||||
for( p.y = 0; p.y < img.rows; p.y++ )
|
||||
@@ -415,7 +415,7 @@ void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bgdGMM, c
|
||||
/*
|
||||
Learn GMMs parameters.
|
||||
*/
|
||||
void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGMM, GMM& fgdGMM )
|
||||
static void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGMM, GMM& fgdGMM )
|
||||
{
|
||||
bgdGMM.initLearning();
|
||||
fgdGMM.initLearning();
|
||||
@@ -443,7 +443,7 @@ void learnGMMs( const Mat& img, const Mat& mask, const Mat& compIdxs, GMM& bgdGM
|
||||
/*
|
||||
Construct GCGraph
|
||||
*/
|
||||
void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, double lambda,
|
||||
static void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const GMM& fgdGMM, double lambda,
|
||||
const Mat& leftW, const Mat& upleftW, const Mat& upW, const Mat& uprightW,
|
||||
GCGraph<double>& graph )
|
||||
{
|
||||
@@ -506,7 +506,7 @@ void constructGCGraph( const Mat& img, const Mat& mask, const GMM& bgdGMM, const
|
||||
/*
|
||||
Estimate segmentation using MaxFlow algorithm
|
||||
*/
|
||||
void estimateSegmentation( GCGraph<double>& graph, Mat& mask )
|
||||
static void estimateSegmentation( GCGraph<double>& graph, Mat& mask )
|
||||
{
|
||||
graph.maxFlow();
|
||||
Point p;
|
||||
@@ -533,7 +533,7 @@ void cv::grabCut( InputArray _img, InputOutputArray _mask, Rect rect,
|
||||
Mat& mask = _mask.getMatRef();
|
||||
Mat& bgdModel = _bgdModel.getMatRef();
|
||||
Mat& fgdModel = _fgdModel.getMatRef();
|
||||
|
||||
|
||||
if( img.empty() )
|
||||
CV_Error( CV_StsBadArg, "image is empty" );
|
||||
if( img.type() != CV_8UC3 )
|
||||
|
||||
@@ -114,7 +114,7 @@ icvHoughLinesStandard( const CvMat* img, float rho, float theta,
|
||||
_tabCos.allocate(numangle);
|
||||
int *accum = _accum, *sort_buf = _sort_buf;
|
||||
float *tabSin = _tabSin, *tabCos = _tabCos;
|
||||
|
||||
|
||||
memset( accum, 0, sizeof(accum[0]) * (numangle+2) * (numrho+2) );
|
||||
|
||||
for( ang = 0, n = 0; n < numangle; ang += theta, n++ )
|
||||
@@ -249,7 +249,7 @@ icvHoughLinesSDiv( const CvMat* img,
|
||||
/* Precalculating sin */
|
||||
_sinTable.resize( 5 * tn * stn );
|
||||
sinTable = &_sinTable[0];
|
||||
|
||||
|
||||
for( index = 0; index < 5 * tn * stn; index++ )
|
||||
sinTable[index] = (float)cos( stheta * index * 0.2f );
|
||||
|
||||
@@ -449,7 +449,7 @@ icvHoughLinesSDiv( const CvMat* img,
|
||||
h_get_next__index( &pos );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
h_destroy_list__index(list);
|
||||
}
|
||||
|
||||
@@ -756,7 +756,7 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method,
|
||||
}
|
||||
else
|
||||
CV_Error( CV_StsBadArg, "Destination is not CvMemStorage* nor CvMat*" );
|
||||
|
||||
|
||||
iparam1 = cvRound(param1);
|
||||
iparam2 = cvRound(param2);
|
||||
|
||||
@@ -842,7 +842,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
acols = accum->cols - 2;
|
||||
adata = accum->data.i;
|
||||
astep = accum->step/sizeof(adata[0]);
|
||||
// Accumulate circle evidence for each edge pixel
|
||||
// Accumulate circle evidence for each edge pixel
|
||||
for( y = 0; y < rows; y++ )
|
||||
{
|
||||
const uchar* edges_row = edges->data.ptr + y*edges->step;
|
||||
@@ -868,7 +868,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
|
||||
x0 = cvRound((x*idp)*ONE);
|
||||
y0 = cvRound((y*idp)*ONE);
|
||||
// Step from min_radius to max_radius in both directions of the gradient
|
||||
// Step from min_radius to max_radius in both directions of the gradient
|
||||
for( k = 0; k < 2; k++ )
|
||||
{
|
||||
x1 = x0 + min_radius * sx;
|
||||
@@ -894,7 +894,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
nz_count = nz->total;
|
||||
if( !nz_count )
|
||||
return;
|
||||
//Find possible circle centers
|
||||
//Find possible circle centers
|
||||
for( y = 1; y < arows - 1; y++ )
|
||||
{
|
||||
for( x = 1; x < acols - 1; x++ )
|
||||
@@ -924,19 +924,19 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
dr = dp;
|
||||
min_dist = MAX( min_dist, dp );
|
||||
min_dist *= min_dist;
|
||||
// For each found possible center
|
||||
// Estimate radius and check support
|
||||
// For each found possible center
|
||||
// Estimate radius and check support
|
||||
for( i = 0; i < centers->total; i++ )
|
||||
{
|
||||
int ofs = *(int*)cvGetSeqElem( centers, i );
|
||||
y = ofs/(acols+2);
|
||||
x = ofs - (y)*(acols+2);
|
||||
//Calculate circle's center in pixels
|
||||
//Calculate circle's center in pixels
|
||||
float cx = (float)((x + 0.5f)*dp), cy = (float)(( y + 0.5f )*dp);
|
||||
float start_dist, dist_sum;
|
||||
float r_best = 0, c[3];
|
||||
int max_count = 0;
|
||||
// Check distance with previously detected circles
|
||||
// Check distance with previously detected circles
|
||||
for( j = 0; j < circles->total; j++ )
|
||||
{
|
||||
float* c = (float*)cvGetSeqElem( circles, j );
|
||||
@@ -946,7 +946,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
|
||||
if( j < circles->total )
|
||||
continue;
|
||||
// Estimate best radius
|
||||
// Estimate best radius
|
||||
cvStartReadSeq( nz, &reader );
|
||||
for( j = k = 0; j < nz_count; j++ )
|
||||
{
|
||||
@@ -982,7 +982,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
{
|
||||
float r_cur = ddata[sort_buf[(j + start_idx)/2]];
|
||||
if( (start_idx - j)*r_best >= max_count*r_cur ||
|
||||
(r_best < FLT_EPSILON && start_idx - j >= max_count) )
|
||||
(r_best < FLT_EPSILON && start_idx - j >= max_count) )
|
||||
{
|
||||
r_best = r_cur;
|
||||
max_count = start_idx - j;
|
||||
@@ -993,7 +993,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
}
|
||||
dist_sum += d;
|
||||
}
|
||||
// Check if the circle has enough support
|
||||
// Check if the circle has enough support
|
||||
if( max_count > acc_threshold )
|
||||
{
|
||||
c[0] = cx;
|
||||
@@ -1103,9 +1103,9 @@ static void seqToMat(const CvSeq* seq, OutputArray _arr)
|
||||
else
|
||||
_arr.release();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cv::HoughLines( InputArray _image, OutputArray _lines,
|
||||
double rho, double theta, int threshold,
|
||||
double srn, double stn )
|
||||
|
||||
@@ -406,42 +406,42 @@ static void fftShift(InputOutputArray _out)
|
||||
merge(planes, out);
|
||||
}
|
||||
|
||||
Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize)
|
||||
static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize)
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
|
||||
|
||||
int type = src.type();
|
||||
CV_Assert( type == CV_32FC1 || type == CV_64FC1 );
|
||||
|
||||
|
||||
int minr = peakLocation.y - (weightBoxSize.height >> 1);
|
||||
int maxr = peakLocation.y + (weightBoxSize.height >> 1);
|
||||
int minc = peakLocation.x - (weightBoxSize.width >> 1);
|
||||
int maxc = peakLocation.x + (weightBoxSize.width >> 1);
|
||||
|
||||
|
||||
Point2d centroid;
|
||||
double sumIntensity = 0.0;
|
||||
|
||||
|
||||
// clamp the values to min and max if needed.
|
||||
if(minr < 0)
|
||||
{
|
||||
minr = 0;
|
||||
}
|
||||
|
||||
|
||||
if(minc < 0)
|
||||
{
|
||||
minc = 0;
|
||||
}
|
||||
|
||||
|
||||
if(maxr > src.rows - 1)
|
||||
{
|
||||
maxr = src.rows - 1;
|
||||
}
|
||||
|
||||
|
||||
if(maxc > src.cols - 1)
|
||||
{
|
||||
maxc = src.cols - 1;
|
||||
}
|
||||
|
||||
|
||||
if(type == CV_32FC1)
|
||||
{
|
||||
const float* dataIn = (const float*)src.data;
|
||||
@@ -454,7 +454,7 @@ Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weigh
|
||||
centroid.y += (double)y*dataIn[x];
|
||||
sumIntensity += (double)dataIn[x];
|
||||
}
|
||||
|
||||
|
||||
dataIn += src.cols;
|
||||
}
|
||||
}
|
||||
@@ -470,19 +470,19 @@ Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weigh
|
||||
centroid.y += (double)y*dataIn[x];
|
||||
sumIntensity += dataIn[x];
|
||||
}
|
||||
|
||||
|
||||
dataIn += src.cols;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sumIntensity += DBL_EPSILON; // prevent div0 problems...
|
||||
|
||||
|
||||
centroid.x /= sumIntensity;
|
||||
centroid.y /= sumIntensity;
|
||||
|
||||
|
||||
return centroid;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _window)
|
||||
|
||||
@@ -73,13 +73,13 @@ template<typename T, typename ST> struct RowSum : public BaseRowFilter
|
||||
ksize = _ksize;
|
||||
anchor = _anchor;
|
||||
}
|
||||
|
||||
|
||||
void operator()(const uchar* src, uchar* dst, int width, int cn)
|
||||
{
|
||||
const T* S = (const T*)src;
|
||||
ST* D = (ST*)dst;
|
||||
int i = 0, k, ksz_cn = ksize*cn;
|
||||
|
||||
|
||||
width = (width - 1)*cn;
|
||||
for( k = 0; k < cn; k++, S++, D++ )
|
||||
{
|
||||
@@ -108,7 +108,7 @@ template<typename ST, typename T> struct ColumnSum : public BaseColumnFilter
|
||||
}
|
||||
|
||||
void reset() { sumCount = 0; }
|
||||
|
||||
|
||||
void operator()(const uchar** src, uchar* dst, int dststep, int count, int width)
|
||||
{
|
||||
int i;
|
||||
@@ -198,7 +198,7 @@ template<typename ST, typename T> struct ColumnSum : public BaseColumnFilter
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
cv::Ptr<cv::BaseRowFilter> cv::getRowSumFilter(int srcType, int sumType, int ksize, int anchor)
|
||||
{
|
||||
int sdepth = CV_MAT_DEPTH(srcType), ddepth = CV_MAT_DEPTH(sumType);
|
||||
@@ -325,7 +325,7 @@ void cv::blur( InputArray src, OutputArray dst,
|
||||
Size ksize, Point anchor, int borderType )
|
||||
{
|
||||
boxFilter( src, dst, -1, ksize, anchor, true, borderType );
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
Gaussian Blur
|
||||
@@ -422,7 +422,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize,
|
||||
Mat src = _src.getMat();
|
||||
_dst.create( src.size(), src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
if( borderType != BORDER_CONSTANT )
|
||||
{
|
||||
if( src.rows == 1 )
|
||||
@@ -454,7 +454,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize,
|
||||
namespace cv
|
||||
{
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4244 )
|
||||
#endif
|
||||
|
||||
@@ -479,7 +479,7 @@ typedef struct
|
||||
|
||||
#if CV_SSE2
|
||||
#define MEDIAN_HAVE_SIMD 1
|
||||
|
||||
|
||||
static inline void histogram_add_simd( const HT x[16], HT y[16] )
|
||||
{
|
||||
const __m128i* rx = (const __m128i*)x;
|
||||
@@ -499,12 +499,12 @@ static inline void histogram_sub_simd( const HT x[16], HT y[16] )
|
||||
_mm_store_si128(ry+0, r0);
|
||||
_mm_store_si128(ry+1, r1);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
#define MEDIAN_HAVE_SIMD 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static inline void histogram_add( const HT x[16], HT y[16] )
|
||||
{
|
||||
int i;
|
||||
@@ -667,14 +667,14 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize )
|
||||
{
|
||||
for( j = 0; j < 2*r; ++j )
|
||||
histogram_add( &h_coarse[16*(n*c+j)], H[c].coarse );
|
||||
|
||||
|
||||
for( j = r; j < n-r; j++ )
|
||||
{
|
||||
int t = 2*r*r + 2*r, b, sum = 0;
|
||||
HT* segment;
|
||||
|
||||
|
||||
histogram_add( &h_coarse[16*(n*c + std::min(j+r,n-1))], H[c].coarse );
|
||||
|
||||
|
||||
// Find median at coarse level
|
||||
for ( k = 0; k < 16 ; ++k )
|
||||
{
|
||||
@@ -686,14 +686,14 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize )
|
||||
}
|
||||
}
|
||||
assert( k < 16 );
|
||||
|
||||
|
||||
/* Update corresponding histogram segment */
|
||||
if ( luc[c][k] <= j-r )
|
||||
{
|
||||
memset( &H[c].fine[k], 0, 16 * sizeof(HT) );
|
||||
for ( luc[c][k] = j-r; luc[c][k] < MIN(j+r+1,n); ++luc[c][k] )
|
||||
histogram_add( &h_fine[16*(n*(16*c+k)+luc[c][k])], H[c].fine[k] );
|
||||
|
||||
|
||||
if ( luc[c][k] < j+r+1 )
|
||||
{
|
||||
histogram_muladd( j+r+1 - n, &h_fine[16*(n*(16*c+k)+(n-1))], &H[c].fine[k][0] );
|
||||
@@ -708,9 +708,9 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize )
|
||||
histogram_add( &h_fine[16*(n*(16*c+k)+MIN(luc[c][k],n-1))], H[c].fine[k] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
histogram_sub( &h_coarse[16*(n*c+MAX(j-r,0))], H[c].coarse );
|
||||
|
||||
|
||||
/* Find median in segment */
|
||||
segment = H[c].fine[k];
|
||||
for ( b = 0; b < 16 ; b++ )
|
||||
@@ -734,7 +734,7 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize )
|
||||
}
|
||||
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( default: 4244 )
|
||||
#endif
|
||||
|
||||
@@ -910,7 +910,7 @@ struct MinMax16u
|
||||
b = std::max(b, t);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct MinMax16s
|
||||
{
|
||||
typedef short value_type;
|
||||
@@ -974,7 +974,7 @@ struct MinMaxVec16u
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct MinMaxVec16s
|
||||
{
|
||||
typedef short value_type;
|
||||
@@ -988,9 +988,9 @@ struct MinMaxVec16s
|
||||
a = _mm_min_epi16(a, b);
|
||||
b = _mm_max_epi16(b, t);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct MinMaxVec32f
|
||||
{
|
||||
typedef float value_type;
|
||||
@@ -1033,7 +1033,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
Op op;
|
||||
VecOp vop;
|
||||
volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE2);
|
||||
|
||||
|
||||
if( m == 3 )
|
||||
{
|
||||
if( size.width == 1 || size.height == 1 )
|
||||
@@ -1055,7 +1055,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
size.width *= cn;
|
||||
for( i = 0; i < size.height; i++, dst += dstep )
|
||||
{
|
||||
@@ -1155,7 +1155,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
p[k*5+2] = rowk[j]; p[k*5+3] = rowk[j3];
|
||||
p[k*5+4] = rowk[j4];
|
||||
}
|
||||
|
||||
|
||||
op(p[1], p[2]); op(p[0], p[1]); op(p[1], p[2]); op(p[4], p[5]); op(p[3], p[4]);
|
||||
op(p[4], p[5]); op(p[0], p[3]); op(p[2], p[5]); op(p[2], p[3]); op(p[1], p[4]);
|
||||
op(p[1], p[2]); op(p[3], p[4]); op(p[7], p[8]); op(p[6], p[7]); op(p[7], p[8]);
|
||||
@@ -1195,7 +1195,7 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
p[k*5+2] = vop.load(rowk+j); p[k*5+3] = vop.load(rowk+j+cn);
|
||||
p[k*5+4] = vop.load(rowk+j+cn*2);
|
||||
}
|
||||
|
||||
|
||||
vop(p[1], p[2]); vop(p[0], p[1]); vop(p[1], p[2]); vop(p[4], p[5]); vop(p[3], p[4]);
|
||||
vop(p[4], p[5]); vop(p[0], p[3]); vop(p[2], p[5]); vop(p[2], p[3]); vop(p[1], p[4]);
|
||||
vop(p[1], p[2]); vop(p[3], p[4]); vop(p[7], p[8]); vop(p[6], p[7]); vop(p[7], p[8]);
|
||||
@@ -1229,13 +1229,13 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize )
|
||||
{
|
||||
Mat src0 = _src0.getMat();
|
||||
_dst.create( src0.size(), src0.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
if( ksize <= 1 )
|
||||
{
|
||||
src0.copyTo(dst);
|
||||
@@ -1248,13 +1248,13 @@ void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize )
|
||||
if (tegra::medianBlur(src0, dst, ksize))
|
||||
return;
|
||||
#endif
|
||||
|
||||
|
||||
bool useSortNet = ksize == 3 || (ksize == 5
|
||||
#if !CV_SSE2
|
||||
&& src0.depth() > CV_8U
|
||||
#endif
|
||||
);
|
||||
|
||||
|
||||
Mat src;
|
||||
if( useSortNet )
|
||||
{
|
||||
@@ -1315,7 +1315,7 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d,
|
||||
sigma_color = 1;
|
||||
if( sigma_space <= 0 )
|
||||
sigma_space = 1;
|
||||
|
||||
|
||||
double gauss_color_coeff = -0.5/(sigma_color*sigma_color);
|
||||
double gauss_space_coeff = -0.5/(sigma_space*sigma_space);
|
||||
|
||||
@@ -1422,7 +1422,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
sigma_color = 1;
|
||||
if( sigma_space <= 0 )
|
||||
sigma_space = 1;
|
||||
|
||||
|
||||
double gauss_color_coeff = -0.5/(sigma_color*sigma_color);
|
||||
double gauss_space_coeff = -0.5/(sigma_space*sigma_space);
|
||||
|
||||
@@ -1433,9 +1433,9 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
radius = MAX(radius, 1);
|
||||
d = radius*2 + 1;
|
||||
// compute the min/max range for the input image (even if multichannel)
|
||||
|
||||
|
||||
minMaxLoc( src.reshape(1), &minValSrc, &maxValSrc );
|
||||
|
||||
|
||||
// temporary copy of the image with borders for easy processing
|
||||
Mat temp;
|
||||
copyMakeBorder( src, temp, radius, radius, radius, radius, borderType );
|
||||
@@ -1454,7 +1454,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
float* expLUT = &_expLUT[0];
|
||||
|
||||
scale_index = kExpNumBins/len;
|
||||
|
||||
|
||||
// initialize the exp LUT
|
||||
for( i = 0; i < kExpNumBins+2; i++ )
|
||||
{
|
||||
@@ -1467,7 +1467,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
else
|
||||
expLUT[i] = 0.f;
|
||||
}
|
||||
|
||||
|
||||
// initialize space-related bilateral filter coefficients
|
||||
for( i = -radius, maxk = 0; i <= radius; i++ )
|
||||
for( j = -radius; j <= radius; j++ )
|
||||
@@ -1481,7 +1481,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
|
||||
for( i = 0; i < size.height; i++ )
|
||||
{
|
||||
const float* sptr = (const float*)(temp.data + (i+radius)*temp.step) + radius*cn;
|
||||
const float* sptr = (const float*)(temp.data + (i+radius)*temp.step) + radius*cn;
|
||||
float* dptr = (float*)(dst.data + i*dst.step);
|
||||
|
||||
if( cn == 1 )
|
||||
@@ -1493,11 +1493,11 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
for( k = 0; k < maxk; k++ )
|
||||
{
|
||||
float val = sptr[j + space_ofs[k]];
|
||||
float alpha = (float)(std::abs(val - val0)*scale_index);
|
||||
float alpha = (float)(std::abs(val - val0)*scale_index);
|
||||
int idx = cvFloor(alpha);
|
||||
alpha -= idx;
|
||||
float w = space_weight[k]*(expLUT[idx] + alpha*(expLUT[idx+1] - expLUT[idx]));
|
||||
sum += val*w;
|
||||
sum += val*w;
|
||||
wsum += w;
|
||||
}
|
||||
dptr[j] = (float)(sum/wsum);
|
||||
@@ -1514,7 +1514,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
{
|
||||
const float* sptr_k = sptr + j + space_ofs[k];
|
||||
float b = sptr_k[0], g = sptr_k[1], r = sptr_k[2];
|
||||
float alpha = (float)((std::abs(b - b0) +
|
||||
float alpha = (float)((std::abs(b - b0) +
|
||||
std::abs(g - g0) + std::abs(r - r0))*scale_index);
|
||||
int idx = cvFloor(alpha);
|
||||
alpha -= idx;
|
||||
@@ -1541,7 +1541,7 @@ void cv::bilateralFilter( InputArray _src, OutputArray _dst, int d,
|
||||
Mat src = _src.getMat();
|
||||
_dst.create( src.size(), src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
if( src.depth() == CV_8U )
|
||||
bilateralFilter_8u( src, dst, d, sigmaColor, sigmaSpace, borderType );
|
||||
else if( src.depth() == CV_32F )
|
||||
|
||||
@@ -134,7 +134,7 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep,
|
||||
|
||||
if( size.width == cn )
|
||||
buf[cn] = 0;
|
||||
|
||||
|
||||
if( sqsum )
|
||||
{
|
||||
sqsum[-cn] = 0;
|
||||
@@ -148,7 +148,7 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep,
|
||||
sum += sumstep - cn;
|
||||
tilted += tiltedstep - cn;
|
||||
buf += -cn;
|
||||
|
||||
|
||||
if( sqsum )
|
||||
sqsum += sqsumstep - cn;
|
||||
|
||||
@@ -197,7 +197,7 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep,
|
||||
tilted[x] = t0 + t1 + tilted[x - tiltedstep - cn];
|
||||
buf[x] = t0;
|
||||
}
|
||||
|
||||
|
||||
if( sqsum )
|
||||
sqsum++;
|
||||
}
|
||||
@@ -205,10 +205,10 @@ void integral_( const T* src, size_t _srcstep, ST* sum, size_t _sumstep,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define DEF_INTEGRAL_FUNC(suffix, T, ST, QT) \
|
||||
void integral_##suffix( T* src, size_t srcstep, ST* sum, size_t sumstep, QT* sqsum, size_t sqsumstep, \
|
||||
ST* tilted, size_t tiltedstep, Size size, int cn ) \
|
||||
static void integral_##suffix( T* src, size_t srcstep, ST* sum, size_t sumstep, QT* sqsum, size_t sqsumstep, \
|
||||
ST* tilted, size_t tiltedstep, Size size, int cn ) \
|
||||
{ integral_(src, srcstep, sum, sumstep, sqsum, sqsumstep, tilted, tiltedstep, size, cn); }
|
||||
|
||||
DEF_INTEGRAL_FUNC(8u32s, uchar, int, double)
|
||||
@@ -217,7 +217,7 @@ DEF_INTEGRAL_FUNC(8u64f, uchar, double, double)
|
||||
DEF_INTEGRAL_FUNC(32f, float, float, double)
|
||||
DEF_INTEGRAL_FUNC(32f64f, float, double, double)
|
||||
DEF_INTEGRAL_FUNC(64f, double, double, double)
|
||||
|
||||
|
||||
typedef void (*IntegralFunc)(const uchar* src, size_t srcstep, uchar* sum, size_t sumstep,
|
||||
uchar* sqsum, size_t sqsumstep, uchar* tilted, size_t tstep,
|
||||
Size size, int cn );
|
||||
@@ -236,19 +236,19 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output
|
||||
sdepth = CV_MAT_DEPTH(sdepth);
|
||||
_sum.create( isize, CV_MAKETYPE(sdepth, cn) );
|
||||
sum = _sum.getMat();
|
||||
|
||||
|
||||
if( _tilted.needed() )
|
||||
{
|
||||
_tilted.create( isize, CV_MAKETYPE(sdepth, cn) );
|
||||
tilted = _tilted.getMat();
|
||||
}
|
||||
|
||||
|
||||
if( _sqsum.needed() )
|
||||
{
|
||||
_sqsum.create( isize, CV_MAKETYPE(CV_64F, cn) );
|
||||
sqsum = _sqsum.getMat();
|
||||
}
|
||||
|
||||
|
||||
IntegralFunc func = 0;
|
||||
|
||||
if( depth == CV_8U && sdepth == CV_32S )
|
||||
@@ -269,7 +269,7 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output
|
||||
func( src.data, src.step, sum.data, sum.step, sqsum.data, sqsum.step,
|
||||
tilted.data, tilted.step, src.size(), cn );
|
||||
}
|
||||
|
||||
|
||||
void cv::integral( InputArray src, OutputArray sum, int sdepth )
|
||||
{
|
||||
integral( src, sum, noArray(), noArray(), sdepth );
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if _MSC_VER >= 1200 || defined __BORLANDC__
|
||||
#if (defined _MSC_VER && _MSC_VER >= 1200) || defined __BORLANDC__
|
||||
#define cv_stricmp stricmp
|
||||
#define cv_strnicmp strnicmp
|
||||
#if defined WINCE
|
||||
|
||||
@@ -3478,7 +3478,7 @@ typedef struct CvBGCodeBookModel
|
||||
CvBGCodeBookElem* freeList;
|
||||
} CvBGCodeBookModel;
|
||||
|
||||
CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel();
|
||||
CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel( void );
|
||||
CVAPI(void) cvReleaseBGCodeBookModel( CvBGCodeBookModel** model );
|
||||
|
||||
CVAPI(void) cvBGCodeBookUpdate( CvBGCodeBookModel* model, const CvArr* image,
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning(disable:4786) // Disable MSVC warnings in the standard library.
|
||||
#pragma warning(disable:4100)
|
||||
#pragma warning(disable:4512)
|
||||
@@ -49,7 +49,7 @@
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning(default:4100)
|
||||
#pragma warning(default:4512)
|
||||
#endif
|
||||
@@ -148,7 +148,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras,
|
||||
cvReleaseImage(&gray_img);
|
||||
CV_CALL(gray_img = cvCreateImage(image_size, IPL_DEPTH_8U, 1));
|
||||
}
|
||||
|
||||
|
||||
CV_CALL(cvCvtColor(samples[c], gray_img, CV_BGR2GRAY));
|
||||
|
||||
img = gray_img;
|
||||
@@ -172,7 +172,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras,
|
||||
etalon_size, points, &count) != 0;
|
||||
if (count == 0)
|
||||
continue;
|
||||
|
||||
|
||||
// If found is true, it means all the points were found (count = num_points).
|
||||
// If found is false but count is non-zero, it means that not all points were found.
|
||||
|
||||
@@ -258,7 +258,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras,
|
||||
{ 0.f, 1.f, 0.f, 0.f },
|
||||
{ 0.f, 0.f, 1.f, 0.f },
|
||||
{ transVect[0], transVect[1], transVect[2], 1.f } };
|
||||
|
||||
|
||||
float rmat[4][4] = { { rotMatr[0], rotMatr[1], rotMatr[2], 0.f },
|
||||
{ rotMatr[3], rotMatr[4], rotMatr[5], 0.f },
|
||||
{ rotMatr[6], rotMatr[7], rotMatr[8], 0.f },
|
||||
@@ -267,7 +267,7 @@ CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras,
|
||||
|
||||
MultMatrix(camera_info[c].mat, tmat, rmat);
|
||||
|
||||
// change the transformation of the cameras to put them in the world coordinate
|
||||
// change the transformation of the cameras to put them in the world coordinate
|
||||
// system we want to work with.
|
||||
|
||||
// Start with an identity matrix; then fill in the values to accomplish
|
||||
|
||||
@@ -53,13 +53,13 @@
|
||||
#include "assert.h"
|
||||
#include "math.h"
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#if defined _MSC_VER && _MSC_VER >= 1400
|
||||
#pragma warning(disable: 4512) // suppress "assignment operator could not be generated"
|
||||
#endif
|
||||
|
||||
// J.S. Beis and D.G. Lowe. Shape indexing using approximate nearest-neighbor search
|
||||
// in highdimensional spaces. In Proc. IEEE Conf. Comp. Vision Patt. Recog.,
|
||||
// pages 1000--1006, 1997. http://citeseer.ist.psu.edu/beis97shape.html
|
||||
// J.S. Beis and D.G. Lowe. Shape indexing using approximate nearest-neighbor search
|
||||
// in highdimensional spaces. In Proc. IEEE Conf. Comp. Vision Patt. Recog.,
|
||||
// pages 1000--1006, 1997. http://citeseer.ist.psu.edu/beis97shape.html
|
||||
#undef __deref
|
||||
#undef __valuetype
|
||||
|
||||
@@ -72,23 +72,23 @@ public:
|
||||
|
||||
private:
|
||||
struct node {
|
||||
int dim; // split dimension; >=0 for nodes, -1 for leaves
|
||||
__valuetype value; // if leaf, value of leaf
|
||||
int left, right; // node indices of left and right branches
|
||||
scalar_type boundary; // left if deref(value,dim)<=boundary, otherwise right
|
||||
int dim; // split dimension; >=0 for nodes, -1 for leaves
|
||||
__valuetype value; // if leaf, value of leaf
|
||||
int left, right; // node indices of left and right branches
|
||||
scalar_type boundary; // left if deref(value,dim)<=boundary, otherwise right
|
||||
};
|
||||
typedef std::vector < node > node_array;
|
||||
|
||||
__deref deref; // requires operator() (__valuetype lhs,int dim)
|
||||
__deref deref; // requires operator() (__valuetype lhs,int dim)
|
||||
|
||||
node_array nodes; // node storage
|
||||
int point_dim; // dimension of points (the k in kd-tree)
|
||||
int root_node; // index of root node, -1 if empty tree
|
||||
node_array nodes; // node storage
|
||||
int point_dim; // dimension of points (the k in kd-tree)
|
||||
int root_node; // index of root node, -1 if empty tree
|
||||
|
||||
// for given set of point indices, compute dimension of highest variance
|
||||
template < class __instype, class __valuector >
|
||||
int dimension_of_highest_variance(__instype * first, __instype * last,
|
||||
__valuector ctor) {
|
||||
__valuector ctor) {
|
||||
assert(last - first > 0);
|
||||
|
||||
accum_type maxvar = -std::numeric_limits < accum_type >::max();
|
||||
@@ -96,32 +96,32 @@ private:
|
||||
for (int j = 0; j < point_dim; ++j) {
|
||||
accum_type mean = 0;
|
||||
for (__instype * k = first; k < last; ++k)
|
||||
mean += deref(ctor(*k), j);
|
||||
mean += deref(ctor(*k), j);
|
||||
mean /= last - first;
|
||||
accum_type var = 0;
|
||||
for (__instype * k = first; k < last; ++k) {
|
||||
accum_type diff = accum_type(deref(ctor(*k), j)) - mean;
|
||||
var += diff * diff;
|
||||
accum_type diff = accum_type(deref(ctor(*k), j)) - mean;
|
||||
var += diff * diff;
|
||||
}
|
||||
var /= last - first;
|
||||
|
||||
assert(maxj != -1 || var >= maxvar);
|
||||
|
||||
if (var >= maxvar) {
|
||||
maxvar = var;
|
||||
maxj = j;
|
||||
maxvar = var;
|
||||
maxj = j;
|
||||
}
|
||||
}
|
||||
|
||||
return maxj;
|
||||
}
|
||||
|
||||
// given point indices and dimension, find index of median; (almost) modifies [first,last)
|
||||
// given point indices and dimension, find index of median; (almost) modifies [first,last)
|
||||
// such that points_in[first,median]<=point[median], points_in(median,last)>point[median].
|
||||
// implemented as partial quicksort; expected linear perf.
|
||||
template < class __instype, class __valuector >
|
||||
__instype * median_partition(__instype * first, __instype * last,
|
||||
int dim, __valuector ctor) {
|
||||
int dim, __valuector ctor) {
|
||||
assert(last - first > 0);
|
||||
__instype *k = first + (last - first) / 2;
|
||||
median_partition(first, last, k, dim, ctor);
|
||||
@@ -143,14 +143,14 @@ private:
|
||||
};
|
||||
|
||||
template < class __instype, class __valuector >
|
||||
void median_partition(__instype * first, __instype * last,
|
||||
__instype * k, int dim, __valuector ctor) {
|
||||
void median_partition(__instype * first, __instype * last,
|
||||
__instype * k, int dim, __valuector ctor) {
|
||||
int pivot = (int)((last - first) / 2);
|
||||
|
||||
std::swap(first[pivot], last[-1]);
|
||||
__instype *middle = std::partition(first, last - 1,
|
||||
median_pr < __instype, __valuector >
|
||||
(last[-1], dim, deref, ctor));
|
||||
median_pr < __instype, __valuector >
|
||||
(last[-1], dim, deref, ctor));
|
||||
std::swap(*middle, last[-1]);
|
||||
|
||||
if (middle < k)
|
||||
@@ -170,36 +170,36 @@ private:
|
||||
__instype *median = median_partition(first, last, dim, ctor);
|
||||
|
||||
__instype *split = median;
|
||||
for (; split != last && deref(ctor(*split), dim) ==
|
||||
deref(ctor(*median), dim); ++split);
|
||||
for (; split != last && deref(ctor(*split), dim) ==
|
||||
deref(ctor(*median), dim); ++split);
|
||||
|
||||
if (split == last) { // leaf
|
||||
int nexti = -1;
|
||||
for (--split; split >= first; --split) {
|
||||
int i = (int)nodes.size();
|
||||
node & n = *nodes.insert(nodes.end(), node());
|
||||
n.dim = -1;
|
||||
n.value = ctor(*split);
|
||||
n.left = -1;
|
||||
n.right = nexti;
|
||||
nexti = i;
|
||||
}
|
||||
int nexti = -1;
|
||||
for (--split; split >= first; --split) {
|
||||
int i = (int)nodes.size();
|
||||
node & n = *nodes.insert(nodes.end(), node());
|
||||
n.dim = -1;
|
||||
n.value = ctor(*split);
|
||||
n.left = -1;
|
||||
n.right = nexti;
|
||||
nexti = i;
|
||||
}
|
||||
|
||||
return nexti;
|
||||
return nexti;
|
||||
} else { // node
|
||||
int i = (int)nodes.size();
|
||||
// note that recursive insert may invalidate this ref
|
||||
node & n = *nodes.insert(nodes.end(), node());
|
||||
int i = (int)nodes.size();
|
||||
// note that recursive insert may invalidate this ref
|
||||
node & n = *nodes.insert(nodes.end(), node());
|
||||
|
||||
n.dim = dim;
|
||||
n.boundary = deref(ctor(*median), dim);
|
||||
n.dim = dim;
|
||||
n.boundary = deref(ctor(*median), dim);
|
||||
|
||||
int left = insert(first, split, ctor);
|
||||
nodes[i].left = left;
|
||||
int right = insert(split, last, ctor);
|
||||
nodes[i].right = right;
|
||||
int left = insert(first, split, ctor);
|
||||
nodes[i].left = left;
|
||||
int right = insert(split, last, ctor);
|
||||
nodes[i].right = right;
|
||||
|
||||
return i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,21 +214,21 @@ private:
|
||||
|
||||
if (n.dim >= 0) { // node
|
||||
if (deref(p, n.dim) <= n.boundary) // left
|
||||
r = remove(&n.left, p);
|
||||
r = remove(&n.left, p);
|
||||
else // right
|
||||
r = remove(&n.right, p);
|
||||
r = remove(&n.right, p);
|
||||
|
||||
// if terminal, remove this node
|
||||
if (n.left == -1 && n.right == -1)
|
||||
*i = -1;
|
||||
*i = -1;
|
||||
|
||||
return r;
|
||||
} else { // leaf
|
||||
if (n.value == p) {
|
||||
*i = n.right;
|
||||
return true;
|
||||
*i = n.right;
|
||||
return true;
|
||||
} else
|
||||
return remove(&n.right, p);
|
||||
return remove(&n.right, p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,14 +245,14 @@ public:
|
||||
}
|
||||
// given points, initialize a balanced tree
|
||||
CvKDTree(__valuetype * first, __valuetype * last, int _point_dim,
|
||||
__deref _deref = __deref())
|
||||
__deref _deref = __deref())
|
||||
: deref(_deref) {
|
||||
set_data(first, last, _point_dim, identity_ctor());
|
||||
}
|
||||
// given points, initialize a balanced tree
|
||||
template < class __instype, class __valuector >
|
||||
CvKDTree(__instype * first, __instype * last, int _point_dim,
|
||||
__valuector ctor, __deref _deref = __deref())
|
||||
__valuector ctor, __deref _deref = __deref())
|
||||
: deref(_deref) {
|
||||
set_data(first, last, _point_dim, ctor);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public:
|
||||
}
|
||||
template < class __instype, class __valuector >
|
||||
void set_data(__instype * first, __instype * last, int _point_dim,
|
||||
__valuector ctor) {
|
||||
__valuector ctor) {
|
||||
point_dim = _point_dim;
|
||||
nodes.clear();
|
||||
nodes.reserve(last - first);
|
||||
@@ -292,9 +292,9 @@ public:
|
||||
std::cout << " ";
|
||||
const node & n = nodes[i];
|
||||
if (n.dim >= 0) {
|
||||
std::cout << "node " << i << ", left " << nodes[i].left << ", right " <<
|
||||
nodes[i].right << ", dim " << nodes[i].dim << ", boundary " <<
|
||||
nodes[i].boundary << std::endl;
|
||||
std::cout << "node " << i << ", left " << nodes[i].left << ", right " <<
|
||||
nodes[i].right << ", dim " << nodes[i].dim << ", boundary " <<
|
||||
nodes[i].boundary << std::endl;
|
||||
print(n.left, indent + 3);
|
||||
print(n.right, indent + 3);
|
||||
} else
|
||||
@@ -304,9 +304,9 @@ public:
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// bbf search
|
||||
public:
|
||||
struct bbf_nn { // info on found neighbors (approx k nearest)
|
||||
const __valuetype *p; // nearest neighbor
|
||||
accum_type dist; // distance from d to query point
|
||||
struct bbf_nn { // info on found neighbors (approx k nearest)
|
||||
const __valuetype *p; // nearest neighbor
|
||||
accum_type dist; // distance from d to query point
|
||||
bbf_nn(const __valuetype & _p, accum_type _dist)
|
||||
: p(&_p), dist(_dist) {
|
||||
}
|
||||
@@ -316,9 +316,9 @@ public:
|
||||
};
|
||||
typedef std::vector < bbf_nn > bbf_nn_pqueue;
|
||||
private:
|
||||
struct bbf_node { // info on branches not taken
|
||||
int node; // corresponding node
|
||||
accum_type dist; // minimum distance from bounds to query point
|
||||
struct bbf_node { // info on branches not taken
|
||||
int node; // corresponding node
|
||||
accum_type dist; // minimum distance from bounds to query point
|
||||
bbf_node(int _node, accum_type _dist)
|
||||
: node(_node), dist(_dist) {
|
||||
}
|
||||
@@ -346,10 +346,10 @@ private:
|
||||
int bbf_branch(int i, const __desctype * d, bbf_pqueue & pq) const {
|
||||
const node & n = nodes[i];
|
||||
// push bbf_node with bounds of alternate branch, then branch
|
||||
if (d[n.dim] <= n.boundary) { // left
|
||||
if (d[n.dim] <= n.boundary) { // left
|
||||
pq_alternate(n.right, pq, n.boundary - d[n.dim]);
|
||||
return n.left;
|
||||
} else { // right
|
||||
} else { // right
|
||||
pq_alternate(n.left, pq, d[n.dim] - n.boundary);
|
||||
return n.right;
|
||||
}
|
||||
@@ -366,11 +366,11 @@ private:
|
||||
}
|
||||
|
||||
// called per candidate nearest neighbor; constructs new bbf_nn for
|
||||
// candidate and adds it to priority queue of all candidates; if
|
||||
// candidate and adds it to priority queue of all candidates; if
|
||||
// queue len exceeds k, drops the point furthest from query point d.
|
||||
template < class __desctype >
|
||||
void bbf_new_nn(bbf_nn_pqueue & nn_pq, int k,
|
||||
const __desctype * d, const __valuetype & p) const {
|
||||
void bbf_new_nn(bbf_nn_pqueue & nn_pq, int k,
|
||||
const __desctype * d, const __valuetype & p) const {
|
||||
bbf_nn nn(p, distance(d, p));
|
||||
if ((int) nn_pq.size() < k) {
|
||||
nn_pq.push_back(nn);
|
||||
@@ -384,14 +384,14 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
// finds (with high probability) the k nearest neighbors of d,
|
||||
// finds (with high probability) the k nearest neighbors of d,
|
||||
// searching at most emax leaves/bins.
|
||||
// ret_nn_pq is an array containing the (at most) k nearest neighbors
|
||||
// ret_nn_pq is an array containing the (at most) k nearest neighbors
|
||||
// (see bbf_nn structure def above).
|
||||
template < class __desctype >
|
||||
int find_nn_bbf(const __desctype * d,
|
||||
int k, int emax,
|
||||
bbf_nn_pqueue & ret_nn_pq) const {
|
||||
int find_nn_bbf(const __desctype * d,
|
||||
int k, int emax,
|
||||
bbf_nn_pqueue & ret_nn_pq) const {
|
||||
assert(k > 0);
|
||||
ret_nn_pq.clear();
|
||||
|
||||
@@ -411,17 +411,17 @@ public:
|
||||
|
||||
int i;
|
||||
for (i = bbf.node;
|
||||
i != -1 && nodes[i].dim >= 0;
|
||||
i = bbf_branch(i, d, tmp_pq));
|
||||
i != -1 && nodes[i].dim >= 0;
|
||||
i = bbf_branch(i, d, tmp_pq));
|
||||
|
||||
if (i != -1) {
|
||||
|
||||
// add points in leaf/bin to ret_nn_pq
|
||||
do {
|
||||
bbf_new_nn(ret_nn_pq, k, d, nodes[i].value);
|
||||
} while (-1 != (i = nodes[i].right));
|
||||
// add points in leaf/bin to ret_nn_pq
|
||||
do {
|
||||
bbf_new_nn(ret_nn_pq, k, d, nodes[i].value);
|
||||
} while (-1 != (i = nodes[i].right));
|
||||
|
||||
--emax;
|
||||
--emax;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,27 +433,27 @@ public:
|
||||
// orthogonal range search
|
||||
private:
|
||||
void find_ortho_range(int i, scalar_type * bounds_min,
|
||||
scalar_type * bounds_max,
|
||||
std::vector < __valuetype > &inbounds) const {
|
||||
scalar_type * bounds_max,
|
||||
std::vector < __valuetype > &inbounds) const {
|
||||
if (i == -1)
|
||||
return;
|
||||
const node & n = nodes[i];
|
||||
if (n.dim >= 0) { // node
|
||||
if (bounds_min[n.dim] <= n.boundary)
|
||||
find_ortho_range(n.left, bounds_min, bounds_max, inbounds);
|
||||
find_ortho_range(n.left, bounds_min, bounds_max, inbounds);
|
||||
if (bounds_max[n.dim] > n.boundary)
|
||||
find_ortho_range(n.right, bounds_min, bounds_max, inbounds);
|
||||
find_ortho_range(n.right, bounds_min, bounds_max, inbounds);
|
||||
} else { // leaf
|
||||
do {
|
||||
inbounds.push_back(nodes[i].value);
|
||||
inbounds.push_back(nodes[i].value);
|
||||
} while (-1 != (i = nodes[i].right));
|
||||
}
|
||||
}
|
||||
public:
|
||||
// return all points that lie within the given bounds; inbounds is cleared
|
||||
int find_ortho_range(scalar_type * bounds_min,
|
||||
scalar_type * bounds_max,
|
||||
std::vector < __valuetype > &inbounds) const {
|
||||
scalar_type * bounds_max,
|
||||
std::vector < __valuetype > &inbounds) const {
|
||||
inbounds.clear();
|
||||
find_ortho_range(root_node, bounds_min, bounds_max, inbounds);
|
||||
return (int)inbounds.size();
|
||||
|
||||
@@ -237,9 +237,9 @@ public:
|
||||
virtual float* GetFVVar(){return m_FVVar;}; /* returned pointer to array of maximal values of FV, if return 0 then FVrange is not exist */
|
||||
};/* CvBlobTrackFVGenN */
|
||||
|
||||
CvBlobTrackFVGen* cvCreateFVGenP(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(2);}
|
||||
CvBlobTrackFVGen* cvCreateFVGenPV(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(4);}
|
||||
CvBlobTrackFVGen* cvCreateFVGenPVS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(5);}
|
||||
inline CvBlobTrackFVGen* cvCreateFVGenP(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(2);}
|
||||
inline CvBlobTrackFVGen* cvCreateFVGenPV(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(4);}
|
||||
inline CvBlobTrackFVGen* cvCreateFVGenPVS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenN(5);}
|
||||
#undef MAX_FV_SIZE
|
||||
|
||||
#define MAX_FV_SIZE 4
|
||||
@@ -408,7 +408,7 @@ public:
|
||||
virtual float* GetFVVar(){return m_FVVar;}; /* returned pointer to array of maximal values of FV, if return 0 then FVrange is not exist */
|
||||
};/* CvBlobTrackFVGenSS */
|
||||
|
||||
CvBlobTrackFVGen* cvCreateFVGenSS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenSS;}
|
||||
inline CvBlobTrackFVGen* cvCreateFVGenSS(){return (CvBlobTrackFVGen*)new CvBlobTrackFVGenSS;}
|
||||
|
||||
/*======================= TRAJECTORY ANALYZER MODULES =====================*/
|
||||
/* Trajectory Analyser module */
|
||||
@@ -1510,7 +1510,7 @@ public:
|
||||
|
||||
}; /* CvBlobTrackAnalysisSVM. */
|
||||
|
||||
|
||||
#if 0
|
||||
CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP()
|
||||
{return (CvBlobTrackAnalysis*) new CvBlobTrackAnalysisSVM(cvCreateFVGenP);}
|
||||
|
||||
@@ -1522,3 +1522,4 @@ CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS()
|
||||
|
||||
CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS()
|
||||
{return (CvBlobTrackAnalysis*) new CvBlobTrackAnalysisSVM(cvCreateFVGenSS);}
|
||||
#endif
|
||||
|
||||
@@ -162,12 +162,15 @@ public:
|
||||
}
|
||||
}; /* class CvBlobTrackerOneKalman */
|
||||
|
||||
#if 0
|
||||
static CvBlobTrackerOne* cvCreateModuleBlobTrackerOneKalman()
|
||||
{
|
||||
return (CvBlobTrackerOne*) new CvBlobTrackerOneKalman;
|
||||
}
|
||||
|
||||
|
||||
CvBlobTracker* cvCreateBlobTrackerKalman()
|
||||
{
|
||||
return cvCreateBlobTrackerList(cvCreateModuleBlobTrackerOneKalman);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -716,7 +716,7 @@ void CvBlobTrackerOneMSFG::CollectHist(IplImage* pImg, IplImage* pMask, CvBlob*
|
||||
}; /* CollectHist */
|
||||
#endif
|
||||
|
||||
CvBlobTrackerOne* cvCreateBlobTrackerOneMSFG()
|
||||
static CvBlobTrackerOne* cvCreateBlobTrackerOneMSFG()
|
||||
{
|
||||
return (CvBlobTrackerOne*) new CvBlobTrackerOneMSFG;
|
||||
}
|
||||
@@ -739,7 +739,7 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
CvBlobTrackerOne* cvCreateBlobTrackerOneMS()
|
||||
static CvBlobTrackerOne* cvCreateBlobTrackerOneMS()
|
||||
{
|
||||
return (CvBlobTrackerOne*) new CvBlobTrackerOneMS;
|
||||
}
|
||||
@@ -1169,6 +1169,7 @@ public:
|
||||
|
||||
}; /* CvBlobTrackerOneMSPF */
|
||||
|
||||
CvBlobTrackerOne* cvCreateBlobTrackerOneMSPF();
|
||||
CvBlobTrackerOne* cvCreateBlobTrackerOneMSPF()
|
||||
{
|
||||
return (CvBlobTrackerOne*) new CvBlobTrackerOneMSPF;
|
||||
|
||||
@@ -47,7 +47,7 @@ typedef float DefHistType;
|
||||
#define DefHistTypeMat CV_32F
|
||||
#define HIST_INDEX(_pData) (((_pData)[0]>>m_ByteShift) + (((_pData)[1]>>(m_ByteShift))<<m_BinBit)+((pImgData[2]>>m_ByteShift)<<(m_BinBit*2)))
|
||||
|
||||
void calcKernelEpanechnikov(CvMat* pK)
|
||||
static void calcKernelEpanechnikov(CvMat* pK)
|
||||
{ /* Allocate kernel for histogramm creation: */
|
||||
int x,y;
|
||||
int w = pK->width;
|
||||
@@ -445,7 +445,7 @@ public:
|
||||
virtual void Release(){delete this;};
|
||||
}; /*CvBlobTrackerOneMSFGS*/
|
||||
|
||||
CvBlobTrackerOne* cvCreateBlobTrackerOneMSFGS()
|
||||
static CvBlobTrackerOne* cvCreateBlobTrackerOneMSFGS()
|
||||
{
|
||||
return (CvBlobTrackerOne*) new CvBlobTrackerOneMSFGS;
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ void CvBlobTrackPostProcKalman::Release()
|
||||
delete this;
|
||||
}
|
||||
|
||||
CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcKalmanOne()
|
||||
static CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcKalmanOne()
|
||||
{
|
||||
return (CvBlobTrackPostProcOne*) new CvBlobTrackPostProcKalman;
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ public:
|
||||
}
|
||||
}; /* class CvBlobTrackPostProcTimeAver */
|
||||
|
||||
CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverRectOne()
|
||||
static CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverRectOne()
|
||||
{
|
||||
return (CvBlobTrackPostProcOne*) new CvBlobTrackPostProcTimeAver(0);
|
||||
}
|
||||
|
||||
CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverExpOne()
|
||||
static CvBlobTrackPostProcOne* cvCreateModuleBlobTrackPostProcTimeAverExpOne()
|
||||
{
|
||||
return (CvBlobTrackPostProcOne*) new CvBlobTrackPostProcTimeAver(1);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
#undef quad
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4701 )
|
||||
#endif
|
||||
|
||||
@@ -99,18 +99,18 @@ bool CvCalibFilter::SetEtalon( CvCalibEtalonType type, double* params,
|
||||
|
||||
Stop();
|
||||
|
||||
if (latestPoints != NULL)
|
||||
{
|
||||
for( i = 0; i < MAX_CAMERAS; i++ )
|
||||
cvFree( latestPoints + i );
|
||||
}
|
||||
if (latestPoints != NULL)
|
||||
{
|
||||
for( i = 0; i < MAX_CAMERAS; i++ )
|
||||
cvFree( latestPoints + i );
|
||||
}
|
||||
|
||||
if( type == CV_CALIB_ETALON_USER || type != etalonType )
|
||||
{
|
||||
if (etalonParams != NULL)
|
||||
{
|
||||
cvFree( &etalonParams );
|
||||
}
|
||||
if (etalonParams != NULL)
|
||||
{
|
||||
cvFree( &etalonParams );
|
||||
}
|
||||
}
|
||||
|
||||
etalonType = type;
|
||||
@@ -154,10 +154,10 @@ bool CvCalibFilter::SetEtalon( CvCalibEtalonType type, double* params,
|
||||
|
||||
if( etalonPointCount != pointCount )
|
||||
{
|
||||
if (etalonPoints != NULL)
|
||||
{
|
||||
cvFree( &etalonPoints );
|
||||
}
|
||||
if (etalonPoints != NULL)
|
||||
{
|
||||
cvFree( &etalonPoints );
|
||||
}
|
||||
etalonPointCount = pointCount;
|
||||
etalonPoints = (CvPoint2D32f*)cvAlloc( arrSize );
|
||||
}
|
||||
@@ -184,15 +184,15 @@ bool CvCalibFilter::SetEtalon( CvCalibEtalonType type, double* params,
|
||||
break;
|
||||
|
||||
case CV_CALIB_ETALON_USER:
|
||||
if (params != NULL)
|
||||
{
|
||||
memcpy( etalonParams, params, arrSize );
|
||||
}
|
||||
if (points != NULL)
|
||||
{
|
||||
memcpy( etalonPoints, points, arrSize );
|
||||
}
|
||||
break;
|
||||
if (params != NULL)
|
||||
{
|
||||
memcpy( etalonParams, params, arrSize );
|
||||
}
|
||||
if (points != NULL)
|
||||
{
|
||||
memcpy( etalonPoints, points, arrSize );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
@@ -226,7 +226,7 @@ CvCalibFilter::GetEtalon( int* paramCount, const double** params,
|
||||
void CvCalibFilter::SetCameraCount( int count )
|
||||
{
|
||||
Stop();
|
||||
|
||||
|
||||
if( count != cameraCount )
|
||||
{
|
||||
for( int i = 0; i < cameraCount; i++ )
|
||||
@@ -245,7 +245,7 @@ void CvCalibFilter::SetCameraCount( int count )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CvCalibFilter::SetFrames( int frames )
|
||||
{
|
||||
if( frames < 5 )
|
||||
@@ -253,7 +253,7 @@ bool CvCalibFilter::SetFrames( int frames )
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
framesTotal = frames;
|
||||
return true;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ void CvCalibFilter::Stop( bool calibrate )
|
||||
|
||||
cameraParams[i].imgSize[0] = (float)imgSize.width;
|
||||
cameraParams[i].imgSize[1] = (float)imgSize.height;
|
||||
|
||||
|
||||
// cameraParams[i].focalLength[0] = cameraParams[i].matrix[0];
|
||||
// cameraParams[i].focalLength[1] = cameraParams[i].matrix[4];
|
||||
|
||||
@@ -315,7 +315,7 @@ void CvCalibFilter::Stop( bool calibrate )
|
||||
memcpy( cameraParams[i].transVect, transVect, 3 * sizeof(transVect[0]));
|
||||
|
||||
mat.data.ptr = (uchar*)(cameraParams + i);
|
||||
|
||||
|
||||
/* check resultant camera parameters: if there are some INF's or NAN's,
|
||||
stop and reset results */
|
||||
if( !cvCheckArr( &mat, CV_CHECK_RANGE | CV_CHECK_QUIET, -10000, 10000 ))
|
||||
@@ -342,7 +342,7 @@ void CvCalibFilter::Stop( bool calibrate )
|
||||
{
|
||||
stereo.fundMatr[i] = stereo.fundMatr[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -499,16 +499,16 @@ bool CvCalibFilter::GetLatestPoints( int idx, CvPoint2D32f** pts,
|
||||
int* count, bool* found )
|
||||
{
|
||||
int n;
|
||||
|
||||
|
||||
if( (unsigned)idx >= (unsigned)cameraCount ||
|
||||
!pts || !count || !found )
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
n = latestCounts[idx];
|
||||
|
||||
|
||||
*found = n > 0;
|
||||
*count = abs(n);
|
||||
*pts = latestPoints[idx];
|
||||
@@ -616,7 +616,7 @@ const CvCamera* CvCalibFilter::GetCameraParams( int idx ) const
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return isCalibrated ? cameraParams + idx : 0;
|
||||
}
|
||||
|
||||
@@ -630,7 +630,7 @@ const CvStereoCamera* CvCalibFilter::GetStereoParams() const
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return &stereo;
|
||||
}
|
||||
|
||||
@@ -640,9 +640,9 @@ bool CvCalibFilter::SetCameraParams( CvCamera* params )
|
||||
{
|
||||
CvMat mat;
|
||||
int arrSize;
|
||||
|
||||
|
||||
Stop();
|
||||
|
||||
|
||||
if( !params )
|
||||
{
|
||||
assert(0);
|
||||
@@ -667,7 +667,7 @@ bool CvCalibFilter::SaveCameraParams( const char* filename )
|
||||
if( isCalibrated )
|
||||
{
|
||||
int i, j;
|
||||
|
||||
|
||||
FILE* f = fopen( filename, "w" );
|
||||
|
||||
if( !f ) return false;
|
||||
@@ -729,7 +729,7 @@ bool CvCalibFilter::LoadCameraParams( const char* filename )
|
||||
return false;
|
||||
|
||||
SetCameraCount( d );
|
||||
|
||||
|
||||
for( i = 0; i < cameraCount; i++ )
|
||||
{
|
||||
for( j = 0; j < (int)(sizeof(cameraParams[i])/sizeof(float)); j++ )
|
||||
@@ -763,16 +763,16 @@ bool CvCalibFilter::LoadCameraParams( const char* filename )
|
||||
CV_Assert(values_read == 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fclose(f);
|
||||
|
||||
stereo.warpSize = cvSize( cvRound(cameraParams[0].imgSize[0]), cvRound(cameraParams[0].imgSize[1]));
|
||||
|
||||
isCalibrated = true;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -924,4 +924,4 @@ bool CvCalibFilter::Undistort( CvMat** srcarr, CvMat** dstarr )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
//#include <limits.h>
|
||||
//#include "cv.h"
|
||||
//#include "highgui.h"
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
|
||||
/* Valery Mosyagin */
|
||||
@@ -53,7 +53,7 @@
|
||||
/* ===== Function for find corresponding between images ===== */
|
||||
|
||||
/* Create feature points on image and return number of them. Array points fills by found points */
|
||||
int icvCreateFeaturePoints(IplImage *image, CvMat *points, CvMat *status)
|
||||
static int icvCreateFeaturePoints(IplImage *image, CvMat *points, CvMat *status)
|
||||
{
|
||||
int foundFeaturePoints = 0;
|
||||
IplImage *grayImage = 0;
|
||||
@@ -175,9 +175,9 @@ int icvCreateFeaturePoints(IplImage *image, CvMat *points, CvMat *status)
|
||||
|
||||
/* For given points1 (with pntStatus) on image1 finds corresponding points2 on image2 and set pntStatus2 for them */
|
||||
/* Returns number of corresponding points */
|
||||
int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
static int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
IplImage *image2,/* Image 2 */
|
||||
CvMat *points1,
|
||||
CvMat *points1,
|
||||
CvMat *pntStatus1,
|
||||
CvMat *points2,
|
||||
CvMat *pntStatus2,
|
||||
@@ -203,7 +203,7 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
/* Test input data for errors */
|
||||
|
||||
/* Test for null pointers */
|
||||
if( image1 == 0 || image2 == 0 ||
|
||||
if( image1 == 0 || image2 == 0 ||
|
||||
points1 == 0 || points2 == 0 ||
|
||||
pntStatus1 == 0 || pntStatus2 == 0)
|
||||
{
|
||||
@@ -226,7 +226,7 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
}
|
||||
|
||||
/* Test for matrices */
|
||||
if( !CV_IS_MAT(points1) || !CV_IS_MAT(points2) ||
|
||||
if( !CV_IS_MAT(points1) || !CV_IS_MAT(points2) ||
|
||||
!CV_IS_MAT(pntStatus1) || !CV_IS_MAT(pntStatus2) )
|
||||
{
|
||||
CV_ERROR( CV_StsUnsupportedFormat, "Input parameters (points and status) must be a matrices" );
|
||||
@@ -333,11 +333,11 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
pyrImage1, pyrImage2,
|
||||
cornerPoints1, cornerPoints2,
|
||||
numVisPoints, cvSize(10,10), 3,
|
||||
status, errors,
|
||||
status, errors,
|
||||
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03),
|
||||
0/*CV_LKFLOW_PYR_A_READY*/ );
|
||||
|
||||
|
||||
|
||||
memset(stat2,0,sizeof(uchar)*numPoints);
|
||||
|
||||
int currVis = 0;
|
||||
@@ -393,7 +393,7 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
CvMat fundMatr;
|
||||
double fundMatr_dat[9];
|
||||
fundMatr = cvMat(3,3,CV_64F,fundMatr_dat);
|
||||
|
||||
|
||||
CV_CALL( pStatus = cvCreateMat(1,totalCorns,CV_32F) );
|
||||
|
||||
int num = cvFindFundamentalMat(tmpPoints1,tmpPoints2,&fundMatr,CV_FM_RANSAC,threshold,0.99,pStatus);
|
||||
@@ -435,8 +435,9 @@ int icvFindCorrForGivenPoints( IplImage *image1,/* Image 1 */
|
||||
|
||||
return resNumCorrPoints;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints,CvMat *addStatus,int addCreateNum)
|
||||
static int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints,CvMat *addStatus,int addCreateNum)
|
||||
{
|
||||
/* Add to existing points and status arrays new points or just grow */
|
||||
CvMat *newOldPoint = 0;
|
||||
@@ -445,7 +446,7 @@ int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints,
|
||||
|
||||
CV_FUNCNAME( "icvGrowPointsAndStatus" );
|
||||
__BEGIN__;
|
||||
|
||||
|
||||
/* Test for errors */
|
||||
if( oldPoints == 0 || oldStatus == 0 )
|
||||
{
|
||||
@@ -546,8 +547,9 @@ int icvGrowPointsAndStatus(CvMat **oldPoints,CvMat **oldStatus,CvMat *addPoints,
|
||||
|
||||
return newTotalNumber;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
static int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
CvMat *newPoints,/* New points */
|
||||
CvMat *oldStatus,/* Status for old points */
|
||||
CvMat *newStatus,
|
||||
@@ -560,7 +562,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
CvSeq* seq = 0;
|
||||
|
||||
int originalPoints = 0;
|
||||
|
||||
|
||||
CV_FUNCNAME( "icvRemoveDoublePoins" );
|
||||
__BEGIN__;
|
||||
|
||||
@@ -624,7 +626,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
{
|
||||
CV_ERROR( CV_StsOutOfRange, "Statuses must have 1 row" );
|
||||
}
|
||||
|
||||
|
||||
/* we have points on image and wants add new points */
|
||||
/* use subdivision for find nearest points */
|
||||
|
||||
@@ -731,7 +733,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
/* Point is double. Turn it off */
|
||||
/* Set status */
|
||||
//newStatus->data.ptr[i] = 0;
|
||||
|
||||
|
||||
/* No this is a double point */
|
||||
//originalPoints--;
|
||||
flag = 0;
|
||||
@@ -745,7 +747,7 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
__END__;
|
||||
|
||||
cvReleaseMemStorage( &storage );
|
||||
|
||||
|
||||
|
||||
return originalPoints;
|
||||
|
||||
@@ -755,11 +757,11 @@ int icvRemoveDoublePoins( CvMat *oldPoints,/* Points on prev image */
|
||||
void icvComputeProjectMatrix(CvMat* objPoints,CvMat* projPoints,CvMat* projMatr);
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *status, CvMat *projMatr)
|
||||
static void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *status, CvMat *projMatr)
|
||||
{
|
||||
/* Compute number of good points */
|
||||
int num = cvCountNonZero(status);
|
||||
|
||||
|
||||
/* Create arrays */
|
||||
CvMat *objPoints = 0;
|
||||
objPoints = cvCreateMat(4,num,CV_64F);
|
||||
@@ -802,7 +804,7 @@ void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *stat
|
||||
|
||||
currVis++;
|
||||
}
|
||||
|
||||
|
||||
fprintf(file,"\n");
|
||||
}
|
||||
|
||||
@@ -820,17 +822,16 @@ void icvComputeProjectMatrixStatus(CvMat *objPoints4D,CvMat *points2,CvMat *stat
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* For given N images
|
||||
/* For given N images
|
||||
we have corresponding points on N images
|
||||
computed projection matrices
|
||||
reconstructed 4D points
|
||||
|
||||
we must to compute
|
||||
|
||||
we must to compute
|
||||
|
||||
|
||||
*/
|
||||
|
||||
void icvAddNewImageToPrevious____(
|
||||
static void icvAddNewImageToPrevious____(
|
||||
IplImage *newImage,//Image to add
|
||||
IplImage *oldImage,//Previous image
|
||||
CvMat *oldPoints,// previous 2D points on prev image (some points may be not visible)
|
||||
@@ -868,7 +869,7 @@ void icvAddNewImageToPrevious____(
|
||||
int corrNum;
|
||||
corrNum = icvFindCorrForGivenPoints( oldImage,/* Image 1 */
|
||||
newImage,/* Image 2 */
|
||||
oldPoints,
|
||||
oldPoints,
|
||||
oldPntStatus,
|
||||
points2,
|
||||
status,
|
||||
@@ -887,10 +888,10 @@ void icvAddNewImageToPrevious____(
|
||||
// icvComputeProjectMatrix(objPoints4D,points2,&projMatr);
|
||||
icvComputeProjectMatrixStatus(objPoints4D,points2,status,&projMatr);
|
||||
cvCopy(&projMatr,newProjMatr);
|
||||
|
||||
|
||||
/* Create new points and find correspondence */
|
||||
icvCreateFeaturePoints(newImage, newFPoints2D2,newFPointsStatus);
|
||||
|
||||
|
||||
/* Good if we test new points before find corr points */
|
||||
|
||||
/* Find correspondence for new found points */
|
||||
@@ -947,7 +948,7 @@ void icvAddNewImageToPrevious____(
|
||||
//CreateGood
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
int icvDeleteSparsInPoints( int numImages,
|
||||
static int icvDeleteSparsInPoints( int numImages,
|
||||
CvMat **points,
|
||||
CvMat **status,
|
||||
CvMat *wasStatus)/* status of previous configuration */
|
||||
@@ -979,7 +980,7 @@ int icvDeleteSparsInPoints( int numImages,
|
||||
|
||||
int numCoord;
|
||||
numCoord = points[0]->rows;// !!! may be number of coordinates is not correct !!!
|
||||
|
||||
|
||||
int i;
|
||||
int currExistPoint;
|
||||
currExistPoint = 0;
|
||||
@@ -1041,7 +1042,7 @@ int icvDeleteSparsInPoints( int numImages,
|
||||
return comNumber;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
void icvGrowPointsArray(CvMat **points)
|
||||
{
|
||||
@@ -1089,7 +1090,7 @@ int AddImageToStruct( IplImage *newImage,//Image to add
|
||||
cvConvert(pntStatus,status);
|
||||
|
||||
int corrNum = FindCorrForGivenPoints(oldImage,newImage,oldPoints,newPoints,status);
|
||||
|
||||
|
||||
/* Status has new status of points */
|
||||
|
||||
CvMat projMatr;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
Stan Birchfield and Carlo Tomasi
|
||||
International Journal of Computer Vision,
|
||||
35(3): 269-293, December 1999.
|
||||
|
||||
|
||||
This implementation uses different cost function that results in
|
||||
O(pixPerRow*maxDisparity) complexity of dynamic programming stage versus
|
||||
O(pixPerRow*log(pixPerRow)*maxDisparity) in the above paper.
|
||||
@@ -68,7 +68,7 @@
|
||||
typedef struct _CvDPCell
|
||||
{
|
||||
uchar step; //local-optimal step
|
||||
int sum; //current sum
|
||||
int sum; //current sum
|
||||
}_CvDPCell;
|
||||
|
||||
typedef struct _CvRightImData
|
||||
@@ -79,17 +79,17 @@ typedef struct _CvRightImData
|
||||
#define CV_IMAX3(a,b,c) ((temp3 = (a) >= (b) ? (a) : (b)),(temp3 >= (c) ? temp3 : (c)))
|
||||
#define CV_IMIN3(a,b,c) ((temp3 = (a) <= (b) ? (a) : (b)),(temp3 <= (c) ? temp3 : (c)))
|
||||
|
||||
void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
static void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
uchar* disparities,
|
||||
CvSize size, int widthStep,
|
||||
int maxDisparity,
|
||||
float _param1, float _param2,
|
||||
int maxDisparity,
|
||||
float _param1, float _param2,
|
||||
float _param3, float _param4,
|
||||
float _param5 )
|
||||
{
|
||||
int x, y, i, j, temp3;
|
||||
int d, s;
|
||||
int dispH = maxDisparity + 3;
|
||||
int dispH = maxDisparity + 3;
|
||||
uchar *dispdata;
|
||||
int imgW = size.width;
|
||||
int imgH = size.height;
|
||||
@@ -103,22 +103,22 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
int param5 = cvRound(_param5);
|
||||
|
||||
#define CELL(d,x) cells[(d)+(x)*dispH]
|
||||
|
||||
|
||||
uchar* dsi = (uchar*)cvAlloc(sizeof(uchar)*imgW*dispH);
|
||||
uchar* edges = (uchar*)cvAlloc(sizeof(uchar)*imgW*imgH);
|
||||
_CvDPCell* cells = (_CvDPCell*)cvAlloc(sizeof(_CvDPCell)*imgW*MAX(dispH,(imgH+1)/2));
|
||||
_CvRightImData* rData = (_CvRightImData*)cvAlloc(sizeof(_CvRightImData)*imgW);
|
||||
int* reliabilities = (int*)cells;
|
||||
|
||||
for( y = 0; y < imgH; y++ )
|
||||
{
|
||||
|
||||
for( y = 0; y < imgH; y++ )
|
||||
{
|
||||
uchar* srcdata1 = src1 + widthStep * y;
|
||||
uchar* srcdata2 = src2 + widthStep * y;
|
||||
uchar* srcdata2 = src2 + widthStep * y;
|
||||
|
||||
//init rData
|
||||
prevval = prev = srcdata2[0];
|
||||
for( j = 1; j < imgW; j++ )
|
||||
{
|
||||
{
|
||||
curr = srcdata2[j];
|
||||
val = (uchar)((curr + prev)>>1);
|
||||
rData[j-1].max_val = (uchar)CV_IMAX3( val, prevval, prev );
|
||||
@@ -130,12 +130,12 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
|
||||
// fill dissimularity space image
|
||||
for( i = 1; i <= maxDisparity + 1; i++ )
|
||||
{
|
||||
{
|
||||
dsi += imgW;
|
||||
rData--;
|
||||
for( j = i - 1; j < imgW - 1; j++ )
|
||||
{
|
||||
int t;
|
||||
{
|
||||
int t;
|
||||
if( (t = srcdata1[j] - rData[j+1].max_val) >= 0 )
|
||||
{
|
||||
dsi[j] = (uchar)t;
|
||||
@@ -160,36 +160,36 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
for( j = 3; j < imgW-4; j++ )
|
||||
{
|
||||
edges[y*imgW+j] = 0;
|
||||
|
||||
if( ( CV_IMAX3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) -
|
||||
|
||||
if( ( CV_IMAX3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) -
|
||||
CV_IMIN3( srcdata1[j-3], srcdata1[j-2], srcdata1[j-1] ) ) >= ICV_BIRCH_DIFF_LUM )
|
||||
{
|
||||
edges[y*imgW+j] |= 1;
|
||||
}
|
||||
if( ( CV_IMAX3( srcdata2[j+3], srcdata2[j+2], srcdata2[j+1] ) -
|
||||
if( ( CV_IMAX3( srcdata2[j+3], srcdata2[j+2], srcdata2[j+1] ) -
|
||||
CV_IMIN3( srcdata2[j+3], srcdata2[j+2], srcdata2[j+1] ) ) >= ICV_BIRCH_DIFF_LUM )
|
||||
{
|
||||
edges[y*imgW+j] |= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//find correspondence using dynamical programming
|
||||
//init DP table
|
||||
for( x = 0; x < imgW; x++ )
|
||||
for( x = 0; x < imgW; x++ )
|
||||
{
|
||||
CELL(0,x).sum = CELL(dispH-1,x).sum = ICV_MAX_DP_SUM_VAL;
|
||||
CELL(0,x).step = CELL(dispH-1,x).step = ICV_DP_STEP_LEFT;
|
||||
}
|
||||
for( d = 2; d < dispH; d++ )
|
||||
for( d = 2; d < dispH; d++ )
|
||||
{
|
||||
CELL(d,d-2).sum = ICV_MAX_DP_SUM_VAL;
|
||||
CELL(d,d-2).step = ICV_DP_STEP_UP;
|
||||
}
|
||||
}
|
||||
CELL(1,0).sum = 0;
|
||||
CELL(1,0).step = ICV_DP_STEP_LEFT;
|
||||
|
||||
for( x = 1; x < imgW; x++ )
|
||||
{
|
||||
{
|
||||
int d = MIN( x + 1, maxDisparity + 1);
|
||||
uchar* _edges = edges + y*imgW + x;
|
||||
int e0 = _edges[0] & 1;
|
||||
@@ -201,17 +201,17 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
int sum[3];
|
||||
|
||||
//check left step
|
||||
sum[0] = _cell[d-dispH].sum - param2;
|
||||
sum[0] = _cell[d-dispH].sum - param2;
|
||||
|
||||
//check up step
|
||||
if( _cell[d+1].step != ICV_DP_STEP_DIAG && e0 )
|
||||
{
|
||||
sum[1] = _cell[d+1].sum + param1;
|
||||
|
||||
if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) )
|
||||
if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) )
|
||||
{
|
||||
int t;
|
||||
|
||||
|
||||
sum[2] = _cell[d-1-dispH].sum + param1;
|
||||
|
||||
t = sum[1] < sum[0];
|
||||
@@ -223,7 +223,7 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
_cell[d].sum = sum[t] + s;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
_cell[d].step = ICV_DP_STEP_DIAG;
|
||||
_cell[d].sum = sum[2] + s;
|
||||
}
|
||||
@@ -242,7 +242,7 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) )
|
||||
else if( _cell[d-1-dispH].step != ICV_DP_STEP_UP && (_edges[1-d] & 2) )
|
||||
{
|
||||
sum[2] = _cell[d-1-dispH].sum + param1;
|
||||
if( sum[0] <= sum[2] )
|
||||
@@ -278,25 +278,25 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
min_val = CELL(i,imgW-1).sum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//track optimal pass
|
||||
for( x = imgW - 1; x > 0; x-- )
|
||||
{
|
||||
{
|
||||
dispdata[x] = (uchar)(d - 1);
|
||||
while( CELL(d,x).step == ICV_DP_STEP_UP ) d++;
|
||||
if ( CELL(d,x).step == ICV_DP_STEP_DIAG )
|
||||
{
|
||||
s = x;
|
||||
while( CELL(d,x).step == ICV_DP_STEP_DIAG )
|
||||
while( CELL(d,x).step == ICV_DP_STEP_DIAG )
|
||||
{
|
||||
d--;
|
||||
x--;
|
||||
d--;
|
||||
x--;
|
||||
}
|
||||
for( i = x; i < s; i++ )
|
||||
{
|
||||
dispdata[i] = (uchar)(d-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//for x
|
||||
}// for y
|
||||
|
||||
@@ -319,9 +319,9 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
{
|
||||
for( y = 1; y < imgH - 1; y++ )
|
||||
{
|
||||
if( ( CV_IMAX3( src1[(y-1)*widthStep+x], src1[y*widthStep+x],
|
||||
src1[(y+1)*widthStep+x] ) -
|
||||
CV_IMIN3( src1[(y-1)*widthStep+x], src1[y*widthStep+x],
|
||||
if( ( CV_IMAX3( src1[(y-1)*widthStep+x], src1[y*widthStep+x],
|
||||
src1[(y+1)*widthStep+x] ) -
|
||||
CV_IMIN3( src1[(y-1)*widthStep+x], src1[y*widthStep+x],
|
||||
src1[(y+1)*widthStep+x] ) ) >= ICV_BIRCH_DIFF_LUM )
|
||||
{
|
||||
edges[y*imgW+x] |= 4;
|
||||
@@ -332,14 +332,14 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
}
|
||||
}
|
||||
|
||||
//remove along any particular row, every gradient
|
||||
//remove along any particular row, every gradient
|
||||
//for which two adjacent columns do not agree.
|
||||
for( y = 0; y < imgH; y++ )
|
||||
{
|
||||
prev = edges[y*imgW];
|
||||
for( x = 1; x < imgW - 1; x++ )
|
||||
{
|
||||
curr = edges[y*imgW+x];
|
||||
curr = edges[y*imgW+x];
|
||||
if( (curr & 4) &&
|
||||
( !( prev & 4 ) ||
|
||||
!( edges[y*imgW+x+1] & 4 ) ) )
|
||||
@@ -360,41 +360,41 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
;
|
||||
s = y - i;
|
||||
for( ; i < y; i++ )
|
||||
{
|
||||
{
|
||||
reliabilities[i*imgW+x] = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Y - propagate reliable regions
|
||||
}
|
||||
|
||||
//Y - propagate reliable regions
|
||||
for( x = 0; x < imgW; x++ )
|
||||
{
|
||||
{
|
||||
for( y = 0; y < imgH; y++ )
|
||||
{
|
||||
{
|
||||
d = dest[y*widthStep+x];
|
||||
if( reliabilities[y*imgW+x] >= param4 && !(edges[y*imgW+x] & 4) &&
|
||||
d > 0 )//highly || moderately
|
||||
{
|
||||
{
|
||||
disparities[y*widthStep+x] = (uchar)d;
|
||||
//up propagation
|
||||
for( i = y - 1; i >= 0; i-- )
|
||||
{
|
||||
if( ( edges[i*imgW+x] & 4 ) ||
|
||||
( dest[i*widthStep+x] < d &&
|
||||
( dest[i*widthStep+x] < d &&
|
||||
reliabilities[i*imgW+x] >= param3 ) ||
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
dest[i*widthStep+x] - 1 == d ) ) break;
|
||||
|
||||
disparities[i*widthStep+x] = (uchar)d;
|
||||
}
|
||||
|
||||
disparities[i*widthStep+x] = (uchar)d;
|
||||
}
|
||||
|
||||
//down propagation
|
||||
for( i = y + 1; i < imgH; i++ )
|
||||
{
|
||||
if( ( edges[i*imgW+x] & 4 ) ||
|
||||
( dest[i*widthStep+x] < d &&
|
||||
( dest[i*widthStep+x] < d &&
|
||||
reliabilities[i*imgW+x] >= param3 ) ||
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
dest[i*widthStep+x] - 1 == d ) ) break;
|
||||
|
||||
disparities[i*widthStep+x] = (uchar)d;
|
||||
@@ -417,41 +417,41 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
for( ; x < imgW && dest[y*widthStep+x] == dest[y*widthStep+x-1]; x++ );
|
||||
s = x - i;
|
||||
for( ; i < x; i++ )
|
||||
{
|
||||
{
|
||||
reliabilities[y*imgW+i] = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//X - propagate reliable regions
|
||||
for( y = 0; y < imgH; y++ )
|
||||
{
|
||||
}
|
||||
|
||||
//X - propagate reliable regions
|
||||
for( y = 0; y < imgH; y++ )
|
||||
{
|
||||
for( x = 0; x < imgW; x++ )
|
||||
{
|
||||
{
|
||||
d = dest[y*widthStep+x];
|
||||
if( reliabilities[y*imgW+x] >= param4 && !(edges[y*imgW+x] & 1) &&
|
||||
d > 0 )//highly || moderately
|
||||
{
|
||||
{
|
||||
disparities[y*widthStep+x] = (uchar)d;
|
||||
//up propagation
|
||||
for( i = x - 1; i >= 0; i-- )
|
||||
{
|
||||
if( (edges[y*imgW+i] & 1) ||
|
||||
( dest[y*widthStep+i] < d &&
|
||||
( dest[y*widthStep+i] < d &&
|
||||
reliabilities[y*imgW+i] >= param3 ) ||
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
dest[y*widthStep+i] - 1 == d ) ) break;
|
||||
|
||||
disparities[y*widthStep+i] = (uchar)d;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//down propagation
|
||||
for( i = x + 1; i < imgW; i++ )
|
||||
{
|
||||
if( (edges[y*imgW+i] & 1) ||
|
||||
( dest[y*widthStep+i] < d &&
|
||||
( dest[y*widthStep+i] < d &&
|
||||
reliabilities[y*imgW+i] >= param3 ) ||
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
( reliabilities[y*imgW+x] < param5 &&
|
||||
dest[y*widthStep+i] - 1 == d ) ) break;
|
||||
|
||||
disparities[y*widthStep+i] = (uchar)d;
|
||||
@@ -466,10 +466,10 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
}
|
||||
|
||||
//release resources
|
||||
cvFree( &dsi );
|
||||
cvFree( &edges );
|
||||
cvFree( &cells );
|
||||
cvFree( &rData );
|
||||
cvFree( &dsi );
|
||||
cvFree( &edges );
|
||||
cvFree( &cells );
|
||||
cvFree( &rData );
|
||||
}
|
||||
|
||||
|
||||
@@ -483,7 +483,7 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
// rightImage - right image of stereo-pair (format 8uC1).
|
||||
// mode -mode of correspondance retrieval (now CV_RETR_DP_BIRCHFIELD only)
|
||||
// dispImage - destination disparity image
|
||||
// maxDisparity - maximal disparity
|
||||
// maxDisparity - maximal disparity
|
||||
// param1, param2, param3, param4, param5 - parameters of algorithm
|
||||
// Returns:
|
||||
// Notes:
|
||||
@@ -491,43 +491,43 @@ void icvFindStereoCorrespondenceByBirchfieldDP( uchar* src1, uchar* src2,
|
||||
// All images must have format 8uC1.
|
||||
//F*/
|
||||
CV_IMPL void
|
||||
cvFindStereoCorrespondence(
|
||||
cvFindStereoCorrespondence(
|
||||
const CvArr* leftImage, const CvArr* rightImage,
|
||||
int mode,
|
||||
CvArr* depthImage,
|
||||
int maxDisparity,
|
||||
double param1, double param2, double param3,
|
||||
int maxDisparity,
|
||||
double param1, double param2, double param3,
|
||||
double param4, double param5 )
|
||||
{
|
||||
{
|
||||
CV_FUNCNAME( "cvFindStereoCorrespondence" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvMat *src1, *src2;
|
||||
CvMat *src1, *src2;
|
||||
CvMat *dst;
|
||||
CvMat src1_stub, src2_stub, dst_stub;
|
||||
int coi;
|
||||
int coi;
|
||||
|
||||
CV_CALL( src1 = cvGetMat( leftImage, &src1_stub, &coi ));
|
||||
if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" );
|
||||
CV_CALL( src2 = cvGetMat( rightImage, &src2_stub, &coi ));
|
||||
if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" );
|
||||
if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" );
|
||||
CV_CALL( dst = cvGetMat( depthImage, &dst_stub, &coi ));
|
||||
if( coi ) CV_ERROR( CV_BadCOI, "COI is not supported by the function" );
|
||||
|
||||
// check args
|
||||
if( CV_MAT_TYPE( src1->type ) != CV_8UC1 ||
|
||||
CV_MAT_TYPE( src2->type ) != CV_8UC1 ||
|
||||
// check args
|
||||
if( CV_MAT_TYPE( src1->type ) != CV_8UC1 ||
|
||||
CV_MAT_TYPE( src2->type ) != CV_8UC1 ||
|
||||
CV_MAT_TYPE( dst->type ) != CV_8UC1) CV_ERROR(CV_StsUnsupportedFormat,
|
||||
"All images must be single-channel and have 8u" );
|
||||
"All images must be single-channel and have 8u" );
|
||||
|
||||
if( !CV_ARE_SIZES_EQ( src1, src2 ) || !CV_ARE_SIZES_EQ( src1, dst ) )
|
||||
CV_ERROR( CV_StsUnmatchedSizes, "" );
|
||||
|
||||
|
||||
if( maxDisparity <= 0 || maxDisparity >= src1->width || maxDisparity > 255 )
|
||||
CV_ERROR(CV_StsOutOfRange,
|
||||
CV_ERROR(CV_StsOutOfRange,
|
||||
"parameter /maxDisparity/ is out of range");
|
||||
|
||||
|
||||
if( mode == CV_DISPARITY_BIRCHFIELD )
|
||||
{
|
||||
if( param1 == CV_UNDEF_SC_PARAM ) param1 = CV_IDP_BIRCHFIELD_PARAM1;
|
||||
@@ -536,10 +536,10 @@ cvFindStereoCorrespondence(
|
||||
if( param4 == CV_UNDEF_SC_PARAM ) param4 = CV_IDP_BIRCHFIELD_PARAM4;
|
||||
if( param5 == CV_UNDEF_SC_PARAM ) param5 = CV_IDP_BIRCHFIELD_PARAM5;
|
||||
|
||||
CV_CALL( icvFindStereoCorrespondenceByBirchfieldDP( src1->data.ptr,
|
||||
src2->data.ptr, dst->data.ptr,
|
||||
CV_CALL( icvFindStereoCorrespondenceByBirchfieldDP( src1->data.ptr,
|
||||
src2->data.ptr, dst->data.ptr,
|
||||
cvGetMatSize( src1 ), src1->step,
|
||||
maxDisparity, (float)param1, (float)param2, (float)param3,
|
||||
maxDisparity, (float)param1, (float)param2, (float)param3,
|
||||
(float)param4, (float)param5 ) );
|
||||
}
|
||||
else
|
||||
@@ -547,7 +547,7 @@ cvFindStereoCorrespondence(
|
||||
CV_ERROR( CV_StsBadArg, "Unsupported mode of function" );
|
||||
}
|
||||
|
||||
__END__;
|
||||
__END__;
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
CvStatus CV_STDCALL
|
||||
static CvStatus
|
||||
icvJacobiEigens_32f(float *A, float *V, float *E, int n, float eps)
|
||||
{
|
||||
int i, j, k, ind;
|
||||
|
||||
@@ -83,7 +83,7 @@ static int CompareContour(const void* a, const void* b, void* )
|
||||
return (dx < wt && dy < ht);
|
||||
}
|
||||
|
||||
void cvFindBlobsByCCClasters(IplImage* pFG, CvBlobSeq* pBlobs, CvMemStorage* storage)
|
||||
static void cvFindBlobsByCCClasters(IplImage* pFG, CvBlobSeq* pBlobs, CvMemStorage* storage)
|
||||
{ /* Create contours: */
|
||||
IplImage* pIB = NULL;
|
||||
CvSeq* cnt = NULL;
|
||||
|
||||
@@ -160,9 +160,5 @@ public:
|
||||
};
|
||||
|
||||
/* Blob detector constructor: */
|
||||
CvBlobDetector* cvCreateBlobDetectorReal(CvTestSeq* pTestSeq){return new CvBlobDetectorReal(pTestSeq);}
|
||||
|
||||
|
||||
|
||||
|
||||
//CvBlobDetector* cvCreateBlobDetectorReal(CvTestSeq* pTestSeq){return new CvBlobDetectorReal(pTestSeq);}
|
||||
|
||||
|
||||
+146
-145
File diff suppressed because it is too large
Load Diff
@@ -48,7 +48,7 @@
|
||||
#include "_kdtree.hpp"
|
||||
#include "_featuretree.h"
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#if defined _MSC_VER && _MSC_VER >= 1400
|
||||
#pragma warning(disable:4996) // suppress "function call with parameters may be unsafe" in std::copy
|
||||
#endif
|
||||
|
||||
@@ -95,7 +95,7 @@ class CvKDTreeWrap : public CvFeatureTree {
|
||||
|
||||
for (int j = 0; j < d->rows; ++j) {
|
||||
const typename __treetype::scalar_type* dj =
|
||||
(const typename __treetype::scalar_type*) dptr;
|
||||
(const typename __treetype::scalar_type*) dptr;
|
||||
|
||||
int* resultsj = (int*) resultsptr;
|
||||
double* distj = (double*) distptr;
|
||||
@@ -103,8 +103,8 @@ class CvKDTreeWrap : public CvFeatureTree {
|
||||
|
||||
assert((int)nn.size() <= k);
|
||||
for (unsigned int j = 0; j < nn.size(); ++j) {
|
||||
*resultsj++ = *nn[j].p;
|
||||
*distj++ = nn[j].dist;
|
||||
*resultsj++ = *nn[j].p;
|
||||
*distj++ = nn[j].dist;
|
||||
}
|
||||
std::fill(resultsj, resultsj + k - nn.size(), -1);
|
||||
std::fill(distj, distj + k - nn.size(), 0);
|
||||
@@ -117,16 +117,16 @@ class CvKDTreeWrap : public CvFeatureTree {
|
||||
|
||||
template <class __treetype>
|
||||
int find_ortho_range(CvMat* bounds_min, CvMat* bounds_max,
|
||||
CvMat* results) {
|
||||
CvMat* results) {
|
||||
int rn = results->rows * results->cols;
|
||||
std::vector<int> inbounds;
|
||||
dispatch_cvtype(mat, ((__treetype*)data)->
|
||||
find_ortho_range((typename __treetype::scalar_type*)bounds_min->data.ptr,
|
||||
(typename __treetype::scalar_type*)bounds_max->data.ptr,
|
||||
inbounds));
|
||||
find_ortho_range((typename __treetype::scalar_type*)bounds_min->data.ptr,
|
||||
(typename __treetype::scalar_type*)bounds_max->data.ptr,
|
||||
inbounds));
|
||||
std::copy(inbounds.begin(),
|
||||
inbounds.begin() + std::min((int)inbounds.size(), rn),
|
||||
(int*) results->data.ptr);
|
||||
inbounds.begin() + std::min((int)inbounds.size(), rn),
|
||||
(int*) results->data.ptr);
|
||||
return (int)inbounds.size();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class CvKDTreeWrap : public CvFeatureTree {
|
||||
public:
|
||||
CvKDTreeWrap(CvMat* _mat) : mat(_mat) {
|
||||
// * a flag parameter should tell us whether
|
||||
// * (a) user ensures *mat outlives *this and is unchanged,
|
||||
// * (a) user ensures *mat outlives *this and is unchanged,
|
||||
// * (b) we take reference and user ensures mat is unchanged,
|
||||
// * (c) we copy data, (d) we own and release data.
|
||||
|
||||
@@ -144,8 +144,8 @@ public:
|
||||
tmp[j] = j;
|
||||
|
||||
dispatch_cvtype(mat, data = new tree_type
|
||||
(&tmp[0], &tmp[0] + tmp.size(), mat->cols,
|
||||
tree_type::deref_type(mat)));
|
||||
(&tmp[0], &tmp[0] + tmp.size(), mat->cols,
|
||||
tree_type::deref_type(mat)));
|
||||
}
|
||||
~CvKDTreeWrap() {
|
||||
dispatch_cvtype(mat, delete (tree_type*) data);
|
||||
@@ -185,15 +185,15 @@ public:
|
||||
assert(CV_MAT_TYPE(results->type) == CV_32SC1);
|
||||
|
||||
dispatch_cvtype(mat, find_nn<tree_type>
|
||||
(desc, k, emax, results, dist));
|
||||
(desc, k, emax, results, dist));
|
||||
}
|
||||
int FindOrthoRange(CvMat* bounds_min, CvMat* bounds_max,
|
||||
CvMat* results) {
|
||||
CvMat* results) {
|
||||
bool free_bounds = false;
|
||||
int count = -1;
|
||||
|
||||
if (bounds_min->cols * bounds_min->rows != dims() ||
|
||||
bounds_max->cols * bounds_max->rows != dims())
|
||||
bounds_max->cols * bounds_max->rows != dims())
|
||||
CV_Error(CV_StsUnmatchedSizes, "bounds_{min,max} must 1 x dims or dims x 1");
|
||||
if (CV_MAT_TYPE(bounds_min->type) != CV_MAT_TYPE(bounds_max->type))
|
||||
CV_Error(CV_StsUnmatchedFormats, "bounds_{min,max} must have same type");
|
||||
@@ -218,7 +218,7 @@ public:
|
||||
assert(bounds_max->rows * bounds_max->cols == dims());
|
||||
|
||||
dispatch_cvtype(mat, count = find_ortho_range<tree_type>
|
||||
(bounds_min, bounds_max,results));
|
||||
(bounds_min, bounds_max,results));
|
||||
|
||||
if (free_bounds) {
|
||||
cvReleaseMat(&bounds_min);
|
||||
|
||||
@@ -1247,7 +1247,7 @@ int _cvSolveEqu1th(T c1, T c0, T* X);
|
||||
vertices_number: in, number of vertices in polygon
|
||||
Return :
|
||||
--------------------------------------------------------------------------*/
|
||||
void _cvSetSeqBlockSize(CvVoronoiDiagramInt* pVoronoiDiagramInt,int vertices_number)
|
||||
static void _cvSetSeqBlockSize(CvVoronoiDiagramInt* pVoronoiDiagramInt,int vertices_number)
|
||||
{
|
||||
int N = 2*vertices_number;
|
||||
cvSetSeqBlockSize(pVoronoiDiagramInt->SiteSeq,N*pVoronoiDiagramInt->SiteSeq->elem_size);
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
typedef void (*pointer_LMJac)( const CvMat* src, CvMat* dst );
|
||||
typedef void (*pointer_LMFunc)( const CvMat* src, CvMat* dst );
|
||||
|
||||
#if 0
|
||||
/* Optimization using Levenberg-Marquardt */
|
||||
void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction,
|
||||
pointer_LMFunc function,
|
||||
@@ -75,7 +76,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction,
|
||||
CvMat *matrJtJN = 0;
|
||||
CvMat *matrJt = 0;
|
||||
CvMat *vectB = 0;
|
||||
|
||||
|
||||
CV_FUNCNAME( "cvLevenbegrMarquardtOptimization" );
|
||||
__BEGIN__;
|
||||
|
||||
@@ -104,7 +105,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction,
|
||||
{
|
||||
CV_ERROR( CV_StsUnmatchedSizes, "Number of colomn of vector X0 must be 1" );
|
||||
}
|
||||
|
||||
|
||||
if( observRes->cols != 1 )
|
||||
{
|
||||
CV_ERROR( CV_StsUnmatchedSizes, "Number of colomn of vector observed rusult must be 1" );
|
||||
@@ -157,8 +158,8 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction,
|
||||
/* Print result of function to file */
|
||||
|
||||
/* Compute error */
|
||||
cvSub(observRes,resFunc,error);
|
||||
|
||||
cvSub(observRes,resFunc,error);
|
||||
|
||||
//valError = error_function(observRes,resFunc);
|
||||
/* Need to use new version of computing error (norm) */
|
||||
valError = cvNorm(observRes,resFunc);
|
||||
@@ -169,7 +170,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction,
|
||||
/* Define optimal delta for J'*J*delta=J'*error */
|
||||
/* compute J'J */
|
||||
cvMulTransposed(Jac,matrJtJ,1);
|
||||
|
||||
|
||||
cvCopy(matrJtJ,matrJtJN);
|
||||
|
||||
/* compute J'*error */
|
||||
@@ -244,6 +245,7 @@ void cvLevenbergMarquardtOptimization(pointer_LMJac JacobianFunction,
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
|
||||
@@ -65,9 +65,13 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat**
|
||||
*/
|
||||
#define TRACK_BUNDLE_FILE "d:\\test\\bundle.txt"
|
||||
|
||||
void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPoints,
|
||||
CvMat** pointsPres, int numImages,
|
||||
CvMat** resultProjMatrs, CvMat* resultPoints4D,int maxIter,double epsilon );
|
||||
|
||||
|
||||
/* ============== Bundle adjustment optimization ================= */
|
||||
void icvComputeDerivateProj(CvMat *points4D,CvMat *projMatr, CvMat *status, CvMat *derivProj)
|
||||
static void icvComputeDerivateProj(CvMat *points4D,CvMat *projMatr, CvMat *status, CvMat *derivProj)
|
||||
{
|
||||
/* Compute derivate for given projection matrix points and status of points */
|
||||
|
||||
@@ -201,7 +205,7 @@ void icvComputeDerivateProj(CvMat *points4D,CvMat *projMatr, CvMat *status, CvMa
|
||||
}
|
||||
/*======================================================================================*/
|
||||
|
||||
void icvComputeDerivateProjAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **projDerives)
|
||||
static void icvComputeDerivateProjAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **projDerives)
|
||||
{
|
||||
CV_FUNCNAME( "icvComputeDerivateProjAll" );
|
||||
__BEGIN__;
|
||||
@@ -228,7 +232,7 @@ void icvComputeDerivateProjAll(CvMat *points4D, CvMat **projMatrs, CvMat **point
|
||||
}
|
||||
/*======================================================================================*/
|
||||
|
||||
void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints, CvMat *derivPoint)
|
||||
static void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints, CvMat *derivPoint)
|
||||
{
|
||||
|
||||
CV_FUNCNAME( "icvComputeDerivatePoints" );
|
||||
@@ -267,7 +271,7 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints
|
||||
{
|
||||
CV_ERROR( CV_StsOutOfRange, "Size of projection matrix (projMatr) must be 3x4" );
|
||||
}
|
||||
|
||||
|
||||
if( !CV_IS_MAT(presPoints) )
|
||||
{
|
||||
CV_ERROR( CV_StsUnsupportedFormat, "Status must be a matrix 1xN" );
|
||||
@@ -282,10 +286,10 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints
|
||||
{
|
||||
CV_ERROR( CV_StsUnsupportedFormat, "derivPoint must be a matrix 2 x 4VisNum" );
|
||||
}
|
||||
/* ----- End test ----- */
|
||||
|
||||
/* ----- End test ----- */
|
||||
|
||||
/* Compute derivates by points */
|
||||
|
||||
|
||||
double p[12];
|
||||
int i;
|
||||
for( i = 0; i < 12; i++ )
|
||||
@@ -311,16 +315,16 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints
|
||||
piX[0] = X[0]*p[0] + X[1]*p[1] + X[2]*p[2] + X[3]*p[3];
|
||||
piX[1] = X[0]*p[4] + X[1]*p[5] + X[2]*p[6] + X[3]*p[7];
|
||||
piX[2] = X[0]*p[8] + X[1]*p[9] + X[2]*p[10] + X[3]*p[11];
|
||||
|
||||
|
||||
int i,j;
|
||||
|
||||
double tmp3 = 1/(piX[2]*piX[2]);
|
||||
|
||||
|
||||
for( j = 0; j < 2; j++ )//for x and y
|
||||
{
|
||||
for( i = 0; i < 4; i++ )// for X,Y,Z,W
|
||||
{
|
||||
cvmSet( derivPoint,
|
||||
cvmSet( derivPoint,
|
||||
j, currVisPoint*4+i,
|
||||
(p[j*4+i]*piX[2]-p[8+i]*piX[j]) * tmp3 );
|
||||
}
|
||||
@@ -337,8 +341,9 @@ void icvComputeDerivatePoints(CvMat *points4D,CvMat *projMatr, CvMat *presPoints
|
||||
__END__;
|
||||
return;
|
||||
}
|
||||
|
||||
/*======================================================================================*/
|
||||
void icvComputeDerivatePointsAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **pointDerives)
|
||||
static void icvComputeDerivatePointsAll(CvMat *points4D, CvMat **projMatrs, CvMat **pointPres, int numImages,CvMat **pointDerives)
|
||||
{
|
||||
CV_FUNCNAME( "icvComputeDerivatePointsAll" );
|
||||
__BEGIN__;
|
||||
@@ -364,7 +369,7 @@ void icvComputeDerivatePointsAll(CvMat *points4D, CvMat **projMatrs, CvMat **poi
|
||||
return;
|
||||
}
|
||||
/*======================================================================================*/
|
||||
void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, CvMat **matrV)
|
||||
static void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, CvMat **matrV)
|
||||
{
|
||||
int *shifts = 0;
|
||||
|
||||
@@ -404,10 +409,10 @@ void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, C
|
||||
{
|
||||
if( cvmGet(presPoints[currImage],0,currPoint) > 0 )
|
||||
{
|
||||
sum += cvmGet(pointDeriv[currImage],0,shifts[currImage]*4+i) *
|
||||
sum += cvmGet(pointDeriv[currImage],0,shifts[currImage]*4+i) *
|
||||
cvmGet(pointDeriv[currImage],0,shifts[currImage]*4+j);
|
||||
|
||||
sum += cvmGet(pointDeriv[currImage],1,shifts[currImage]*4+i) *
|
||||
sum += cvmGet(pointDeriv[currImage],1,shifts[currImage]*4+i) *
|
||||
cvmGet(pointDeriv[currImage],1,shifts[currImage]*4+j);
|
||||
}
|
||||
}
|
||||
@@ -429,11 +434,11 @@ void icvComputeMatrixVAll(int numImages,CvMat **pointDeriv,CvMat **presPoints, C
|
||||
|
||||
__END__;
|
||||
cvFree( &shifts);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
/*======================================================================================*/
|
||||
void icvComputeMatrixUAll(int numImages,CvMat **projDeriv,CvMat** matrU)
|
||||
static void icvComputeMatrixUAll(int numImages,CvMat **projDeriv,CvMat** matrU)
|
||||
{
|
||||
CV_FUNCNAME( "icvComputeMatrixVAll" );
|
||||
__BEGIN__;
|
||||
@@ -460,7 +465,7 @@ void icvComputeMatrixUAll(int numImages,CvMat **projDeriv,CvMat** matrU)
|
||||
return;
|
||||
}
|
||||
/*======================================================================================*/
|
||||
void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvMat **presPoints, CvMat *matrW)
|
||||
static void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvMat **presPoints, CvMat *matrW)
|
||||
{
|
||||
CV_FUNCNAME( "icvComputeMatrixW" );
|
||||
__BEGIN__;
|
||||
@@ -509,10 +514,10 @@ void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvM
|
||||
for( int currCol = 0; currCol < 4; currCol++ )
|
||||
{
|
||||
double sum;
|
||||
sum = cvmGet(projDeriv[currImage],currVis*2+0,currLine) *
|
||||
sum = cvmGet(projDeriv[currImage],currVis*2+0,currLine) *
|
||||
cvmGet(pointDeriv[currImage],0,currVis*4+currCol);
|
||||
|
||||
sum += cvmGet(projDeriv[currImage],currVis*2+1,currLine) *
|
||||
sum += cvmGet(projDeriv[currImage],currVis*2+1,currLine) *
|
||||
cvmGet(pointDeriv[currImage],1,currVis*4+currCol);
|
||||
|
||||
cvmSet(matrW,currImage*12+currLine,currPoint*4+currCol,sum);
|
||||
@@ -529,7 +534,7 @@ void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef TRACK_BUNDLE
|
||||
{
|
||||
FILE *file;
|
||||
@@ -560,9 +565,10 @@ void icvComputeMatrixW(int numImages, CvMat **projDeriv, CvMat **pointDeriv, CvM
|
||||
__END__;
|
||||
return;
|
||||
}
|
||||
|
||||
/*======================================================================================*/
|
||||
/* Compute jacobian mult projection matrices error */
|
||||
void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,CvMat *jacProjErr )
|
||||
static void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,CvMat *jacProjErr )
|
||||
{
|
||||
CV_FUNCNAME( "icvComputeJacErrorProj" );
|
||||
__BEGIN__;
|
||||
@@ -596,7 +602,7 @@ void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,C
|
||||
double sum = 0;
|
||||
for( int i = 0; i < num; i++ )
|
||||
{
|
||||
sum += cvmGet(projDeriv[currImage],i,currCol) *
|
||||
sum += cvmGet(projDeriv[currImage],i,currCol) *
|
||||
cvmGet(projErrors[currImage],i%2,i/2);
|
||||
}
|
||||
cvmSet(jacProjErr,currImage*12+currCol,0,sum);
|
||||
@@ -627,9 +633,10 @@ void icvComputeJacErrorProj(int numImages,CvMat **projDeriv,CvMat **projErrors,C
|
||||
__END__;
|
||||
return;
|
||||
}
|
||||
|
||||
/*======================================================================================*/
|
||||
/* Compute jacobian mult points error */
|
||||
void icvComputeJacErrorPoint(int numImages,CvMat **pointDeriv,CvMat **projErrors, CvMat **presPoints,CvMat *jacPointErr )
|
||||
static void icvComputeJacErrorPoint(int numImages,CvMat **pointDeriv,CvMat **projErrors, CvMat **presPoints,CvMat *jacPointErr )
|
||||
{
|
||||
int *shifts = 0;
|
||||
|
||||
@@ -734,6 +741,7 @@ void icvComputeJacErrorPoint(int numImages,CvMat **pointDeriv,CvMat **projErrors
|
||||
}
|
||||
/*======================================================================================*/
|
||||
|
||||
|
||||
/* Reconstruct 4D points using status */
|
||||
void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat** presPoints,
|
||||
CvMat *points4D,int numImages,CvMat **projError)
|
||||
@@ -797,7 +805,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat**
|
||||
numVisProj++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( numVisProj < 2 )
|
||||
{
|
||||
/* This point can't be reconstructed */
|
||||
@@ -821,7 +829,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat**
|
||||
y = cvmGet(projPoints[currImage],1,currPoint);
|
||||
for( int k = 0; k < 4; k++ )
|
||||
{
|
||||
matrA_dat[currVisProj*12 + k] =
|
||||
matrA_dat[currVisProj*12 + k] =
|
||||
x * cvmGet(projMatrs[currImage],2,k) - cvmGet(projMatrs[currImage],0,k);
|
||||
|
||||
matrA_dat[currVisProj*12+4 + k] =
|
||||
@@ -854,7 +862,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat**
|
||||
CvMat point3D;
|
||||
double point3D_dat[3];
|
||||
point3D = cvMat(3,1,CV_64F,point3D_dat);
|
||||
|
||||
|
||||
int currPoint;
|
||||
int numVis = 0;
|
||||
double totalError = 0;
|
||||
@@ -897,7 +905,7 @@ void icvReconstructPoints4DStatus(CvMat** projPoints, CvMat **projMatrs, CvMat**
|
||||
|
||||
/*======================================================================================*/
|
||||
|
||||
void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, CvMat **pointsPres, CvMat **projPoints)
|
||||
static void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs, CvMat **pointsPres, CvMat **projPoints)
|
||||
{
|
||||
CV_FUNCNAME( "icvProjPointsStatusFunc" );
|
||||
__BEGIN__;
|
||||
@@ -943,7 +951,7 @@ void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs,
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int currImage;
|
||||
for( currImage = 0; currImage < numImages; currImage++ )
|
||||
{
|
||||
@@ -969,7 +977,7 @@ void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs,
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
cvmMul(projMatrs[currImage],&point4D,&point3D);
|
||||
double w = point3D_dat[2];
|
||||
cvmSet(projPoints[currImage],0,currVisPoint,point3D_dat[0]/w);
|
||||
@@ -998,11 +1006,11 @@ void icvProjPointsStatusFunc( int numImages, CvMat *points4D, CvMat **projMatrs,
|
||||
}
|
||||
|
||||
/*======================================================================================*/
|
||||
void icvFreeMatrixArray(CvMat ***matrArray,int numMatr)
|
||||
static void icvFreeMatrixArray(CvMat ***matrArray,int numMatr)
|
||||
{
|
||||
/* Free each matrix */
|
||||
int currMatr;
|
||||
|
||||
|
||||
if( *matrArray != 0 )
|
||||
{/* Need delete */
|
||||
for( currMatr = 0; currMatr < numMatr; currMatr++ )
|
||||
@@ -1015,7 +1023,7 @@ void icvFreeMatrixArray(CvMat ***matrArray,int numMatr)
|
||||
}
|
||||
|
||||
/*======================================================================================*/
|
||||
void *icvClearAlloc(int size)
|
||||
static void *icvClearAlloc(int size)
|
||||
{
|
||||
void *ptr = 0;
|
||||
|
||||
@@ -1047,6 +1055,7 @@ int icvDeleteSparsInPoints( int numImages,
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*======================================================================================*/
|
||||
/* !!! may be useful to return norm of error */
|
||||
/* !!! may be does not work correct with not all visible 4D points */
|
||||
@@ -1054,15 +1063,15 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
CvMat** pointsPres, int numImages,
|
||||
CvMat** resultProjMatrs, CvMat* resultPoints4D,int maxIter,double epsilon )
|
||||
{
|
||||
|
||||
|
||||
CvMat *vectorX_points4D = 0;
|
||||
CvMat **vectorX_projMatrs = 0;
|
||||
CvMat **vectorX_projMatrs = 0;
|
||||
|
||||
CvMat *newVectorX_points4D = 0;
|
||||
CvMat **newVectorX_projMatrs = 0;
|
||||
|
||||
CvMat *changeVectorX_points4D = 0;
|
||||
CvMat *changeVectorX_projMatrs = 0;
|
||||
CvMat *changeVectorX_projMatrs = 0;
|
||||
|
||||
CvMat **observVisPoints = 0;
|
||||
CvMat **projVisPoints = 0;
|
||||
@@ -1097,17 +1106,17 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
{
|
||||
CV_ERROR( CV_StsOutOfRange, "Number of images must be more than zero" );
|
||||
}
|
||||
|
||||
|
||||
if( maxIter < 1 || maxIter > 2000 )
|
||||
{
|
||||
CV_ERROR( CV_StsOutOfRange, "Maximum number of iteration must be in [1..1000]" );
|
||||
}
|
||||
|
||||
|
||||
if( epsilon < 0 )
|
||||
{
|
||||
CV_ERROR( CV_StsOutOfRange, "Epsilon parameter must be >= 0" );
|
||||
}
|
||||
|
||||
|
||||
if( !CV_IS_MAT(resultPoints4D) )
|
||||
{
|
||||
CV_ERROR( CV_StsUnsupportedFormat, "resultPoints4D must be a matrix 4 x NumPnt" );
|
||||
@@ -1139,7 +1148,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
CV_CALL( changeVectorX_projMatrs = cvCreateMat(3,4,CV_64F));
|
||||
|
||||
int currImage;
|
||||
|
||||
|
||||
/* ----- Test input params ----- */
|
||||
for( currImage = 0; currImage < numImages; currImage++ )
|
||||
{
|
||||
@@ -1355,7 +1364,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
double norm = cvNorm(vectorX_projMatrs[i]);
|
||||
fprintf(file," test 6.01 prev normProj=%lf\n",norm);
|
||||
}
|
||||
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
@@ -1384,7 +1393,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
double norm = cvNorm(matrsUk[i]);
|
||||
fprintf(file," test 6.01 prev matrsUk=%lf\n",norm);
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < numPoints; i++ )
|
||||
{
|
||||
double norm = cvNorm(matrsVi[i]);
|
||||
@@ -1427,7 +1436,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
double norm = cvNorm(matrsUk[i]);
|
||||
fprintf(file," test 6.01 post1 matrsUk=%lf\n",norm);
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < numPoints; i++ )
|
||||
{
|
||||
double norm = cvNorm(matrsVi[i]);
|
||||
@@ -1612,7 +1621,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
newError += currNorm * currNorm;
|
||||
}
|
||||
newError = sqrt(newError);
|
||||
|
||||
|
||||
currIter++;
|
||||
|
||||
|
||||
@@ -1732,7 +1741,7 @@ void cvOptimizeLevenbergMarquardtBundle( CvMat** projMatrs, CvMat** observProjPo
|
||||
|
||||
|
||||
} while( change > epsilon && currIter < maxIter );
|
||||
|
||||
|
||||
/*--------------------------------------------*/
|
||||
/* Optimization complete copy computed params */
|
||||
/* Copy projection matrices */
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
|
||||
/* Valery Mosyagin */
|
||||
|
||||
#if 0
|
||||
|
||||
typedef void (*pointer_LMJac)( const CvMat* src, CvMat* dst );
|
||||
typedef void (*pointer_LMFunc)( const CvMat* src, CvMat* dst );
|
||||
|
||||
@@ -61,7 +63,7 @@ void icvReconstructPointsFor3View( CvMat* projMatr1,CvMat* projMatr2,CvMat* proj
|
||||
|
||||
|
||||
/* Jacobian computation for trifocal case */
|
||||
void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian)
|
||||
static void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian)
|
||||
{
|
||||
CV_FUNCNAME( "icvJacobianFunction_ProjTrifocal" );
|
||||
__BEGIN__;
|
||||
@@ -101,7 +103,7 @@ void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian)
|
||||
/* Fill Jacobian matrix */
|
||||
int currProjPoint;
|
||||
int currMatr;
|
||||
|
||||
|
||||
cvZero(Jacobian);
|
||||
for( currMatr = 0; currMatr < 3; currMatr++ )
|
||||
{
|
||||
@@ -137,7 +139,7 @@ void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian)
|
||||
{
|
||||
for( i = 0; i < 4; i++ )// for X,Y,Z,W
|
||||
{
|
||||
cvmSet( Jacobian,
|
||||
cvmSet( Jacobian,
|
||||
currMatr*numPoints*2+currProjPoint*2+j, 36+currProjPoint*4+i,
|
||||
(p[j*4+i]*piX[2]-p[8+i]*piX[j]) * tmp3 );
|
||||
}
|
||||
@@ -161,7 +163,7 @@ void icvJacobianFunction_ProjTrifocal(const CvMat *vectX,CvMat *Jacobian)
|
||||
return;
|
||||
}
|
||||
|
||||
void icvFunc_ProjTrifocal(const CvMat *vectX, CvMat *resFunc)
|
||||
static void icvFunc_ProjTrifocal(const CvMat *vectX, CvMat *resFunc)
|
||||
{
|
||||
/* Computes function in a given point */
|
||||
/* Computers project points using 3 projection matrices and points 3D */
|
||||
@@ -264,7 +266,7 @@ void icvFunc_ProjTrifocal(const CvMat *vectX, CvMat *resFunc)
|
||||
|
||||
/*----------------------------------------------------------------------------------------*/
|
||||
|
||||
void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints,
|
||||
static void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints,
|
||||
CvMat **resultProjMatrs, CvMat *resultPoints4D)
|
||||
{
|
||||
|
||||
@@ -312,7 +314,7 @@ void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints,
|
||||
{
|
||||
CV_ERROR( CV_StsNullPtr, "Some of projPoints is a NULL pointer" );
|
||||
}
|
||||
|
||||
|
||||
if( resultProjMatrs[i] == 0 )
|
||||
{
|
||||
CV_ERROR( CV_StsNullPtr, "Some of resultProjMatrs is a NULL pointer" );
|
||||
@@ -402,7 +404,7 @@ void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints,
|
||||
cvmSet(vectorX0,36 + currPoint*4 + 3,0,cvmGet(points4D,3,currPoint));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Allocate memory for result */
|
||||
cvLevenbergMarquardtOptimization( icvJacobianFunction_ProjTrifocal, icvFunc_ProjTrifocal,
|
||||
vectorX0,observRes,optimX,100,1e-6);
|
||||
@@ -441,7 +443,7 @@ void icvOptimizeProjectionTrifocal(CvMat **projMatrs,CvMat **projPoints,
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* Create good points using status information */
|
||||
void icvCreateGoodPoints(CvMat *points,CvMat **goodPoints, CvMat *status)
|
||||
static void icvCreateGoodPoints(CvMat *points,CvMat **goodPoints, CvMat *status)
|
||||
{
|
||||
*goodPoints = 0;
|
||||
|
||||
@@ -493,3 +495,4 @@ void icvCreateGoodPoints(CvMat *points,CvMat **goodPoints, CvMat *status)
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -87,7 +87,7 @@ double _cvStretchingWork(CvPoint2D32f* P1,
|
||||
|
||||
L1 = sqrt( (double)P1->x*P1->x + P1->y*P1->y);
|
||||
L2 = sqrt( (double)P2->x*P2->x + P2->y*P2->y);
|
||||
|
||||
|
||||
L_min = MIN(L1, L2);
|
||||
dL = fabs( L1 - L2 );
|
||||
|
||||
@@ -96,15 +96,15 @@ double _cvStretchingWork(CvPoint2D32f* P1,
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
CvPoint2D32f Q( CvPoint2D32f q0, CvPoint2D32f q1, CvPoint2D32f q2, double t );
|
||||
double angle( CvPoint2D32f A, CvPoint2D32f B );
|
||||
|
||||
double _cvBendingWork( CvPoint2D32f* B0,
|
||||
CvPoint2D32f* F0,
|
||||
CvPoint2D32f* B1,
|
||||
CvPoint2D32f* F1/*,
|
||||
CvPoint* K*/)
|
||||
{
|
||||
CvPoint2D32f Q( CvPoint2D32f q0, CvPoint2D32f q1, CvPoint2D32f q2, double t );
|
||||
double angle( CvPoint2D32f A, CvPoint2D32f B );
|
||||
|
||||
CvPoint2D32f Q0, Q1, Q2;
|
||||
CvPoint2D32f Q1_nm = { 0, 0 }, Q2_nm = { 0, 0 };
|
||||
double d0, d1, d2, des, t_zero;
|
||||
@@ -140,7 +140,7 @@ double _cvBendingWork( CvPoint2D32f* B0,
|
||||
d_angle = d_angle - CV_PI*0.5;
|
||||
d_angle = fabs(d_angle);
|
||||
|
||||
|
||||
|
||||
K->x = -K->x;
|
||||
K->y = -K->y;
|
||||
B1->x = -B1->x;
|
||||
@@ -427,7 +427,7 @@ void _cvWorkSouthEast(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D
|
||||
small_edge.y = NULL_EDGE*edges1[i-2].y;
|
||||
|
||||
w1 = W[i-1][j-1].w_east + _cvBendingWork(&edges1[i-2],
|
||||
&edges1[i-1],
|
||||
&edges1[i-1],
|
||||
/*&null_edge*/&small_edge,
|
||||
&edges2[j-1]/*,
|
||||
&edges2[j-2]*/);
|
||||
@@ -442,7 +442,7 @@ void _cvWorkSouthEast(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D
|
||||
small_edge.y = NULL_EDGE*edges2[j-2].y;
|
||||
|
||||
w3 = W[i-1][j-1].w_south + _cvBendingWork( /*&null_edge*/&small_edge,
|
||||
&edges1[i-1],
|
||||
&edges1[i-1],
|
||||
&edges2[j-2],
|
||||
&edges2[j-1]/*,
|
||||
&edges1[i-2]*/);
|
||||
@@ -511,6 +511,7 @@ void _cvWorkSouth(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D32f*
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===================================================
|
||||
CvPoint2D32f Q(CvPoint2D32f q0,CvPoint2D32f q1,CvPoint2D32f q2,double t)
|
||||
{
|
||||
@@ -519,14 +520,14 @@ CvPoint2D32f Q(CvPoint2D32f q0,CvPoint2D32f q1,CvPoint2D32f q2,double t)
|
||||
q.x = (float)(q0.x*(1-t)*(1-t) + 2*q1.x*t*(1-t) + q2.x*t*t);
|
||||
q.y = (float)(q0.y*(1-t)*(1-t) + 2*q1.y*t*(1-t) + q2.y*t*t);
|
||||
|
||||
return q;
|
||||
return q;
|
||||
}
|
||||
|
||||
double angle(CvPoint2D32f A, CvPoint2D32f B)
|
||||
{
|
||||
return acos( (A.x*B.x + A.y*B.y)/sqrt( (double)(A.x*A.x + A.y*A.y)*(B.x*B.x + B.y*B.y) ) );
|
||||
}
|
||||
|
||||
#if 0
|
||||
/***************************************************************************************\
|
||||
*
|
||||
* This function compute intermediate polygon between contour1 and contour2
|
||||
@@ -536,14 +537,14 @@ double angle(CvPoint2D32f A, CvPoint2D32f B)
|
||||
* param = [0,1]; 0 correspondence to contour1, 1 - contour2
|
||||
*
|
||||
\***************************************************************************************/
|
||||
CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
static CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
CvSeq* contour2,
|
||||
CvSeq* corr,
|
||||
double param,
|
||||
CvMemStorage* storage)
|
||||
{
|
||||
int j;
|
||||
|
||||
|
||||
CvSeqWriter writer01;
|
||||
CvSeqReader reader01;
|
||||
|
||||
@@ -558,7 +559,7 @@ CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
int corr_point;
|
||||
|
||||
// Create output sequence.
|
||||
CvSeq* output = cvCreateSeq(0,
|
||||
CvSeq* output = cvCreateSeq(0,
|
||||
sizeof(CvSeq),
|
||||
sizeof(CvPoint),
|
||||
storage );
|
||||
@@ -570,7 +571,7 @@ CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
point1 = (CvPoint* )malloc( Ni*sizeof(CvPoint) );
|
||||
point2 = (CvPoint* )malloc( Nj*sizeof(CvPoint) );
|
||||
|
||||
// Initialize arrays of point
|
||||
// Initialize arrays of point
|
||||
cvCvtSeqToArray( contour1, point1, CV_WHOLE_SEQ );
|
||||
cvCvtSeqToArray( contour2, point2, CV_WHOLE_SEQ );
|
||||
|
||||
@@ -583,7 +584,7 @@ CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
|
||||
i = Ni-1; //correspondence to points of contour1
|
||||
for( ; corr; corr = corr->h_next )
|
||||
{
|
||||
{
|
||||
//Initializes process of sequential reading from sequence
|
||||
cvStartReadSeq( corr, &reader01, 0 );
|
||||
|
||||
@@ -595,7 +596,7 @@ CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
// Compute point of intermediate polygon.
|
||||
point_output.x = cvRound(point1[i].x + param*( point2[corr_point].x - point1[i].x ));
|
||||
point_output.y = cvRound(point1[i].y + param*( point2[corr_point].y - point1[i].y ));
|
||||
|
||||
|
||||
// Write element to sequence.
|
||||
CV_WRITE_SEQ_ELEM( point_output, writer01 );
|
||||
}
|
||||
@@ -603,7 +604,7 @@ CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
}
|
||||
// Updates sequence header.
|
||||
cvFlushSeqWriter( &writer01 );
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -621,9 +622,9 @@ CvSeq* icvBlendContours(CvSeq* contour1,
|
||||
**************************************************************************************************/
|
||||
|
||||
|
||||
void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
CvSeq* contour2,
|
||||
CvSeq** corr,
|
||||
static void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
CvSeq* contour2,
|
||||
CvSeq** corr,
|
||||
CvMemStorage* storage)
|
||||
{
|
||||
int i,j; // counter of cycles
|
||||
@@ -660,7 +661,7 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
edges1 = (CvPoint2D32f* )malloc( (Ni-1)*sizeof(CvPoint2D32f) );
|
||||
edges2 = (CvPoint2D32f* )malloc( (Nj-1)*sizeof(CvPoint2D32f) );
|
||||
|
||||
// Initialize arrays of point
|
||||
// Initialize arrays of point
|
||||
cvCvtSeqToArray( contour1, point1, CV_WHOLE_SEQ );
|
||||
cvCvtSeqToArray( contour2, point2, CV_WHOLE_SEQ );
|
||||
|
||||
@@ -679,7 +680,7 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
edges2[i].y = (float)( point2[i+1].y - point2[i].y );
|
||||
};
|
||||
|
||||
// Find infinity constant
|
||||
// Find infinity constant
|
||||
//inf=1;
|
||||
/////////////
|
||||
|
||||
@@ -716,11 +717,11 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
{
|
||||
j=0;/////////
|
||||
W[i][j].w_east = W[i-1][j].w_east;
|
||||
W[i][j].w_east = W[i][j].w_east /*+
|
||||
W[i][j].w_east = W[i][j].w_east /*+
|
||||
_cvBendingWork( &edges1[i-2], &edges1[i-1], &null_edge, &null_edge, NULL )*/;
|
||||
W[i][j].w_east = W[i][j].w_east + _cvStretchingWork( &edges2[i-1], &null_edge );
|
||||
W[i][j].path_e = PATH_TO_E;
|
||||
|
||||
|
||||
j=1;//////////
|
||||
W[i][j].w_south = inf;
|
||||
|
||||
@@ -732,18 +733,18 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
small_edge.x = NULL_EDGE*edges1[i-2].x;
|
||||
small_edge.y = NULL_EDGE*edges1[i-2].y;
|
||||
|
||||
W[i][j].w_southeast = W[i][j].w_southeast +
|
||||
W[i][j].w_southeast = W[i][j].w_southeast +
|
||||
_cvBendingWork( &edges1[i-2], &edges1[i-1], /*&null_edge*/&small_edge, &edges2[j-1]/*, &edges2[Nj-2]*/);
|
||||
|
||||
W[i][j].path_se = PATH_TO_E;
|
||||
}
|
||||
|
||||
for(j=2; j<Nj; j++)
|
||||
{
|
||||
{
|
||||
i=0;//////////
|
||||
W[i][j].w_south = W[i][j-1].w_south;
|
||||
W[i][j].w_south = W[i][j].w_south + _cvStretchingWork( &null_edge, &edges2[j-1] );
|
||||
W[i][j].w_south = W[i][j].w_south /*+
|
||||
W[i][j].w_south = W[i][j].w_south /*+
|
||||
_cvBendingWork( &null_edge, &null_edge, &edges2[j-2], &edges2[j-1], NULL )*/;
|
||||
W[i][j].path_s = 3;
|
||||
|
||||
@@ -758,7 +759,7 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
small_edge.x = NULL_EDGE*edges2[j-2].x;
|
||||
small_edge.y = NULL_EDGE*edges2[j-2].y;
|
||||
|
||||
W[i][j].w_southeast = W[i][j].w_southeast +
|
||||
W[i][j].w_southeast = W[i][j].w_southeast +
|
||||
_cvBendingWork( /*&null_edge*/&small_edge, &edges1[i-1], &edges2[j-2], &edges2[j-1]/*, &edges1[Ni-2]*/);
|
||||
W[i][j].path_se = 3;
|
||||
}
|
||||
@@ -773,8 +774,8 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
|
||||
i=Ni-1;j=Nj-1;
|
||||
|
||||
*corr = cvCreateSeq(0,
|
||||
sizeof(CvSeq),
|
||||
*corr = cvCreateSeq(0,
|
||||
sizeof(CvSeq),
|
||||
sizeof(int),
|
||||
storage );
|
||||
|
||||
@@ -806,26 +807,26 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
{
|
||||
CV_WRITE_SEQ_ELEM( j, writer );
|
||||
|
||||
switch( path )
|
||||
switch( path )
|
||||
{
|
||||
case PATH_TO_E:
|
||||
path = W[i][j].path_e;
|
||||
i--;
|
||||
cvFlushSeqWriter( &writer );
|
||||
corr01->h_next = cvCreateSeq( 0,
|
||||
sizeof(CvSeq),
|
||||
corr01->h_next = cvCreateSeq( 0,
|
||||
sizeof(CvSeq),
|
||||
sizeof(int),
|
||||
storage );
|
||||
corr01 = corr01->h_next;
|
||||
cvStartAppendToSeq( corr01, &writer );
|
||||
break;
|
||||
|
||||
|
||||
case PATH_TO_SE:
|
||||
path = W[i][j].path_se;
|
||||
j--; i--;
|
||||
cvFlushSeqWriter( &writer );
|
||||
corr01->h_next = cvCreateSeq( 0,
|
||||
sizeof(CvSeq),
|
||||
corr01->h_next = cvCreateSeq( 0,
|
||||
sizeof(CvSeq),
|
||||
sizeof(int),
|
||||
storage );
|
||||
corr01 = corr01->h_next;
|
||||
@@ -852,4 +853,4 @@ void icvCalcContoursCorrespondence(CvSeq* contour1,
|
||||
free(edges1);
|
||||
free(edges2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+418
-418
File diff suppressed because it is too large
Load Diff
@@ -41,11 +41,11 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ typedef struct CvTSTrans
|
||||
float angle;
|
||||
} CvTSTrans;
|
||||
|
||||
void SET_TRANS_0(CvTSTrans *pT)
|
||||
static void SET_TRANS_0(CvTSTrans *pT)
|
||||
{
|
||||
memset(pT,0,sizeof(CvTSTrans));
|
||||
pT->C = 1;
|
||||
|
||||
@@ -99,8 +99,9 @@ void icvReconstructPointsFor3View( CvMat* projMatr1,CvMat* projMatr2,CvMat* proj
|
||||
/*==========================================================================================*/
|
||||
/* Functions for calculation the tensor */
|
||||
/*==========================================================================================*/
|
||||
#if 0
|
||||
#if 1
|
||||
void fprintMatrix(FILE* file,CvMat* matrix)
|
||||
static void fprintMatrix(FILE* file,CvMat* matrix)
|
||||
{
|
||||
int i,j;
|
||||
fprintf(file,"\n");
|
||||
@@ -116,7 +117,7 @@ void fprintMatrix(FILE* file,CvMat* matrix)
|
||||
#endif
|
||||
/*==========================================================================================*/
|
||||
|
||||
void icvNormalizePoints( CvMat* points, CvMat* normPoints,CvMat* cameraMatr )
|
||||
static void icvNormalizePoints( CvMat* points, CvMat* normPoints,CvMat* cameraMatr )
|
||||
{
|
||||
/* Normalize image points using camera matrix */
|
||||
|
||||
@@ -169,7 +170,7 @@ void icvNormalizePoints( CvMat* points, CvMat* normPoints,CvMat* cameraMatr )
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*=====================================================================================*/
|
||||
/*
|
||||
@@ -405,7 +406,7 @@ int icvComputeProjectMatrices6Points( CvMat* points1,CvMat* points2,CvMat* point
|
||||
}
|
||||
|
||||
/*==========================================================================================*/
|
||||
int icvGetRandNumbers(int range,int count,int* arr)
|
||||
static int icvGetRandNumbers(int range,int count,int* arr)
|
||||
{
|
||||
/* Generate random numbers [0,range-1] */
|
||||
|
||||
@@ -454,7 +455,7 @@ int icvGetRandNumbers(int range,int count,int* arr)
|
||||
return 1;
|
||||
}
|
||||
/*==========================================================================================*/
|
||||
void icvSelectColsByNumbers(CvMat* srcMatr, CvMat* dstMatr, int* indexes,int number)
|
||||
static void icvSelectColsByNumbers(CvMat* srcMatr, CvMat* dstMatr, int* indexes,int number)
|
||||
{
|
||||
|
||||
CV_FUNCNAME( "icvSelectColsByNumbers" );
|
||||
@@ -501,7 +502,7 @@ void icvSelectColsByNumbers(CvMat* srcMatr, CvMat* dstMatr, int* indexes,int num
|
||||
}
|
||||
|
||||
/*==========================================================================================*/
|
||||
void icvProject4DPoints(CvMat* points4D,CvMat* projMatr, CvMat* projPoints)
|
||||
static void icvProject4DPoints(CvMat* points4D,CvMat* projMatr, CvMat* projPoints)
|
||||
{
|
||||
|
||||
CvMat* tmpProjPoints = 0;
|
||||
@@ -584,7 +585,8 @@ void icvProject4DPoints(CvMat* points4D,CvMat* projMatr, CvMat* projPoints)
|
||||
return;
|
||||
}
|
||||
/*==========================================================================================*/
|
||||
int icvCompute3ProjectMatricesNPointsStatus( CvMat** points,/* 3 arrays of points on image */
|
||||
#if 0
|
||||
static int icvCompute3ProjectMatricesNPointsStatus( CvMat** points,/* 3 arrays of points on image */
|
||||
CvMat** projMatrs,/* array of 3 prejection matrices */
|
||||
CvMat** statuses,/* 3 arrays of status of points */
|
||||
double threshold,/* Threshold for good point */
|
||||
@@ -783,6 +785,7 @@ int icvCompute3ProjectMatricesNPointsStatus( CvMat** points,/* 3 arrays of point
|
||||
return numProjMatrs;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*==========================================================================================*/
|
||||
int icvComputeProjectMatricesNPoints( CvMat* points1,CvMat* points2,CvMat* points3,
|
||||
@@ -2350,8 +2353,8 @@ void ReconstructPointsFor3View_bySolve( CvMat* projMatr1,CvMat* projMatr2,CvMat*
|
||||
#endif
|
||||
|
||||
/*==========================================================================================*/
|
||||
|
||||
void icvComputeCameraExrinnsicByPosition(CvMat* camPos, CvMat* rotMatr, CvMat* transVect)
|
||||
#if 0
|
||||
static void icvComputeCameraExrinnsicByPosition(CvMat* camPos, CvMat* rotMatr, CvMat* transVect)
|
||||
{
|
||||
/* We know position of camera. we must to compute rotate matrix and translate vector */
|
||||
|
||||
@@ -2468,7 +2471,7 @@ void icvComputeCameraExrinnsicByPosition(CvMat* camPos, CvMat* rotMatr, CvMat* t
|
||||
|
||||
/*==========================================================================================*/
|
||||
|
||||
void FindTransformForProjectMatrices(CvMat* projMatr1,CvMat* projMatr2,CvMat* rotMatr,CvMat* transVect)
|
||||
static void FindTransformForProjectMatrices(CvMat* projMatr1,CvMat* projMatr2,CvMat* rotMatr,CvMat* transVect)
|
||||
{
|
||||
/* Computes homography for project matrix be "canonical" form */
|
||||
CV_FUNCNAME( "computeProjMatrHomography" );
|
||||
@@ -2586,7 +2589,7 @@ void icvComputeQknowPrincipalPoint(int numImages, CvMat **projMatrs,CvMat *matrQ
|
||||
/* Part with metric reconstruction */
|
||||
|
||||
#if 1
|
||||
void icvComputeQ(int numMatr, CvMat** projMatr, CvMat** cameraMatr, CvMat* matrQ)
|
||||
static void icvComputeQ(int numMatr, CvMat** projMatr, CvMat** cameraMatr, CvMat* matrQ)
|
||||
{
|
||||
/* K*K' = P*Q*P' */
|
||||
/* try to solve Q by linear method */
|
||||
@@ -2731,7 +2734,7 @@ void icvComputeQ(int numMatr, CvMat** projMatr, CvMat** cameraMatr, CvMat* matrQ
|
||||
#endif
|
||||
/*-----------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void icvDecomposeQ(CvMat* /*matrQ*/,CvMat* /*matrH*/)
|
||||
static void icvDecomposeQ(CvMat* /*matrQ*/,CvMat* /*matrH*/)
|
||||
{
|
||||
#if 0
|
||||
/* Use SVD to decompose matrix Q=H*I*H' */
|
||||
@@ -2789,3 +2792,5 @@ void icvDecomposeQ(CvMat* /*matrQ*/,CvMat* /*matrH*/)
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include "_vectrack.h"
|
||||
|
||||
#define NUM_FACE_ELEMENTS 3
|
||||
enum
|
||||
enum
|
||||
{
|
||||
MOUTH = 0,
|
||||
LEYE = 1,
|
||||
@@ -69,7 +69,7 @@ int ChoiceTrackingFace2(CvFaceTracker* pTF, const int nElements, const CvFaceEle
|
||||
inline int GetEnergy(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoint* ptTempl, CvRect* rTempl);
|
||||
inline int GetEnergy2(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoint* ptTempl, CvRect* rTempl, int* element);
|
||||
inline double CalculateTransformationLMS3_0( CvPoint* pTemplPoints, CvPoint* pSrcPoints);
|
||||
inline double CalculateTransformationLMS3( CvPoint* pTemplPoints,
|
||||
inline double CalculateTransformationLMS3( CvPoint* pTemplPoints,
|
||||
CvPoint* pSrcPoints,
|
||||
double* pdbAverageScale,
|
||||
double* pdbAverageRotate,
|
||||
@@ -91,13 +91,13 @@ struct CvTrackingRect
|
||||
int Energy(const CvTrackingRect& prev)
|
||||
{
|
||||
int prev_color = 0 == prev.iColor ? iColor : prev.iColor;
|
||||
iEnergy = 1 * pow2(r.width - prev.r.width) +
|
||||
1 * pow2(r.height - prev.r.height) +
|
||||
1 * pow2(iColor - prev_color) / 4 +
|
||||
- 1 * nRectsInThis +
|
||||
- 0 * nRectsOnTop +
|
||||
+ 0 * nRectsOnLeft +
|
||||
+ 0 * nRectsOnRight +
|
||||
iEnergy = 1 * pow2(r.width - prev.r.width) +
|
||||
1 * pow2(r.height - prev.r.height) +
|
||||
1 * pow2(iColor - prev_color) / 4 +
|
||||
- 1 * nRectsInThis +
|
||||
- 0 * nRectsOnTop +
|
||||
+ 0 * nRectsOnLeft +
|
||||
+ 0 * nRectsOnRight +
|
||||
+ 0 * nRectsOnBottom;
|
||||
return iEnergy;
|
||||
}
|
||||
@@ -110,10 +110,10 @@ struct CvFaceTracker
|
||||
double dbRotateDelta;
|
||||
double dbRotateAngle;
|
||||
CvPoint ptRotate;
|
||||
|
||||
|
||||
CvPoint ptTempl[NUM_FACE_ELEMENTS];
|
||||
CvRect rTempl[NUM_FACE_ELEMENTS];
|
||||
|
||||
|
||||
IplImage* imgGray;
|
||||
IplImage* imgThresh;
|
||||
CvMemStorage* mstgContours;
|
||||
@@ -149,8 +149,8 @@ struct CvFaceTracker
|
||||
imgGray = cvCreateImage(cvSize(imgGray->width, imgGray->height), 8, 1);
|
||||
imgThresh = cvCreateImage(cvSize(imgGray->width, imgGray->height), 8, 1);
|
||||
mstgContours = cvCreateMemStorage();
|
||||
if ((NULL == imgGray) ||
|
||||
(NULL == imgThresh) ||
|
||||
if ((NULL == imgGray) ||
|
||||
(NULL == imgThresh) ||
|
||||
(NULL == mstgContours))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
@@ -162,11 +162,11 @@ struct CvFaceTracker
|
||||
ReallocImage(&imgThresh, sz, 1);
|
||||
ptRotate = face[MOUTH].ptCenter;
|
||||
float m[6];
|
||||
CvMat mat = cvMat( 2, 3, CV_32FC1, m );
|
||||
CvMat mat = cvMat( 2, 3, CV_32FC1, m );
|
||||
|
||||
if (NULL == imgGray || NULL == imgThresh)
|
||||
return FALSE;
|
||||
|
||||
|
||||
/*m[0] = (float)cos(-dbRotateAngle*CV_PI/180.);
|
||||
m[1] = (float)sin(-dbRotateAngle*CV_PI/180.);
|
||||
m[2] = (float)ptRotate.x;
|
||||
@@ -175,7 +175,7 @@ struct CvFaceTracker
|
||||
m[5] = (float)ptRotate.y;*/
|
||||
cv2DRotationMatrix( cvPointTo32f(ptRotate), -dbRotateAngle, 1., &mat );
|
||||
cvWarpAffine( img, imgGray, &mat );
|
||||
|
||||
|
||||
if (NULL == mstgContours)
|
||||
mstgContours = cvCreateMemStorage();
|
||||
else
|
||||
@@ -225,7 +225,7 @@ protected:
|
||||
void Energy();
|
||||
}; //class CvFaceElement
|
||||
|
||||
int CV_CDECL CompareEnergy(const void* el1, const void* el2, void*)
|
||||
inline int CV_CDECL CompareEnergy(const void* el1, const void* el2, void*)
|
||||
{
|
||||
return ((CvTrackingRect*)el1)->iEnergy - ((CvTrackingRect*)el2)->iEnergy;
|
||||
}// int CV_CDECL CompareEnergy(const void* el1, const void* el2, void*)
|
||||
@@ -322,7 +322,7 @@ void CvFaceElement::FindContours(IplImage* img, IplImage* thresh, int nLayers, i
|
||||
}
|
||||
for (CvSeq* internal = external->v_next; internal; internal = internal->h_next)
|
||||
{
|
||||
cr.r = cvContourBoundingRect(internal);
|
||||
cr.r = cvContourBoundingRect(internal);
|
||||
Move(cr.r, roi.x, roi.y);
|
||||
if (RectInRect(cr.r, m_rROI) && cr.r.width > dMinSize && cr.r.height > dMinSize)
|
||||
{
|
||||
@@ -353,7 +353,7 @@ void CvFaceElement::MergeRects(int d)
|
||||
for (j = i + 1; j < nRects; j++)
|
||||
{
|
||||
CvTrackingRect* pRect2 = (CvTrackingRect*)(reader2.ptr);
|
||||
if (abs(pRect1->ptCenter.y - pRect2->ptCenter.y) < d &&
|
||||
if (abs(pRect1->ptCenter.y - pRect2->ptCenter.y) < d &&
|
||||
abs(pRect1->r.height - pRect2->r.height) < d)
|
||||
{
|
||||
CvTrackingRect rNew;
|
||||
@@ -432,7 +432,7 @@ cvInitFaceTracker(CvFaceTracker* pFaceTracker, const IplImage* imgGray, CvRect*
|
||||
(NULL == pRects) ||
|
||||
(nRects < NUM_FACE_ELEMENTS))
|
||||
return NULL;
|
||||
|
||||
|
||||
//int new_face = FALSE;
|
||||
CvFaceTracker* pFace = pFaceTracker;
|
||||
if (NULL == pFace)
|
||||
@@ -468,7 +468,7 @@ cvTrackFace(CvFaceTracker* pFaceTracker, IplImage* imgGray, CvRect* pRects, int
|
||||
pFaceTracker->InitNextImage(imgGray);
|
||||
*ptRotate = pFaceTracker->ptRotate;
|
||||
*dbAngleRotate = pFaceTracker->dbRotateAngle;
|
||||
|
||||
|
||||
int nElements = 16;
|
||||
double dx = pFaceTracker->face[LEYE].ptCenter.x - pFaceTracker->face[REYE].ptCenter.x;
|
||||
double dy = pFaceTracker->face[LEYE].ptCenter.y - pFaceTracker->face[REYE].ptCenter.y;
|
||||
@@ -476,9 +476,9 @@ cvTrackFace(CvFaceTracker* pFaceTracker, IplImage* imgGray, CvRect* pRects, int
|
||||
int d = cvRound(0.25 * d_eyes);
|
||||
int dMinSize = d;
|
||||
int nRestarts = 0;
|
||||
|
||||
|
||||
int elem;
|
||||
|
||||
|
||||
CvFaceElement big_face[NUM_FACE_ELEMENTS];
|
||||
START:
|
||||
// init
|
||||
@@ -533,7 +533,7 @@ START:
|
||||
}
|
||||
if (2 == elements)
|
||||
find2 = TRUE;
|
||||
else
|
||||
else
|
||||
restart = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -563,13 +563,13 @@ RESTART:
|
||||
pFaceTracker->iTrackingFaceType = noel;
|
||||
found = TRUE;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
restart = TRUE;
|
||||
goto RESTART;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (found)
|
||||
{
|
||||
// angle by mouth & eyes
|
||||
@@ -613,7 +613,7 @@ void ThresholdingParam(IplImage *imgGray, int iNumLayers, int &iMinLevel, int &i
|
||||
{
|
||||
assert(imgGray != NULL);
|
||||
assert(imgGray->nChannels == 1);
|
||||
int i, j;
|
||||
int i, j;
|
||||
// create histogram
|
||||
int histImg[256] = {0};
|
||||
uchar* buffImg = (uchar*)imgGray->imageData;
|
||||
@@ -760,7 +760,7 @@ int ChoiceTrackingFace2(CvFaceTracker* pTF, const int nElements, const CvFaceEle
|
||||
double prev_d02 = sqrt((double)prev_v02.x*prev_v02.x + prev_v02.y*prev_v02.y);
|
||||
double new_d01 = sqrt((double)new_v01.x*new_v01.x + new_v01.y*new_v01.y);
|
||||
double scale = templ_d01 / new_d01;
|
||||
double new_d02 = templ_d02 / scale;
|
||||
double new_d02 = templ_d02 / scale;
|
||||
double sin_a = double(prev_v01.x * prev_v02.y - prev_v01.y * prev_v02.x) / (prev_d01 * prev_d02);
|
||||
double cos_a = cos(asin(sin_a));
|
||||
double x = double(new_v01.x) * cos_a - double(new_v01.y) * sin_a;
|
||||
@@ -806,12 +806,12 @@ inline int GetEnergy(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoin
|
||||
double h_mouth = double(ppNew[MOUTH]->r.height) * scale;
|
||||
energy +=
|
||||
int(512.0 * (e_prev + 16.0 * e_templ)) +
|
||||
4 * pow2(ppNew[LEYE]->r.width - ppNew[REYE]->r.width) +
|
||||
4 * pow2(ppNew[LEYE]->r.height - ppNew[REYE]->r.height) +
|
||||
4 * (int)pow(w_eye - double(rTempl[LEYE].width + rTempl[REYE].width) / 2.0, 2) +
|
||||
2 * (int)pow(h_eye - double(rTempl[LEYE].height + rTempl[REYE].height) / 2.0, 2) +
|
||||
1 * (int)pow(w_mouth - double(rTempl[MOUTH].width), 2) +
|
||||
1 * (int)pow(h_mouth - double(rTempl[MOUTH].height), 2) +
|
||||
4 * pow2(ppNew[LEYE]->r.width - ppNew[REYE]->r.width) +
|
||||
4 * pow2(ppNew[LEYE]->r.height - ppNew[REYE]->r.height) +
|
||||
4 * (int)pow(w_eye - double(rTempl[LEYE].width + rTempl[REYE].width) / 2.0, 2) +
|
||||
2 * (int)pow(h_eye - double(rTempl[LEYE].height + rTempl[REYE].height) / 2.0, 2) +
|
||||
1 * (int)pow(w_mouth - double(rTempl[MOUTH].width), 2) +
|
||||
1 * (int)pow(h_mouth - double(rTempl[MOUTH].height), 2) +
|
||||
0;
|
||||
return energy;
|
||||
}
|
||||
@@ -832,20 +832,20 @@ inline int GetEnergy2(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoi
|
||||
double h0 = (double)ppNew[element[0]]->r.height * scale_templ;
|
||||
double w1 = (double)ppNew[element[1]]->r.width * scale_templ;
|
||||
double h1 = (double)ppNew[element[1]]->r.height * scale_templ;
|
||||
|
||||
|
||||
int energy = ppNew[element[0]]->iEnergy + ppNew[element[1]]->iEnergy +
|
||||
- 2 * (ppNew[element[0]]->nRectsInThis - ppNew[element[1]]->nRectsInThis) +
|
||||
- 2 * (ppNew[element[0]]->nRectsInThis - ppNew[element[1]]->nRectsInThis) +
|
||||
(int)pow(w0 - (double)rTempl[element[0]].width, 2) +
|
||||
(int)pow(h0 - (double)rTempl[element[0]].height, 2) +
|
||||
(int)pow(w1 - (double)rTempl[element[1]].width, 2) +
|
||||
(int)pow(h1 - (double)rTempl[element[1]].height, 2) +
|
||||
(int)pow(new_d - prev_d, 2) +
|
||||
0;
|
||||
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
inline double CalculateTransformationLMS3( CvPoint* pTemplPoints,
|
||||
inline double CalculateTransformationLMS3( CvPoint* pTemplPoints,
|
||||
CvPoint* pSrcPoints,
|
||||
double* pdbAverageScale,
|
||||
double* pdbAverageRotate,
|
||||
@@ -866,41 +866,41 @@ inline double CalculateTransformationLMS3( CvPoint* pTemplPoints,
|
||||
double dbYt = double(pTemplPoints[0].y + pTemplPoints[1].y + pTemplPoints[2].y ) / 3.0;
|
||||
double dbXs = double(pSrcPoints[0].x + pSrcPoints[1].x + pSrcPoints[2].x) / 3.0;
|
||||
double dbYs = double(pSrcPoints[0].y + pSrcPoints[1].y + pSrcPoints[2].y) / 3.0;
|
||||
|
||||
|
||||
double dbXtXt = double(pow2(pTemplPoints[0].x) + pow2(pTemplPoints[1].x) + pow2(pTemplPoints[2].x)) / 3.0;
|
||||
double dbYtYt = double(pow2(pTemplPoints[0].y) + pow2(pTemplPoints[1].y) + pow2(pTemplPoints[2].y)) / 3.0;
|
||||
|
||||
|
||||
double dbXsXs = double(pow2(pSrcPoints[0].x) + pow2(pSrcPoints[1].x) + pow2(pSrcPoints[2].x)) / 3.0;
|
||||
double dbYsYs = double(pow2(pSrcPoints[0].y) + pow2(pSrcPoints[1].y) + pow2(pSrcPoints[2].y)) / 3.0;
|
||||
|
||||
double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x +
|
||||
pTemplPoints[1].x * pSrcPoints[1].x +
|
||||
|
||||
double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x +
|
||||
pTemplPoints[1].x * pSrcPoints[1].x +
|
||||
pTemplPoints[2].x * pSrcPoints[2].x) / 3.0;
|
||||
double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y +
|
||||
pTemplPoints[1].y * pSrcPoints[1].y +
|
||||
double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y +
|
||||
pTemplPoints[1].y * pSrcPoints[1].y +
|
||||
pTemplPoints[2].y * pSrcPoints[2].y) / 3.0;
|
||||
|
||||
double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y +
|
||||
pTemplPoints[1].x * pSrcPoints[1].y +
|
||||
|
||||
double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y +
|
||||
pTemplPoints[1].x * pSrcPoints[1].y +
|
||||
pTemplPoints[2].x * pSrcPoints[2].y) / 3.0;
|
||||
double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x +
|
||||
pTemplPoints[1].y * pSrcPoints[1].x +
|
||||
double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x +
|
||||
pTemplPoints[1].y * pSrcPoints[1].x +
|
||||
pTemplPoints[2].y * pSrcPoints[2].x ) / 3.0;
|
||||
|
||||
|
||||
dbXtXt -= dbXt * dbXt;
|
||||
dbYtYt -= dbYt * dbYt;
|
||||
|
||||
|
||||
dbXsXs -= dbXs * dbXs;
|
||||
dbYsYs -= dbYs * dbYs;
|
||||
|
||||
|
||||
dbXtXs -= dbXt * dbXs;
|
||||
dbYtYs -= dbYt * dbYs;
|
||||
|
||||
|
||||
dbXtYs -= dbXt * dbYs;
|
||||
dbYtXs -= dbYt * dbXs;
|
||||
|
||||
|
||||
dbAverageRotate = atan2( dbXtYs - dbYtXs, dbXtXs + dbYtYs );
|
||||
|
||||
|
||||
double cosR = cos(dbAverageRotate);
|
||||
double sinR = sin(dbAverageRotate);
|
||||
double del = dbXsXs + dbYsYs;
|
||||
@@ -909,15 +909,15 @@ inline double CalculateTransformationLMS3( CvPoint* pTemplPoints,
|
||||
dbAverageScale = (double(dbXtXs + dbYtYs) * cosR + double(dbXtYs - dbYtXs) * sinR) / del;
|
||||
dbLMS = dbXtXt + dbYtYt - ((double)pow(dbXtXs + dbYtYs,2) + (double)pow(dbXtYs - dbYtXs,2)) / del;
|
||||
}
|
||||
|
||||
|
||||
dbAverageShiftX = double(dbXt) - dbAverageScale * (double(dbXs) * cosR + double(dbYs) * sinR);
|
||||
dbAverageShiftY = double(dbYt) - dbAverageScale * (double(dbYs) * cosR - double(dbXs) * sinR);
|
||||
|
||||
|
||||
if( pdbAverageScale != NULL ) *pdbAverageScale = dbAverageScale;
|
||||
if( pdbAverageRotate != NULL ) *pdbAverageRotate = dbAverageRotate;
|
||||
if( pdbAverageShiftX != NULL ) *pdbAverageShiftX = dbAverageShiftX;
|
||||
if( pdbAverageShiftY != NULL ) *pdbAverageShiftY = dbAverageShiftY;
|
||||
|
||||
|
||||
assert(dbLMS >= 0);
|
||||
return dbLMS;
|
||||
}
|
||||
@@ -933,39 +933,39 @@ inline double CalculateTransformationLMS3_0( CvPoint* pTemplPoints, CvPoint* pSr
|
||||
double dbYt = double(pTemplPoints[0].y + pTemplPoints[1].y + pTemplPoints[2].y ) / 3.0;
|
||||
double dbXs = double(pSrcPoints[0].x + pSrcPoints[1].x + pSrcPoints[2].x) / 3.0;
|
||||
double dbYs = double(pSrcPoints[0].y + pSrcPoints[1].y + pSrcPoints[2].y) / 3.0;
|
||||
|
||||
|
||||
double dbXtXt = double(pow2(pTemplPoints[0].x) + pow2(pTemplPoints[1].x) + pow2(pTemplPoints[2].x)) / 3.0;
|
||||
double dbYtYt = double(pow2(pTemplPoints[0].y) + pow2(pTemplPoints[1].y) + pow2(pTemplPoints[2].y)) / 3.0;
|
||||
|
||||
|
||||
double dbXsXs = double(pow2(pSrcPoints[0].x) + pow2(pSrcPoints[1].x) + pow2(pSrcPoints[2].x)) / 3.0;
|
||||
double dbYsYs = double(pow2(pSrcPoints[0].y) + pow2(pSrcPoints[1].y) + pow2(pSrcPoints[2].y)) / 3.0;
|
||||
|
||||
double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x +
|
||||
pTemplPoints[1].x * pSrcPoints[1].x +
|
||||
|
||||
double dbXtXs = double(pTemplPoints[0].x * pSrcPoints[0].x +
|
||||
pTemplPoints[1].x * pSrcPoints[1].x +
|
||||
pTemplPoints[2].x * pSrcPoints[2].x) / 3.0;
|
||||
double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y +
|
||||
pTemplPoints[1].y * pSrcPoints[1].y +
|
||||
double dbYtYs = double(pTemplPoints[0].y * pSrcPoints[0].y +
|
||||
pTemplPoints[1].y * pSrcPoints[1].y +
|
||||
pTemplPoints[2].y * pSrcPoints[2].y) / 3.0;
|
||||
|
||||
double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y +
|
||||
pTemplPoints[1].x * pSrcPoints[1].y +
|
||||
|
||||
double dbXtYs = double(pTemplPoints[0].x * pSrcPoints[0].y +
|
||||
pTemplPoints[1].x * pSrcPoints[1].y +
|
||||
pTemplPoints[2].x * pSrcPoints[2].y) / 3.0;
|
||||
double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x +
|
||||
pTemplPoints[1].y * pSrcPoints[1].x +
|
||||
double dbYtXs = double(pTemplPoints[0].y * pSrcPoints[0].x +
|
||||
pTemplPoints[1].y * pSrcPoints[1].x +
|
||||
pTemplPoints[2].y * pSrcPoints[2].x ) / 3.0;
|
||||
|
||||
|
||||
dbXtXt -= dbXt * dbXt;
|
||||
dbYtYt -= dbYt * dbYt;
|
||||
|
||||
|
||||
dbXsXs -= dbXs * dbXs;
|
||||
dbYsYs -= dbYs * dbYs;
|
||||
|
||||
|
||||
dbXtXs -= dbXt * dbXs;
|
||||
dbYtYs -= dbYt * dbYs;
|
||||
|
||||
|
||||
dbXtYs -= dbXt * dbYs;
|
||||
dbYtXs -= dbYt * dbXs;
|
||||
|
||||
|
||||
double del = dbXsXs + dbYsYs;
|
||||
if( del != 0 )
|
||||
dbLMS = dbXtXt + dbYtYt - ((double)pow(dbXtXs + dbYtYs,2) + (double)pow(dbXtYs - dbYtXs,2)) / del;
|
||||
|
||||
+152
-148
@@ -12,7 +12,7 @@ using namespace std;
|
||||
static CV_IMPLEMENT_QSORT_EX( icvSortFloat, float, CV_CMP_FLOAT, float)
|
||||
|
||||
//===========================================================================
|
||||
string ToString(int i)
|
||||
static string ToString(int i)
|
||||
{
|
||||
stringstream tmp;
|
||||
tmp << i;
|
||||
@@ -25,7 +25,7 @@ string ToString(int i)
|
||||
//----------------------------- CvGBTreesParams -----------------------------
|
||||
//===========================================================================
|
||||
|
||||
CvGBTreesParams::CvGBTreesParams()
|
||||
CvGBTreesParams::CvGBTreesParams()
|
||||
: CvDTreeParams( 3, 10, 0, false, 10, 0, false, false, 0 )
|
||||
{
|
||||
weak_count = 200;
|
||||
@@ -36,8 +36,8 @@ CvGBTreesParams::CvGBTreesParams()
|
||||
|
||||
//===========================================================================
|
||||
|
||||
CvGBTreesParams::CvGBTreesParams( int _loss_function_type, int _weak_count,
|
||||
float _shrinkage, float _subsample_portion,
|
||||
CvGBTreesParams::CvGBTreesParams( int _loss_function_type, int _weak_count,
|
||||
float _shrinkage, float _subsample_portion,
|
||||
int _max_depth, bool _use_surrogates )
|
||||
: CvDTreeParams( 3, 10, 0, false, 10, 0, false, false, 0 )
|
||||
{
|
||||
@@ -64,7 +64,7 @@ CvGBTrees::CvGBTrees()
|
||||
class_labels = 0;
|
||||
class_count = 1;
|
||||
delta = 0.0f;
|
||||
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
@@ -88,10 +88,10 @@ void CvGBTrees::clear()
|
||||
//data->shared = false;
|
||||
for (int i=0; i<class_count; ++i)
|
||||
{
|
||||
int weak_count = cvSliceLength( slice, weak[i] );
|
||||
int weak_count = cvSliceLength( slice, weak[i] );
|
||||
if ((weak[i]) && (weak_count))
|
||||
{
|
||||
cvStartReadSeq( weak[i], &reader );
|
||||
cvStartReadSeq( weak[i], &reader );
|
||||
cvSetSeqReaderPos( &reader, slice.start_index );
|
||||
for (int j=0; j<weak_count; ++j)
|
||||
{
|
||||
@@ -106,7 +106,7 @@ void CvGBTrees::clear()
|
||||
if (weak[i]) cvReleaseMemStorage( &(weak[i]->storage) );
|
||||
delete[] weak;
|
||||
}
|
||||
if (data)
|
||||
if (data)
|
||||
{
|
||||
data->shared = false;
|
||||
delete data;
|
||||
@@ -165,7 +165,7 @@ bool CvGBTrees::problem_type() const
|
||||
|
||||
//===========================================================================
|
||||
|
||||
bool
|
||||
bool
|
||||
CvGBTrees::train( CvMLData* data, CvGBTreesParams params, bool update )
|
||||
{
|
||||
bool result;
|
||||
@@ -218,14 +218,14 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
}
|
||||
|
||||
orig_response = cvCreateMat( 1, n, CV_32F );
|
||||
int step = (_responses->cols > _responses->rows) ? 1 : _responses->step / CV_ELEM_SIZE(_responses->type);
|
||||
int step = (_responses->cols > _responses->rows) ? 1 : _responses->step / CV_ELEM_SIZE(_responses->type);
|
||||
switch (CV_MAT_TYPE(_responses->type))
|
||||
{
|
||||
case CV_32FC1:
|
||||
{
|
||||
for (int i=0; i<n; ++i)
|
||||
{
|
||||
for (int i=0; i<n; ++i)
|
||||
orig_response->data.fl[i] = _responses->data.fl[i*step];
|
||||
}; break;
|
||||
}; break;
|
||||
case CV_32SC1:
|
||||
{
|
||||
for (int i=0; i<n; ++i)
|
||||
@@ -250,7 +250,7 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
mask[j] = 1;
|
||||
}
|
||||
delete[] mask;
|
||||
|
||||
|
||||
class_labels = cvCreateMat(1, class_count, CV_32S);
|
||||
class_labels->data.i[0] = int(orig_response->data.fl[0]);
|
||||
int j = 1;
|
||||
@@ -274,14 +274,14 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
if (_sample_idx)
|
||||
{
|
||||
int sample_idx_len = get_len(_sample_idx);
|
||||
|
||||
|
||||
switch (CV_MAT_TYPE(_sample_idx->type))
|
||||
{
|
||||
case CV_32SC1:
|
||||
{
|
||||
sample_idx = cvCreateMat( 1, sample_idx_len, CV_32S );
|
||||
for (int i=0; i<sample_idx_len; ++i)
|
||||
sample_idx->data.i[i] = _sample_idx->data.i[i];
|
||||
sample_idx->data.i[i] = _sample_idx->data.i[i];
|
||||
} break;
|
||||
case CV_8S:
|
||||
case CV_8U:
|
||||
@@ -294,7 +294,7 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
for (int i=0; i<sample_idx_len; ++i)
|
||||
if (int( _sample_idx->data.ptr[i] ))
|
||||
sample_idx->data.i[active_samples_count++] = i;
|
||||
|
||||
|
||||
} break;
|
||||
default: CV_Error(CV_StsUnmatchedFormats, "_sample_idx should be a 32sC1, 8sC1 or 8uC1 vector.");
|
||||
}
|
||||
@@ -335,14 +335,14 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
storage = cvCreateMemStorage();
|
||||
weak[i] = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvDTree*), storage );
|
||||
storage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// subsample params and data
|
||||
rng = &cv::theRNG();
|
||||
|
||||
int samples_count = get_len(sample_idx);
|
||||
int samples_count = get_len(sample_idx);
|
||||
|
||||
params.subsample_portion = params.subsample_portion <= FLT_EPSILON ||
|
||||
params.subsample_portion = params.subsample_portion <= FLT_EPSILON ||
|
||||
1 - params.subsample_portion <= FLT_EPSILON
|
||||
? 1 : params.subsample_portion;
|
||||
int train_sample_count = cvFloor(params.subsample_portion * samples_count);
|
||||
@@ -358,12 +358,12 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
*subsample_test = cvMat( 1, test_sample_count, CV_32SC1,
|
||||
idx_data + train_sample_count );
|
||||
}
|
||||
|
||||
|
||||
// training procedure
|
||||
|
||||
for ( int i=0; i < params.weak_count; ++i )
|
||||
{
|
||||
do_subsample();
|
||||
do_subsample();
|
||||
for ( int k=0; k < class_count; ++k )
|
||||
{
|
||||
find_gradient(k);
|
||||
@@ -387,21 +387,21 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
cvGetRow( data->train_data, &x, idx);
|
||||
else
|
||||
cvGetCol( data->train_data, &x, idx);
|
||||
|
||||
|
||||
if (missing)
|
||||
{
|
||||
if (_tflag == CV_ROW_SAMPLE)
|
||||
cvGetRow( missing, &x_miss, idx);
|
||||
else
|
||||
cvGetCol( missing, &x_miss, idx);
|
||||
|
||||
|
||||
res = (float)tree->predict(&x, &x_miss)->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = (float)tree->predict(&x)->value;
|
||||
}
|
||||
sum_response_tmp->data.fl[idx + k*n] =
|
||||
sum_response_tmp->data.fl[idx + k*n] =
|
||||
sum_response->data.fl[idx + k*n] +
|
||||
params.shrinkage * res;
|
||||
}
|
||||
@@ -421,13 +421,13 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
|
||||
cvReleaseMat(&new_responses);
|
||||
data->free_train_data();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
} // CvGBTrees::train(...)
|
||||
|
||||
//===========================================================================
|
||||
|
||||
float Sign(float x)
|
||||
inline float Sign(float x)
|
||||
{
|
||||
if (x<0.0f) return -1.0f;
|
||||
else if (x>0.0f) return 1.0f;
|
||||
@@ -484,7 +484,7 @@ void CvGBTrees::find_gradient(const int k)
|
||||
residuals[i] = fabs(resp_data[idx] - current_data[idx]);
|
||||
}
|
||||
icvSortFloat(residuals, n, 0.0f);
|
||||
|
||||
|
||||
delta = residuals[int(ceil(n*alpha))];
|
||||
|
||||
for (int i=0; i<n; ++i)
|
||||
@@ -506,7 +506,7 @@ void CvGBTrees::find_gradient(const int k)
|
||||
int s_step = (sample_idx->cols > sample_idx->rows) ? 1
|
||||
: sample_idx->step/CV_ELEM_SIZE(sample_idx->type);
|
||||
int idx = *(sample_data + subsample_data[i]*s_step);
|
||||
|
||||
|
||||
for (int j=0; j<class_count; ++j)
|
||||
{
|
||||
double res;
|
||||
@@ -516,14 +516,14 @@ void CvGBTrees::find_gradient(const int k)
|
||||
exp_sfi += res;
|
||||
}
|
||||
int orig_label = int(resp_data[idx]);
|
||||
/*
|
||||
/*
|
||||
grad_data[idx] = (float)(!(k-class_labels->data.i[orig_label]+1)) -
|
||||
(float)(exp_fk / exp_sfi);
|
||||
*/
|
||||
int ensemble_label = 0;
|
||||
while (class_labels->data.i[ensemble_label] - orig_label)
|
||||
ensemble_label++;
|
||||
|
||||
*/
|
||||
int ensemble_label = 0;
|
||||
while (class_labels->data.i[ensemble_label] - orig_label)
|
||||
ensemble_label++;
|
||||
|
||||
grad_data[idx] = (float)(!(k-ensemble_label)) -
|
||||
(float)(exp_fk / exp_sfi);
|
||||
}
|
||||
@@ -550,19 +550,19 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
|
||||
for (int i=0; i<get_len(subsample_train); ++i)
|
||||
{
|
||||
int idx = *(sample_data + subsample_data[i]*s_step);
|
||||
if (data->tflag == CV_ROW_SAMPLE)
|
||||
int idx = *(sample_data + subsample_data[i]*s_step);
|
||||
if (data->tflag == CV_ROW_SAMPLE)
|
||||
cvGetRow( data->train_data, &x, idx);
|
||||
else
|
||||
cvGetCol( data->train_data, &x, idx);
|
||||
|
||||
|
||||
if (missing)
|
||||
{
|
||||
if (data->tflag == CV_ROW_SAMPLE)
|
||||
cvGetRow( missing, &miss_x, idx);
|
||||
else
|
||||
cvGetCol( missing, &miss_x, idx);
|
||||
|
||||
|
||||
predictions[i] = tree->predict(&x, &miss_x);
|
||||
}
|
||||
else
|
||||
@@ -585,7 +585,7 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
if (!samples_in_leaf) // It should not be done anyways! but...
|
||||
{
|
||||
leaves[i]->value = 0.0;
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
CvMat* leaf_idx = cvCreateMat(1, samples_in_leaf, CV_32S);
|
||||
@@ -606,12 +606,12 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
int len = sum_response_tmp->cols;
|
||||
for (int j=0; j<get_len(leaf_idx); ++j)
|
||||
{
|
||||
int idx = leaf_idx_data[j];
|
||||
int idx = leaf_idx_data[j];
|
||||
sum_response_tmp->data.fl[idx + _k*len] =
|
||||
sum_response->data.fl[idx + _k*len] +
|
||||
params.shrinkage * value;
|
||||
}
|
||||
leaf_idx_data = 0;
|
||||
leaf_idx_data = 0;
|
||||
cvReleaseMat(&leaf_idx);
|
||||
}
|
||||
|
||||
@@ -634,13 +634,13 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
/*
|
||||
void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
{
|
||||
|
||||
|
||||
CvDTreeNode** leaves;
|
||||
int leaves_count = 0;
|
||||
int offset = _k*sum_response_tmp->cols;
|
||||
CvMat leaf_idx;
|
||||
leaf_idx.rows = 1;
|
||||
|
||||
int offset = _k*sum_response_tmp->cols;
|
||||
CvMat leaf_idx;
|
||||
leaf_idx.rows = 1;
|
||||
|
||||
leaves = GetLeaves( tree, leaves_count);
|
||||
|
||||
for (int i=0; i<leaves_count; ++i)
|
||||
@@ -650,14 +650,14 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
data->get_sample_indices(leaves[i], leaf_idx_data);
|
||||
//CvMat* leaf_idx = new CvMat();
|
||||
//cvInitMatHeader(leaf_idx, n, 1, CV_32S, leaf_idx_data);
|
||||
leaf_idx.cols = n;
|
||||
leaf_idx.data.i = leaf_idx_data;
|
||||
leaf_idx.cols = n;
|
||||
leaf_idx.data.i = leaf_idx_data;
|
||||
|
||||
float value = find_optimal_value(&leaf_idx);
|
||||
leaves[i]->value = value;
|
||||
float val = params.shrinkage * value;
|
||||
float val = params.shrinkage * value;
|
||||
|
||||
|
||||
|
||||
for (int j=0; j<n; ++j)
|
||||
{
|
||||
int idx = leaf_idx_data[j] + offset;
|
||||
@@ -665,9 +665,9 @@ void CvGBTrees::change_values(CvDTree* tree, const int _k)
|
||||
}
|
||||
//leaf_idx_data = 0;
|
||||
//cvReleaseMat(&leaf_idx);
|
||||
leaf_idx.data.i = 0;
|
||||
//delete leaf_idx;
|
||||
delete[] leaf_idx_data;
|
||||
leaf_idx.data.i = 0;
|
||||
//delete leaf_idx;
|
||||
delete[] leaf_idx_data;
|
||||
}
|
||||
|
||||
// releasing the memory
|
||||
@@ -707,7 +707,7 @@ float CvGBTrees::find_optimal_value( const CvMat* _Idx )
|
||||
for (int i=0; i<n; ++i, ++idx)
|
||||
residuals[i] = (resp_data[*idx] - cur_data[*idx]);
|
||||
icvSortFloat(residuals, n, 0.0f);
|
||||
if (n % 2)
|
||||
if (n % 2)
|
||||
gamma = residuals[n/2];
|
||||
else gamma = (residuals[n/2-1] + residuals[n/2]) / 2.0f;
|
||||
delete[] residuals;
|
||||
@@ -748,7 +748,7 @@ float CvGBTrees::find_optimal_value( const CvMat* _Idx )
|
||||
tmp1 += tmp;
|
||||
tmp2 += fabs(tmp)*(1-fabs(tmp));
|
||||
};
|
||||
if (tmp2 == 0)
|
||||
if (tmp2 == 0)
|
||||
{
|
||||
tmp2 = 1;
|
||||
}
|
||||
@@ -818,7 +818,7 @@ void CvGBTrees::do_subsample()
|
||||
//===========================================================================
|
||||
|
||||
float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
CvMat* weak_responses, CvSlice slice, int k) const
|
||||
CvMat* weak_responses, CvSlice slice, int k) const
|
||||
{
|
||||
float result = 0.0f;
|
||||
|
||||
@@ -827,10 +827,10 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
CvSeqReader reader;
|
||||
int weak_count = cvSliceLength( slice, weak[class_count-1] );
|
||||
CvDTree* tree;
|
||||
|
||||
|
||||
if (weak_responses)
|
||||
{
|
||||
if (CV_MAT_TYPE(weak_responses->type) != CV_32F)
|
||||
if (CV_MAT_TYPE(weak_responses->type) != CV_32F)
|
||||
return 0.0f;
|
||||
if ((k >= 0) && (k<class_count) && (weak_responses->rows != 1))
|
||||
return 0.0f;
|
||||
@@ -839,7 +839,7 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
if (weak_responses->cols != weak_count)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
float* sum = new float[class_count];
|
||||
memset(sum, 0, class_count*sizeof(float));
|
||||
|
||||
@@ -847,7 +847,7 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
{
|
||||
if ((weak[i]) && (weak_count))
|
||||
{
|
||||
cvStartReadSeq( weak[i], &reader );
|
||||
cvStartReadSeq( weak[i], &reader );
|
||||
cvSetSeqReaderPos( &reader, slice.start_index );
|
||||
for (int j=0; j<weak_count; ++j)
|
||||
{
|
||||
@@ -859,7 +859,7 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<class_count; ++i)
|
||||
sum[i] += base_value;
|
||||
|
||||
@@ -888,13 +888,13 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
|
||||
delete[] sum;
|
||||
|
||||
/*
|
||||
/*
|
||||
int orig_class_label = -1;
|
||||
for (int i=0; i<get_len(class_labels); ++i)
|
||||
if (class_labels->data.i[i] == class_label+1)
|
||||
orig_class_label = i;
|
||||
*/
|
||||
int orig_class_label = class_labels->data.i[class_label];
|
||||
*/
|
||||
int orig_class_label = class_labels->data.i[class_label];
|
||||
|
||||
return float(orig_class_label);
|
||||
}
|
||||
@@ -903,69 +903,71 @@ float CvGBTrees::predict_serial( const CvMat* _sample, const CvMat* _missing,
|
||||
class Tree_predictor
|
||||
{
|
||||
private:
|
||||
pCvSeq* weak;
|
||||
float* sum;
|
||||
const int k;
|
||||
const CvMat* sample;
|
||||
const CvMat* missing;
|
||||
pCvSeq* weak;
|
||||
float* sum;
|
||||
const int k;
|
||||
const CvMat* sample;
|
||||
const CvMat* missing;
|
||||
const float shrinkage;
|
||||
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
static tbb::spin_mutex SumMutex;
|
||||
#endif
|
||||
|
||||
|
||||
public:
|
||||
Tree_predictor() : weak(0), sum(0), k(0), sample(0), missing(0), shrinkage(1.0f) {}
|
||||
Tree_predictor(pCvSeq* _weak, const int _k, const float _shrinkage,
|
||||
const CvMat* _sample, const CvMat* _missing, float* _sum ) :
|
||||
weak(_weak), sum(_sum), k(_k), sample(_sample),
|
||||
Tree_predictor() : weak(0), sum(0), k(0), sample(0), missing(0), shrinkage(1.0f) {}
|
||||
Tree_predictor(pCvSeq* _weak, const int _k, const float _shrinkage,
|
||||
const CvMat* _sample, const CvMat* _missing, float* _sum ) :
|
||||
weak(_weak), sum(_sum), k(_k), sample(_sample),
|
||||
missing(_missing), shrinkage(_shrinkage)
|
||||
{}
|
||||
|
||||
Tree_predictor( const Tree_predictor& p, cv::Split ) :
|
||||
weak(p.weak), sum(p.sum), k(p.k), sample(p.sample),
|
||||
missing(p.missing), shrinkage(p.shrinkage)
|
||||
{}
|
||||
{}
|
||||
|
||||
Tree_predictor( const Tree_predictor& p, cv::Split ) :
|
||||
weak(p.weak), sum(p.sum), k(p.k), sample(p.sample),
|
||||
missing(p.missing), shrinkage(p.shrinkage)
|
||||
{}
|
||||
|
||||
Tree_predictor& operator=( const Tree_predictor& )
|
||||
{ return *this; }
|
||||
|
||||
Tree_predictor& operator=( const Tree_predictor& )
|
||||
{ return *this; }
|
||||
|
||||
virtual void operator()(const cv::BlockedRange& range) const
|
||||
{
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
tbb::spin_mutex::scoped_lock lock;
|
||||
#endif
|
||||
CvSeqReader reader;
|
||||
int begin = range.begin();
|
||||
int end = range.end();
|
||||
|
||||
int weak_count = end - begin;
|
||||
CvDTree* tree;
|
||||
int begin = range.begin();
|
||||
int end = range.end();
|
||||
|
||||
for (int i=0; i<k; ++i)
|
||||
{
|
||||
float tmp_sum = 0.0f;
|
||||
if ((weak[i]) && (weak_count))
|
||||
{
|
||||
cvStartReadSeq( weak[i], &reader );
|
||||
cvSetSeqReaderPos( &reader, begin );
|
||||
for (int j=0; j<weak_count; ++j)
|
||||
{
|
||||
CV_READ_SEQ_ELEM( tree, reader );
|
||||
tmp_sum += shrinkage*(float)(tree->predict(sample, missing)->value);
|
||||
}
|
||||
}
|
||||
int weak_count = end - begin;
|
||||
CvDTree* tree;
|
||||
|
||||
for (int i=0; i<k; ++i)
|
||||
{
|
||||
float tmp_sum = 0.0f;
|
||||
if ((weak[i]) && (weak_count))
|
||||
{
|
||||
cvStartReadSeq( weak[i], &reader );
|
||||
cvSetSeqReaderPos( &reader, begin );
|
||||
for (int j=0; j<weak_count; ++j)
|
||||
{
|
||||
CV_READ_SEQ_ELEM( tree, reader );
|
||||
tmp_sum += shrinkage*(float)(tree->predict(sample, missing)->value);
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_TBB
|
||||
lock.acquire(SumMutex);
|
||||
sum[i] += tmp_sum;
|
||||
sum[i] += tmp_sum;
|
||||
lock.release();
|
||||
#else
|
||||
sum[i] += tmp_sum;
|
||||
#endif
|
||||
}
|
||||
} // Tree_predictor::operator()
|
||||
|
||||
}
|
||||
} // Tree_predictor::operator()
|
||||
|
||||
virtual ~Tree_predictor() {}
|
||||
|
||||
}; // class Tree_predictor
|
||||
|
||||
|
||||
@@ -976,28 +978,28 @@ tbb::spin_mutex Tree_predictor::SumMutex;
|
||||
|
||||
|
||||
float CvGBTrees::predict( const CvMat* _sample, const CvMat* _missing,
|
||||
CvMat* /*weak_responses*/, CvSlice slice, int k) const
|
||||
CvMat* /*weak_responses*/, CvSlice slice, int k) const
|
||||
{
|
||||
float result = 0.0f;
|
||||
if (!weak) return 0.0f;
|
||||
if (!weak) return 0.0f;
|
||||
float* sum = new float[class_count];
|
||||
for (int i=0; i<class_count; ++i)
|
||||
sum[i] = 0.0f;
|
||||
int begin = slice.start_index;
|
||||
int end = begin + cvSliceLength( slice, weak[0] );
|
||||
|
||||
int begin = slice.start_index;
|
||||
int end = begin + cvSliceLength( slice, weak[0] );
|
||||
|
||||
pCvSeq* weak_seq = weak;
|
||||
Tree_predictor predictor = Tree_predictor(weak_seq, class_count,
|
||||
Tree_predictor predictor = Tree_predictor(weak_seq, class_count,
|
||||
params.shrinkage, _sample, _missing, sum);
|
||||
|
||||
|
||||
//#ifdef HAVE_TBB
|
||||
// tbb::parallel_for(cv::BlockedRange(begin, end), predictor,
|
||||
// tbb::parallel_for(cv::BlockedRange(begin, end), predictor,
|
||||
// tbb::auto_partitioner());
|
||||
//#else
|
||||
cv::parallel_for(cv::BlockedRange(begin, end), predictor);
|
||||
//#endif
|
||||
|
||||
for (int i=0; i<class_count; ++i)
|
||||
for (int i=0; i<class_count; ++i)
|
||||
sum[i] = sum[i] /** params.shrinkage*/ + base_value;
|
||||
|
||||
if (class_count == 1)
|
||||
@@ -1170,7 +1172,7 @@ void CvGBTrees::write( CvFileStorage* fs, const char* name ) const
|
||||
|
||||
void CvGBTrees::read( CvFileStorage* fs, CvFileNode* node )
|
||||
{
|
||||
|
||||
|
||||
CV_FUNCNAME( "CvGBTrees::read" );
|
||||
|
||||
__BEGIN__;
|
||||
@@ -1194,7 +1196,7 @@ void CvGBTrees::read( CvFileStorage* fs, CvFileNode* node )
|
||||
|
||||
|
||||
for (int j=0; j<class_count; ++j)
|
||||
{
|
||||
{
|
||||
s = "trees_";
|
||||
s += ToString(j);
|
||||
|
||||
@@ -1229,39 +1231,39 @@ void CvGBTrees::read( CvFileStorage* fs, CvFileNode* node )
|
||||
class Sample_predictor
|
||||
{
|
||||
private:
|
||||
const CvGBTrees* gbt;
|
||||
float* predictions;
|
||||
const CvMat* samples;
|
||||
const CvMat* missing;
|
||||
const CvGBTrees* gbt;
|
||||
float* predictions;
|
||||
const CvMat* samples;
|
||||
const CvMat* missing;
|
||||
const CvMat* idx;
|
||||
CvSlice slice;
|
||||
|
||||
public:
|
||||
Sample_predictor() : gbt(0), predictions(0), samples(0), missing(0),
|
||||
Sample_predictor() : gbt(0), predictions(0), samples(0), missing(0),
|
||||
idx(0), slice(CV_WHOLE_SEQ)
|
||||
{}
|
||||
|
||||
Sample_predictor(const CvGBTrees* _gbt, float* _predictions,
|
||||
const CvMat* _samples, const CvMat* _missing,
|
||||
Sample_predictor(const CvGBTrees* _gbt, float* _predictions,
|
||||
const CvMat* _samples, const CvMat* _missing,
|
||||
const CvMat* _idx, CvSlice _slice=CV_WHOLE_SEQ) :
|
||||
gbt(_gbt), predictions(_predictions), samples(_samples),
|
||||
gbt(_gbt), predictions(_predictions), samples(_samples),
|
||||
missing(_missing), idx(_idx), slice(_slice)
|
||||
{}
|
||||
|
||||
{}
|
||||
|
||||
|
||||
Sample_predictor( const Sample_predictor& p, cv::Split ) :
|
||||
gbt(p.gbt), predictions(p.predictions),
|
||||
gbt(p.gbt), predictions(p.predictions),
|
||||
samples(p.samples), missing(p.missing), idx(p.idx),
|
||||
slice(p.slice)
|
||||
{}
|
||||
{}
|
||||
|
||||
|
||||
virtual void operator()(const cv::BlockedRange& range) const
|
||||
{
|
||||
int begin = range.begin();
|
||||
int end = range.end();
|
||||
{
|
||||
int begin = range.begin();
|
||||
int end = range.end();
|
||||
|
||||
CvMat x;
|
||||
CvMat x;
|
||||
CvMat miss;
|
||||
|
||||
for (int i=begin; i<end; ++i)
|
||||
@@ -1278,14 +1280,16 @@ public:
|
||||
predictions[i] = gbt->predict_serial(&x,&miss,0,slice);
|
||||
}
|
||||
}
|
||||
} // Sample_predictor::operator()
|
||||
} // Sample_predictor::operator()
|
||||
|
||||
virtual ~Sample_predictor() {}
|
||||
|
||||
}; // class Sample_predictor
|
||||
|
||||
|
||||
|
||||
// type in {CV_TRAIN_ERROR, CV_TEST_ERROR}
|
||||
float
|
||||
float
|
||||
CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
|
||||
{
|
||||
|
||||
@@ -1294,14 +1298,14 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
|
||||
_data->get_train_sample_idx() :
|
||||
_data->get_test_sample_idx();
|
||||
const CvMat* response = _data->get_responses();
|
||||
|
||||
|
||||
int n = sample_idx ? get_len(sample_idx) : 0;
|
||||
n = (type == CV_TRAIN_ERROR && n == 0) ? _data->get_values()->rows : n;
|
||||
|
||||
|
||||
if (!n)
|
||||
return -FLT_MAX;
|
||||
|
||||
float* pred_resp = 0;
|
||||
|
||||
float* pred_resp = 0;
|
||||
if (resp)
|
||||
{
|
||||
resp->resize(n);
|
||||
@@ -1312,17 +1316,17 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
|
||||
|
||||
Sample_predictor predictor = Sample_predictor(this, pred_resp, _data->get_values(),
|
||||
_data->get_missing(), sample_idx);
|
||||
|
||||
|
||||
//#ifdef HAVE_TBB
|
||||
// tbb::parallel_for(cv::BlockedRange(0,n), predictor, tbb::auto_partitioner());
|
||||
//#else
|
||||
cv::parallel_for(cv::BlockedRange(0,n), predictor);
|
||||
//#endif
|
||||
|
||||
|
||||
int* sidx = sample_idx ? sample_idx->data.i : 0;
|
||||
int r_step = CV_IS_MAT_CONT(response->type) ?
|
||||
1 : response->step / CV_ELEM_SIZE(response->type);
|
||||
|
||||
|
||||
|
||||
if ( !problem_type() )
|
||||
{
|
||||
@@ -1342,9 +1346,9 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
|
||||
float d = pred_resp[i] - response->data.fl[si*r_step];
|
||||
err += d*d;
|
||||
}
|
||||
err = err / (float)n;
|
||||
err = err / (float)n;
|
||||
}
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1364,9 +1368,9 @@ CvGBTrees::CvGBTrees( const cv::Mat& trainData, int tflag,
|
||||
class_labels = 0;
|
||||
class_count = 1;
|
||||
delta = 0.0f;
|
||||
|
||||
|
||||
clear();
|
||||
|
||||
|
||||
train(trainData, tflag, responses, varIdx, sampleIdx, varType, missingDataMask, params, false);
|
||||
}
|
||||
|
||||
@@ -1380,7 +1384,7 @@ bool CvGBTrees::train( const cv::Mat& trainData, int tflag,
|
||||
CvMat _trainData = trainData, _responses = responses;
|
||||
CvMat _varIdx = varIdx, _sampleIdx = sampleIdx, _varType = varType;
|
||||
CvMat _missingDataMask = missingDataMask;
|
||||
|
||||
|
||||
return train( &_trainData, tflag, &_responses, varIdx.empty() ? 0 : &_varIdx,
|
||||
sampleIdx.empty() ? 0 : &_sampleIdx, varType.empty() ? 0 : &_varType,
|
||||
missingDataMask.empty() ? 0 : &_missingDataMask, params, update);
|
||||
|
||||
@@ -122,7 +122,7 @@ void CvStatModel::read( CvFileStorage*, CvFileNode* )
|
||||
|
||||
|
||||
/* Calculates upper triangular matrix S, where A is a symmetrical matrix A=S'*S */
|
||||
CV_IMPL void cvChol( CvMat* A, CvMat* S )
|
||||
static void cvChol( CvMat* A, CvMat* S )
|
||||
{
|
||||
int dim = A->rows;
|
||||
|
||||
@@ -182,7 +182,7 @@ CV_IMPL void cvRandMVNormal( CvMat* mean, CvMat* cov, CvMat* sample, CvRNG* rng
|
||||
|
||||
/* Generates <sample> of <amount> points from a discrete variate xi,
|
||||
where Pr{xi = k} == probs[k], 0 < k < len - 1. */
|
||||
CV_IMPL void cvRandSeries( float probs[], int len, int sample[], int amount )
|
||||
static void cvRandSeries( float probs[], int len, int sample[], int amount )
|
||||
{
|
||||
CvMat* univals = cvCreateMat(1, amount, CV_32FC1);
|
||||
float* knots = (float*)cvAlloc( len * sizeof(float) );
|
||||
@@ -321,48 +321,48 @@ CvMat* icvGenerateRandomClusterCenters ( int seed, const CvMat* data,
|
||||
|
||||
#define ICV_RAND_MAX 4294967296 // == 2^32
|
||||
|
||||
CV_IMPL void cvRandRoundUni (CvMat* center,
|
||||
float radius_small,
|
||||
float radius_large,
|
||||
CvMat* desired_matrix,
|
||||
CvRNG* rng_state_ptr)
|
||||
{
|
||||
float rad, norm, coefficient;
|
||||
int dim, size, i, j;
|
||||
CvMat *cov, sample;
|
||||
CvRNG rng_local;
|
||||
// static void cvRandRoundUni (CvMat* center,
|
||||
// float radius_small,
|
||||
// float radius_large,
|
||||
// CvMat* desired_matrix,
|
||||
// CvRNG* rng_state_ptr)
|
||||
// {
|
||||
// float rad, norm, coefficient;
|
||||
// int dim, size, i, j;
|
||||
// CvMat *cov, sample;
|
||||
// CvRNG rng_local;
|
||||
|
||||
CV_FUNCNAME("cvRandRoundUni");
|
||||
__BEGIN__
|
||||
// CV_FUNCNAME("cvRandRoundUni");
|
||||
// __BEGIN__
|
||||
|
||||
rng_local = *rng_state_ptr;
|
||||
// rng_local = *rng_state_ptr;
|
||||
|
||||
CV_ASSERT ((radius_small >= 0) &&
|
||||
(radius_large > 0) &&
|
||||
(radius_small <= radius_large));
|
||||
CV_ASSERT (center && desired_matrix && rng_state_ptr);
|
||||
CV_ASSERT (center->rows == 1);
|
||||
CV_ASSERT (center->cols == desired_matrix->cols);
|
||||
// CV_ASSERT ((radius_small >= 0) &&
|
||||
// (radius_large > 0) &&
|
||||
// (radius_small <= radius_large));
|
||||
// CV_ASSERT (center && desired_matrix && rng_state_ptr);
|
||||
// CV_ASSERT (center->rows == 1);
|
||||
// CV_ASSERT (center->cols == desired_matrix->cols);
|
||||
|
||||
dim = desired_matrix->cols;
|
||||
size = desired_matrix->rows;
|
||||
cov = cvCreateMat (dim, dim, CV_32FC1);
|
||||
cvSetIdentity (cov);
|
||||
cvRandMVNormal (center, cov, desired_matrix, &rng_local);
|
||||
// dim = desired_matrix->cols;
|
||||
// size = desired_matrix->rows;
|
||||
// cov = cvCreateMat (dim, dim, CV_32FC1);
|
||||
// cvSetIdentity (cov);
|
||||
// cvRandMVNormal (center, cov, desired_matrix, &rng_local);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
rad = (float)(cvRandReal(&rng_local)*(radius_large - radius_small) + radius_small);
|
||||
cvGetRow (desired_matrix, &sample, i);
|
||||
norm = (float) cvNorm (&sample, 0, CV_L2);
|
||||
coefficient = rad / norm;
|
||||
for (j = 0; j < dim; j++)
|
||||
CV_MAT_ELEM (sample, float, 0, j) *= coefficient;
|
||||
}
|
||||
// for (i = 0; i < size; i++)
|
||||
// {
|
||||
// rad = (float)(cvRandReal(&rng_local)*(radius_large - radius_small) + radius_small);
|
||||
// cvGetRow (desired_matrix, &sample, i);
|
||||
// norm = (float) cvNorm (&sample, 0, CV_L2);
|
||||
// coefficient = rad / norm;
|
||||
// for (j = 0; j < dim; j++)
|
||||
// CV_MAT_ELEM (sample, float, 0, j) *= coefficient;
|
||||
// }
|
||||
|
||||
__END__
|
||||
// __END__
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
// By S. Dilman - end -
|
||||
|
||||
@@ -1769,7 +1769,7 @@ void cvCombineResponseMaps (CvMat* _responses,
|
||||
}
|
||||
|
||||
|
||||
int icvGetNumberOfCluster( double* prob_vector, int num_of_clusters, float r,
|
||||
static int icvGetNumberOfCluster( double* prob_vector, int num_of_clusters, float r,
|
||||
float outlier_thresh, int normalize_probs )
|
||||
{
|
||||
int max_prob_loc = 0;
|
||||
|
||||
@@ -41,11 +41,11 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4514 4710 4711 4710 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
@@ -298,10 +298,10 @@ cvPrepareTrainData( const char* /*funcname*/,
|
||||
CvMat** out_sample_idx=0 );
|
||||
|
||||
void
|
||||
cvSortSamplesByClasses( const float** samples, const CvMat* classes,
|
||||
cvSortSamplesByClasses( const float** samples, const CvMat* classes,
|
||||
int* class_ranges, const uchar** mask CV_DEFAULT(0) );
|
||||
|
||||
void
|
||||
void
|
||||
cvCombineResponseMaps (CvMat* _responses,
|
||||
const CvMat* old_response_map,
|
||||
CvMat* new_response_map,
|
||||
@@ -329,7 +329,7 @@ CvFileNode* icvFileNodeGetNext(CvFileNode* n, const char* name);
|
||||
|
||||
|
||||
void cvCheckTrainData( const CvMat* train_data, int tflag,
|
||||
const CvMat* missing_mask,
|
||||
const CvMat* missing_mask,
|
||||
int* var_all, int* sample_all );
|
||||
|
||||
CvMat* cvPreprocessIndexArray( const CvMat* idx_arr, int data_arr_size, bool check_for_duplicates=false );
|
||||
@@ -365,7 +365,7 @@ namespace cv
|
||||
CvDTree* tree;
|
||||
CvDTreeNode* node;
|
||||
};
|
||||
|
||||
|
||||
struct ForestTreeBestSplitFinder : DTreeBestSplitFinder
|
||||
{
|
||||
ForestTreeBestSplitFinder() : DTreeBestSplitFinder() {}
|
||||
|
||||
+23
-23
@@ -88,7 +88,7 @@ using namespace cv;
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4514 ) /* unreferenced inline functions */
|
||||
#endif
|
||||
|
||||
@@ -1593,7 +1593,7 @@ bool CvSVM::train( const CvMat* _train_data, const CvMat* _responses,
|
||||
return ok;
|
||||
}
|
||||
|
||||
struct indexedratio
|
||||
struct indexedratio
|
||||
{
|
||||
double val;
|
||||
int ind;
|
||||
@@ -1774,7 +1774,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
|
||||
else
|
||||
CV_SWAP( responses->data.i[i1], responses->data.i[i2], y );
|
||||
}
|
||||
|
||||
|
||||
if (!is_regression && class_labels->cols==2 && balanced)
|
||||
{
|
||||
// count class samples
|
||||
@@ -1786,13 +1786,13 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
|
||||
else
|
||||
++num_1;
|
||||
}
|
||||
|
||||
|
||||
int label_smallest_class;
|
||||
int label_biggest_class;
|
||||
if (num_0 < num_1)
|
||||
{
|
||||
label_biggest_class = class_labels->data.i[1];
|
||||
label_smallest_class = class_labels->data.i[0];
|
||||
label_smallest_class = class_labels->data.i[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2001,7 +2001,7 @@ float CvSVM::predict( const float* row_sample, int row_len, bool returnDFVal ) c
|
||||
|
||||
int var_count = get_var_count();
|
||||
assert( row_len == var_count );
|
||||
(void)row_len;
|
||||
(void)row_len;
|
||||
|
||||
int class_count = class_labels ? class_labels->cols :
|
||||
params.svm_type == ONE_CLASS ? 1 : 0;
|
||||
@@ -2072,7 +2072,7 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const
|
||||
__BEGIN__;
|
||||
|
||||
int class_count;
|
||||
|
||||
|
||||
if( !kernel )
|
||||
CV_ERROR( CV_StsBadArg, "The SVM should be trained first" );
|
||||
|
||||
@@ -2082,7 +2082,7 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const
|
||||
CV_CALL( cvPreparePredictData( sample, var_all, var_idx,
|
||||
class_count, 0, &row_sample ));
|
||||
result = predict( row_sample, get_var_count(), returnDFVal );
|
||||
|
||||
|
||||
__END__;
|
||||
|
||||
if( sample && (!CV_IS_MAT(sample) || sample->data.fl != row_sample) )
|
||||
@@ -2099,12 +2099,12 @@ struct predict_body_svm {
|
||||
samples = _samples;
|
||||
results = _results;
|
||||
}
|
||||
|
||||
|
||||
const CvSVM* pointer;
|
||||
float* result;
|
||||
const CvMat* samples;
|
||||
CvMat* results;
|
||||
|
||||
|
||||
void operator()( const cv::BlockedRange& range ) const
|
||||
{
|
||||
for(int i = range.begin(); i < range.end(); i++ )
|
||||
@@ -2116,15 +2116,15 @@ struct predict_body_svm {
|
||||
results->data.fl[i] = (float)r;
|
||||
if (i == 0)
|
||||
*result = (float)r;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
float CvSVM::predict(const CvMat* samples, CV_OUT CvMat* results) const
|
||||
{
|
||||
float result = 0;
|
||||
cv::parallel_for(cv::BlockedRange(0, samples->rows),
|
||||
predict_body_svm(this, &result, samples, results)
|
||||
cv::parallel_for(cv::BlockedRange(0, samples->rows),
|
||||
predict_body_svm(this, &result, samples, results)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@@ -2141,7 +2141,7 @@ CvSVM::CvSVM( const Mat& _train_data, const Mat& _responses,
|
||||
kernel = 0;
|
||||
solver = 0;
|
||||
default_model_name = "my_svm";
|
||||
|
||||
|
||||
train( _train_data, _responses, _var_idx, _sample_idx, _params );
|
||||
}
|
||||
|
||||
@@ -2166,7 +2166,7 @@ bool CvSVM::train_auto( const Mat& _train_data, const Mat& _responses,
|
||||
|
||||
float CvSVM::predict( const Mat& _sample, bool returnDFVal ) const
|
||||
{
|
||||
CvMat sample = _sample;
|
||||
CvMat sample = _sample;
|
||||
return predict(&sample, returnDFVal);
|
||||
}
|
||||
|
||||
@@ -2648,11 +2648,11 @@ cvTrainSVM_CrossValidation( const CvMat* train_data, int tflag,
|
||||
__BEGIN__;
|
||||
|
||||
double degree_step = 7,
|
||||
g_step = 15,
|
||||
coef_step = 14,
|
||||
C_step = 20,
|
||||
nu_step = 5,
|
||||
p_step = 7; // all steps must be > 1
|
||||
g_step = 15,
|
||||
coef_step = 14,
|
||||
C_step = 20,
|
||||
nu_step = 5,
|
||||
p_step = 7; // all steps must be > 1
|
||||
double degree_begin = 0.01, degree_end = 2;
|
||||
double g_begin = 1e-5, g_end = 0.5;
|
||||
double coef_begin = 0.1, coef_end = 300;
|
||||
@@ -2662,12 +2662,12 @@ cvTrainSVM_CrossValidation( const CvMat* train_data, int tflag,
|
||||
|
||||
double rate = 0, gamma = 0, C = 0, degree = 0, coef = 0, p = 0, nu = 0;
|
||||
|
||||
double best_rate = 0;
|
||||
double best_rate = 0;
|
||||
double best_degree = degree_begin;
|
||||
double best_gamma = g_begin;
|
||||
double best_coef = coef_begin;
|
||||
double best_C = C_begin;
|
||||
double best_nu = nu_begin;
|
||||
double best_C = C_begin;
|
||||
double best_nu = nu_begin;
|
||||
double best_p = p_begin;
|
||||
|
||||
CvSVMModelParams svm_params, *psvm_params;
|
||||
|
||||
@@ -46,7 +46,7 @@ typedef struct CvDI
|
||||
int i;
|
||||
} CvDI;
|
||||
|
||||
int CV_CDECL
|
||||
static int CV_CDECL
|
||||
icvCmpDI( const void* a, const void* b, void* )
|
||||
{
|
||||
const CvDI* e1 = (const CvDI*) a;
|
||||
@@ -65,7 +65,7 @@ cvCreateTestSet( int type, CvMat** samples,
|
||||
CvMat* mean = NULL;
|
||||
CvMat* cov = NULL;
|
||||
CvMemStorage* storage = NULL;
|
||||
|
||||
|
||||
CV_FUNCNAME( "cvCreateTestSet" );
|
||||
|
||||
__BEGIN__;
|
||||
@@ -125,7 +125,7 @@ cvCreateTestSet( int type, CvMat** samples,
|
||||
CV_WRITE_SEQ_ELEM( elem, writer );
|
||||
}
|
||||
CV_CALL( seq = cvEndWriteSeq( &writer ) );
|
||||
|
||||
|
||||
/* sort the sequence in a distance ascending order */
|
||||
CV_CALL( cvSeqSort( seq, icvCmpDI, NULL ) );
|
||||
|
||||
@@ -137,7 +137,7 @@ cvCreateTestSet( int type, CvMat** samples,
|
||||
{
|
||||
int last_idx;
|
||||
double max_dst;
|
||||
|
||||
|
||||
last_idx = num_samples * (cur_class + 1) / num_classes - 1;
|
||||
CV_CALL( max_dst = (*((CvDI*) cvGetSeqElem( seq, last_idx ))).d );
|
||||
max_dst = MAX( max_dst, elem.d );
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "opencv2/nonfree/nonfree.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4512 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
* 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.
|
||||
* The name of Contributor may not be used to endorse or
|
||||
* promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
* 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.
|
||||
* The name of Contributor 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,
|
||||
@@ -43,7 +43,7 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
The following changes have been made, comparing to the original contribution:
|
||||
1. A lot of small optimizations, less memory allocations, got rid of global buffers
|
||||
2. Reversed order of cvGetQuadrangleSubPix and cvResize calls; probably less accurate, but much faster
|
||||
@@ -79,8 +79,8 @@ octave.
|
||||
The extraction of the patch of pixels surrounding a keypoint used to build a
|
||||
descriptor has been simplified.
|
||||
|
||||
KeyPoint descriptor normalisation has been changed from normalising each 4x4
|
||||
cell (resulting in a descriptor of magnitude 16) to normalising the entire
|
||||
KeyPoint descriptor normalisation has been changed from normalising each 4x4
|
||||
cell (resulting in a descriptor of magnitude 16) to normalising the entire
|
||||
descriptor to magnitude 1.
|
||||
|
||||
The default number of octaves has been increased from 3 to 4 to match the
|
||||
@@ -88,20 +88,20 @@ original SURF binary default. The increase in computation time is minimal since
|
||||
the higher octaves are sampled sparsely.
|
||||
|
||||
The default number of layers per octave has been reduced from 3 to 2, to prevent
|
||||
redundant calculation of similar sizes in consecutive octaves. This decreases
|
||||
computation time. The number of features extracted may be less, however the
|
||||
redundant calculation of similar sizes in consecutive octaves. This decreases
|
||||
computation time. The number of features extracted may be less, however the
|
||||
additional features were mostly redundant.
|
||||
|
||||
The radius of the circle of gradient samples used to assign an orientation has
|
||||
been increased from 4 to 6 to match the description in the SURF paper. This is
|
||||
been increased from 4 to 6 to match the description in the SURF paper. This is
|
||||
now defined by ORI_RADIUS, and could be made into a parameter.
|
||||
|
||||
The size of the sliding window used in orientation assignment has been reduced
|
||||
from 120 to 60 degrees to match the description in the SURF paper. This is now
|
||||
defined by ORI_WIN, and could be made into a parameter.
|
||||
|
||||
Other options like HAAR_SIZE0, HAAR_SIZE_INC, SAMPLE_STEP0, ORI_SEARCH_INC,
|
||||
ORI_SIGMA and DESC_SIGMA have been separated from the code and documented.
|
||||
Other options like HAAR_SIZE0, HAAR_SIZE_INC, SAMPLE_STEP0, ORI_SEARCH_INC,
|
||||
ORI_SIGMA and DESC_SIGMA have been separated from the code and documented.
|
||||
These could also be made into parameters.
|
||||
|
||||
Modifications by Ian Mahon
|
||||
@@ -124,12 +124,14 @@ static const int SURF_HAAR_SIZE0 = 9;
|
||||
// This ensures that when looking for the neighbours of a sample, the layers
|
||||
// above and below are aligned correctly.
|
||||
static const int SURF_HAAR_SIZE_INC = 6;
|
||||
|
||||
|
||||
|
||||
|
||||
struct SurfHF
|
||||
{
|
||||
int p0, p1, p2, p3;
|
||||
float w;
|
||||
|
||||
SurfHF(): p0(0), p1(0), p2(0), p3(0), w(0) {}
|
||||
};
|
||||
|
||||
inline float calcHaarPattern( const int* origin, const SurfHF* f, int n )
|
||||
@@ -208,10 +210,10 @@ static void calcLayerDetAndTrace( const Mat& sum, int size, int sampleStep,
|
||||
* Maxima location interpolation as described in "Invariant Features from
|
||||
* Interest Point Groups" by Matthew Brown and David Lowe. This is performed by
|
||||
* fitting a 3D quadratic to a set of neighbouring samples.
|
||||
*
|
||||
* The gradient vector and Hessian matrix at the initial keypoint location are
|
||||
*
|
||||
* The gradient vector and Hessian matrix at the initial keypoint location are
|
||||
* approximated using central differences. The linear system Ax = b is then
|
||||
* solved, where A is the Hessian, b is the negative gradient, and x is the
|
||||
* solved, where A is the Hessian, b is the negative gradient, and x is the
|
||||
* offset of the interpolated maxima coordinates from the initial estimate.
|
||||
* This is equivalent to an iteration of Netwon's optimisation algorithm.
|
||||
*
|
||||
@@ -234,18 +236,18 @@ interpolateKeypoint( float N9[3][9], int dx, int dy, int ds, KeyPoint& kpt )
|
||||
N9[1][3]-2*N9[1][4]+N9[1][5], // 2nd deriv x, x
|
||||
(N9[1][8]-N9[1][6]-N9[1][2]+N9[1][0])/4, // 2nd deriv x, y
|
||||
(N9[2][5]-N9[2][3]-N9[0][5]+N9[0][3])/4, // 2nd deriv x, s
|
||||
(N9[1][8]-N9[1][6]-N9[1][2]+N9[1][0])/4, // 2nd deriv x, y
|
||||
N9[1][1]-2*N9[1][4]+N9[1][7], // 2nd deriv y, y
|
||||
(N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s
|
||||
(N9[1][8]-N9[1][6]-N9[1][2]+N9[1][0])/4, // 2nd deriv x, y
|
||||
N9[1][1]-2*N9[1][4]+N9[1][7], // 2nd deriv y, y
|
||||
(N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s
|
||||
(N9[2][5]-N9[2][3]-N9[0][5]+N9[0][3])/4, // 2nd deriv x, s
|
||||
(N9[2][7]-N9[2][1]-N9[0][7]+N9[0][1])/4, // 2nd deriv y, s
|
||||
N9[0][4]-2*N9[1][4]+N9[2][4]); // 2nd deriv s, s
|
||||
|
||||
Vec3f x = A.solve(b, DECOMP_LU);
|
||||
|
||||
|
||||
bool ok = (x[0] != 0 || x[1] != 0 || x[2] != 0) &&
|
||||
std::abs(x[0]) <= 1 && std::abs(x[1]) <= 1 && std::abs(x[2]) <= 1;
|
||||
|
||||
|
||||
if( ok )
|
||||
{
|
||||
kpt.pt.x += x[0]*dx;
|
||||
@@ -425,7 +427,7 @@ struct SURFFindInvoker
|
||||
{
|
||||
int layer = (*middleIndices)[i];
|
||||
int octave = i / nOctaveLayers;
|
||||
findMaximaInLayer( *sum, *mask_sum, *dets, *traces, *sizes,
|
||||
findMaximaInLayer( *sum, *mask_sum, *dets, *traces, *sizes,
|
||||
*keypoints, octave, layer, hessianThreshold,
|
||||
(*sampleSteps)[layer] );
|
||||
}
|
||||
@@ -459,7 +461,7 @@ struct KeypointGreater
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void fastHessianDetector( const Mat& sum, const Mat& mask_sum, vector<KeyPoint>& keypoints,
|
||||
int nOctaves, int nOctaveLayers, float hessianThreshold )
|
||||
{
|
||||
@@ -479,7 +481,7 @@ static void fastHessianDetector( const Mat& sum, const Mat& mask_sum, vector<Key
|
||||
|
||||
// Allocate space and calculate properties of each layer
|
||||
int index = 0, middleIndex = 0, step = SAMPLE_STEP0;
|
||||
|
||||
|
||||
for( int octave = 0; octave < nOctaves; octave++ )
|
||||
{
|
||||
for( int layer = 0; layer < nOctaveLayers+2; layer++ )
|
||||
@@ -566,7 +568,7 @@ struct SURFInvoker
|
||||
const int dx_s[NX][5] = {{0, 0, 2, 4, -1}, {2, 0, 4, 4, 1}};
|
||||
const int dy_s[NY][5] = {{0, 0, 4, 2, 1}, {0, 2, 4, 4, -1}};
|
||||
|
||||
// Optimisation is better using nOriSampleBound than nOriSamples for
|
||||
// Optimisation is better using nOriSampleBound than nOriSamples for
|
||||
// array lengths. Maybe because it is a constant known at compile time
|
||||
const int nOriSampleBound =(2*ORI_RADIUS+1)*(2*ORI_RADIUS+1);
|
||||
|
||||
@@ -579,7 +581,7 @@ struct SURFInvoker
|
||||
Mat _patch(PATCH_SZ+1, PATCH_SZ+1, CV_8U, PATCH);
|
||||
|
||||
int dsize = extended ? 128 : 64;
|
||||
|
||||
|
||||
int k, k1 = range.begin(), k2 = range.end();
|
||||
float maxSize = 0;
|
||||
for( k = k1; k < k2; k++ )
|
||||
@@ -601,7 +603,7 @@ struct SURFInvoker
|
||||
float s = size*1.2f/9.0f;
|
||||
/* To find the dominant orientation, the gradients in x and y are
|
||||
sampled in a circle of radius 6s using wavelets of size 4s.
|
||||
We ensure the gradient wavelet size is even to ensure the
|
||||
We ensure the gradient wavelet size is even to ensure the
|
||||
wavelet pattern is balanced and symmetric around its center */
|
||||
int grad_wav_size = 2*cvRound( 2*s );
|
||||
if( sum->rows < grad_wav_size || sum->cols < grad_wav_size )
|
||||
@@ -670,7 +672,7 @@ struct SURFInvoker
|
||||
kp.angle = descriptor_dir;
|
||||
if( !descriptors || !descriptors->data )
|
||||
continue;
|
||||
|
||||
|
||||
/* Extract a window of pixels around the keypoint of size 20s */
|
||||
int win_size = (int)((PATCH_SZ+1)*s);
|
||||
CV_Assert( winbuf->cols >= win_size*win_size );
|
||||
@@ -678,13 +680,13 @@ struct SURFInvoker
|
||||
|
||||
if( !upright )
|
||||
{
|
||||
descriptor_dir *= (float)(CV_PI/180);
|
||||
descriptor_dir *= (float)(CV_PI/180);
|
||||
float sin_dir = std::sin(descriptor_dir);
|
||||
float cos_dir = std::cos(descriptor_dir);
|
||||
|
||||
/* Subpixel interpolation version (slower). Subpixel not required since
|
||||
the pixels will all get averaged when we scale down to 20 pixels */
|
||||
/*
|
||||
/*
|
||||
float w[] = { cos_dir, sin_dir, center.x,
|
||||
-sin_dir, cos_dir , center.y };
|
||||
CvMat W = cvMat(2, 3, CV_32F, w);
|
||||
@@ -711,12 +713,12 @@ struct SURFInvoker
|
||||
else
|
||||
{
|
||||
// extract rect - slightly optimized version of the code above
|
||||
// TODO: find faster code, as this is simply an extract rect operation,
|
||||
// TODO: find faster code, as this is simply an extract rect operation,
|
||||
// e.g. by using cvGetSubRect, problem is the border processing
|
||||
// descriptor_dir == 90 grad
|
||||
// sin_dir == 1
|
||||
// cos_dir == 0
|
||||
|
||||
|
||||
float win_offset = -(float)(win_size-1)/2;
|
||||
int start_x = cvRound(center.x + win_offset);
|
||||
int start_y = cvRound(center.y - win_offset);
|
||||
@@ -733,7 +735,7 @@ struct SURFInvoker
|
||||
y = MIN( y, img->rows-1 );
|
||||
WIN[i*win_size + j] = img->at<uchar>(y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Scale the window to size PATCH_SZ so each pixel's size is s. This
|
||||
// makes calculating the gradients with wavelets of size 2s easy
|
||||
@@ -860,7 +862,7 @@ void SURF::operator()(InputArray imgarg, InputArray maskarg,
|
||||
{
|
||||
(*this)(imgarg, maskarg, keypoints, noArray(), false);
|
||||
}
|
||||
|
||||
|
||||
void SURF::operator()(InputArray _img, InputArray _mask,
|
||||
CV_OUT vector<KeyPoint>& keypoints,
|
||||
OutputArray _descriptors,
|
||||
@@ -868,18 +870,18 @@ void SURF::operator()(InputArray _img, InputArray _mask,
|
||||
{
|
||||
Mat img = _img.getMat(), mask = _mask.getMat(), mask1, sum, msum;
|
||||
bool doDescriptors = _descriptors.needed();
|
||||
|
||||
|
||||
CV_Assert(!img.empty() && img.depth() == CV_8U);
|
||||
if( img.channels() > 1 )
|
||||
cvtColor(img, img, COLOR_BGR2GRAY);
|
||||
|
||||
|
||||
CV_Assert(mask.empty() || (mask.type() == CV_8U && mask.size() == img.size()));
|
||||
CV_Assert(hessianThreshold >= 0);
|
||||
CV_Assert(nOctaves > 0);
|
||||
CV_Assert(nOctaveLayers > 0);
|
||||
|
||||
|
||||
integral(img, sum, CV_32S);
|
||||
|
||||
|
||||
// Compute keypoints only if we are not asked for evaluating the descriptors are some given locations:
|
||||
if( !useProvidedKeypoints )
|
||||
{
|
||||
@@ -890,7 +892,7 @@ void SURF::operator()(InputArray _img, InputArray _mask,
|
||||
}
|
||||
fastHessianDetector( sum, msum, keypoints, nOctaves, nOctaveLayers, (float)hessianThreshold );
|
||||
}
|
||||
|
||||
|
||||
int i, j, N = (int)keypoints.size();
|
||||
if( N > 0 )
|
||||
{
|
||||
@@ -898,7 +900,7 @@ void SURF::operator()(InputArray _img, InputArray _mask,
|
||||
bool _1d = false;
|
||||
int dcols = extended ? 128 : 64;
|
||||
size_t dsize = dcols*sizeof(float);
|
||||
|
||||
|
||||
if( doDescriptors )
|
||||
{
|
||||
_1d = _descriptors.kind() == _InputArray::STD_VECTOR && _descriptors.type() == CV_32F;
|
||||
@@ -913,11 +915,11 @@ void SURF::operator()(InputArray _img, InputArray _mask,
|
||||
descriptors = _descriptors.getMat();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// we call SURFInvoker in any case, even if we do not need descriptors,
|
||||
// since it computes orientation of each feature.
|
||||
parallel_for(BlockedRange(0, N), SURFInvoker(img, sum, keypoints, descriptors, extended, upright) );
|
||||
|
||||
|
||||
// remove keypoints that were marked for deletion
|
||||
for( i = j = 0; i < N; i++ )
|
||||
{
|
||||
@@ -951,7 +953,7 @@ void SURF::operator()(InputArray _img, InputArray _mask,
|
||||
void SURF::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask) const
|
||||
{
|
||||
(*this)(image, mask, keypoints, noArray(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void SURF::computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors) const
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user