|
|
|
@ -234,17 +234,20 @@ inline float32x4_t vsetq_f32(float f0, float f1, float f2, float f3) |
|
|
|
|
return a; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, |
|
|
|
|
void HOGDescriptor::computeGradient(InputArray _img, InputOutputArray _grad, InputOutputArray _qangle, |
|
|
|
|
Size paddingTL, Size paddingBR) const |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION(); |
|
|
|
|
|
|
|
|
|
Mat img = _img.getMat(); |
|
|
|
|
CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 ); |
|
|
|
|
|
|
|
|
|
Size gradsize(img.cols + paddingTL.width + paddingBR.width, |
|
|
|
|
img.rows + paddingTL.height + paddingBR.height); |
|
|
|
|
grad.create(gradsize, CV_32FC2); // <magnitude*(1-alpha), magnitude*alpha>
|
|
|
|
|
qangle.create(gradsize, CV_8UC2); // [0..nbins-1] - quantized gradient orientation
|
|
|
|
|
_grad.create(gradsize, CV_32FC2); // <magnitude*(1-alpha), magnitude*alpha>
|
|
|
|
|
_qangle.create(gradsize, CV_8UC2); // [0..nbins-1] - quantized gradient orientation
|
|
|
|
|
Mat grad = _grad.getMat(); |
|
|
|
|
Mat qangle = _qangle.getMat(); |
|
|
|
|
|
|
|
|
|
Size wholeSize; |
|
|
|
|
Point roiofs; |
|
|
|
@ -1650,12 +1653,13 @@ void HOGDescriptor::compute(InputArray _img, std::vector<float>& descriptors, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HOGDescriptor::detect(const Mat& img, |
|
|
|
|
void HOGDescriptor::detect(InputArray _img, |
|
|
|
|
std::vector<Point>& hits, std::vector<double>& weights, double hitThreshold, |
|
|
|
|
Size winStride, Size padding, const std::vector<Point>& locations) const |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION(); |
|
|
|
|
|
|
|
|
|
Mat img = _img.getMat(); |
|
|
|
|
hits.clear(); |
|
|
|
|
weights.clear(); |
|
|
|
|
if( svmDetector.empty() ) |
|
|
|
@ -1764,7 +1768,7 @@ void HOGDescriptor::detect(const Mat& img, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HOGDescriptor::detect(const Mat& img, std::vector<Point>& hits, double hitThreshold, |
|
|
|
|
void HOGDescriptor::detect(InputArray img, std::vector<Point>& hits, double hitThreshold, |
|
|
|
|
Size winStride, Size padding, const std::vector<Point>& locations) const |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION(); |
|
|
|
@ -3544,12 +3548,13 @@ public: |
|
|
|
|
Mutex* mtx; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void HOGDescriptor::detectROI(const cv::Mat& img, const std::vector<cv::Point> &locations, |
|
|
|
|
void HOGDescriptor::detectROI(InputArray _img, const std::vector<cv::Point> &locations, |
|
|
|
|
CV_OUT std::vector<cv::Point>& foundLocations, CV_OUT std::vector<double>& confidences, |
|
|
|
|
double hitThreshold, cv::Size winStride, cv::Size padding) const |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION(); |
|
|
|
|
|
|
|
|
|
Mat img = _img.getMat(); |
|
|
|
|
foundLocations.clear(); |
|
|
|
|
confidences.clear(); |
|
|
|
|
|
|
|
|
@ -3656,12 +3661,13 @@ void HOGDescriptor::detectROI(const cv::Mat& img, const std::vector<cv::Point> & |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HOGDescriptor::detectMultiScaleROI(const cv::Mat& img, |
|
|
|
|
void HOGDescriptor::detectMultiScaleROI(InputArray _img, |
|
|
|
|
CV_OUT std::vector<cv::Rect>& foundLocations, std::vector<DetectionROI>& locations, |
|
|
|
|
double hitThreshold, int groupThreshold) const |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION(); |
|
|
|
|
|
|
|
|
|
Mat img = _img.getMat(); |
|
|
|
|
std::vector<Rect> allCandidates; |
|
|
|
|
Mutex mtx; |
|
|
|
|
|
|
|
|
@ -3674,110 +3680,6 @@ void HOGDescriptor::detectMultiScaleROI(const cv::Mat& img, |
|
|
|
|
cv::groupRectangles(foundLocations, groupThreshold, 0.2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HOGDescriptor::readALTModel(String modelfile) |
|
|
|
|
{ |
|
|
|
|
// read model from SVMlight format..
|
|
|
|
|
FILE *modelfl; |
|
|
|
|
if ((modelfl = fopen(modelfile.c_str(), "rb")) == NULL) |
|
|
|
|
{ |
|
|
|
|
String eerr("file not exist"); |
|
|
|
|
String efile(__FILE__); |
|
|
|
|
String efunc(__FUNCTION__); |
|
|
|
|
CV_THROW (Exception(Error::StsError, eerr, efile, efunc, __LINE__)); |
|
|
|
|
} |
|
|
|
|
char version_buffer[10]; |
|
|
|
|
if (!fread (&version_buffer,sizeof(char),10,modelfl)) |
|
|
|
|
{ |
|
|
|
|
String eerr("version?"); |
|
|
|
|
String efile(__FILE__); |
|
|
|
|
String efunc(__FUNCTION__); |
|
|
|
|
fclose(modelfl); |
|
|
|
|
|
|
|
|
|
CV_THROW (Exception(Error::StsError, eerr, efile, efunc, __LINE__)); |
|
|
|
|
} |
|
|
|
|
if(strcmp(version_buffer,"V6.01")) { |
|
|
|
|
String eerr("version does not match"); |
|
|
|
|
String efile(__FILE__); |
|
|
|
|
String efunc(__FUNCTION__); |
|
|
|
|
fclose(modelfl); |
|
|
|
|
|
|
|
|
|
CV_THROW (Exception(Error::StsError, eerr, efile, efunc, __LINE__)); |
|
|
|
|
} |
|
|
|
|
/* read version number */ |
|
|
|
|
int version = 0; |
|
|
|
|
if (!fread (&version,sizeof(int),1,modelfl)) |
|
|
|
|
{ |
|
|
|
|
fclose(modelfl); |
|
|
|
|
CV_THROW (Exception()); |
|
|
|
|
} |
|
|
|
|
if (version < 200) |
|
|
|
|
{ |
|
|
|
|
String eerr("version does not match"); |
|
|
|
|
String efile(__FILE__); |
|
|
|
|
String efunc(__FUNCTION__); |
|
|
|
|
fclose(modelfl); |
|
|
|
|
CV_THROW (Exception()); |
|
|
|
|
} |
|
|
|
|
int kernel_type; |
|
|
|
|
size_t nread; |
|
|
|
|
nread=fread(&(kernel_type),sizeof(int),1,modelfl); |
|
|
|
|
|
|
|
|
|
{// ignore these
|
|
|
|
|
int poly_degree; |
|
|
|
|
nread=fread(&(poly_degree),sizeof(int),1,modelfl); |
|
|
|
|
|
|
|
|
|
double rbf_gamma; |
|
|
|
|
nread=fread(&(rbf_gamma),sizeof(double), 1, modelfl); |
|
|
|
|
double coef_lin; |
|
|
|
|
nread=fread(&(coef_lin),sizeof(double),1,modelfl); |
|
|
|
|
double coef_const; |
|
|
|
|
nread=fread(&(coef_const),sizeof(double),1,modelfl); |
|
|
|
|
int l; |
|
|
|
|
nread=fread(&l,sizeof(int),1,modelfl); |
|
|
|
|
CV_Assert(l >= 0 && l < 0xFFFF); |
|
|
|
|
char* custom = new char[l]; |
|
|
|
|
nread=fread(custom,sizeof(char),l,modelfl); |
|
|
|
|
delete[] custom; |
|
|
|
|
} |
|
|
|
|
int totwords; |
|
|
|
|
nread=fread(&(totwords),sizeof(int),1,modelfl); |
|
|
|
|
{// ignore these
|
|
|
|
|
int totdoc; |
|
|
|
|
nread=fread(&(totdoc),sizeof(int),1,modelfl); |
|
|
|
|
int sv_num; |
|
|
|
|
nread=fread(&(sv_num), sizeof(int),1,modelfl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double linearbias; |
|
|
|
|
nread=fread(&linearbias, sizeof(double), 1, modelfl); |
|
|
|
|
|
|
|
|
|
std::vector<float> detector; |
|
|
|
|
detector.clear(); |
|
|
|
|
if(kernel_type == 0) { /* linear kernel */ |
|
|
|
|
/* save linear wts also */ |
|
|
|
|
CV_Assert(totwords + 1 > 0 && totwords < 0xFFFF); |
|
|
|
|
double *linearwt = new double[totwords+1]; |
|
|
|
|
int length = totwords; |
|
|
|
|
nread = fread(linearwt, sizeof(double), totwords + 1, modelfl); |
|
|
|
|
if(nread != static_cast<size_t>(length) + 1) { |
|
|
|
|
delete [] linearwt; |
|
|
|
|
fclose(modelfl); |
|
|
|
|
CV_THROW (Exception()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(int i = 0; i < length; i++) |
|
|
|
|
detector.push_back((float)linearwt[i]); |
|
|
|
|
|
|
|
|
|
detector.push_back((float)-linearbias); |
|
|
|
|
setSVMDetector(detector); |
|
|
|
|
delete [] linearwt; |
|
|
|
|
} else { |
|
|
|
|
fclose(modelfl); |
|
|
|
|
CV_THROW (Exception()); |
|
|
|
|
} |
|
|
|
|
fclose(modelfl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HOGDescriptor::groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const |
|
|
|
|
{ |
|
|
|
|
CV_INSTRUMENT_REGION(); |
|
|
|
|