mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
fixed compile errors on VS2008
This commit is contained in:
parent
2122cde787
commit
74300f5f42
@ -628,12 +628,12 @@ class CV_EXPORTS RandomizedTree
|
||||
public:
|
||||
friend class RTreeClassifier;
|
||||
|
||||
static const int PATCH_SIZE = 32;
|
||||
static const uchar PATCH_SIZE = 32;
|
||||
static const int DEFAULT_DEPTH = 9;
|
||||
static const int DEFAULT_VIEWS = 5000;
|
||||
static const size_t DEFAULT_REDUCED_NUM_DIM = 176;
|
||||
static const float LOWER_QUANT_PERC = .03f;
|
||||
static const float UPPER_QUANT_PERC = .92f;
|
||||
static float GET_LOWER_QUANT_PERC() { return .03f; }
|
||||
static float GET_UPPER_QUANT_PERC() { return .92f; }
|
||||
|
||||
RandomizedTree();
|
||||
~RandomizedTree();
|
||||
@ -646,13 +646,13 @@ public:
|
||||
|
||||
// following two funcs are EXPERIMENTAL (do not use unless you know exactly what you do)
|
||||
static void quantizeVector(float *vec, int dim, int N, float bnds[2], int clamp_mode=0);
|
||||
static void quantizeVector(float *src, int dim, int N, float bnds[2], uint8_t *dst);
|
||||
static void quantizeVector(float *src, int dim, int N, float bnds[2], uchar *dst);
|
||||
|
||||
// patch_data must be a 32x32 array (no row padding)
|
||||
float* getPosterior(uchar* patch_data);
|
||||
const float* getPosterior(uchar* patch_data) const;
|
||||
uint8_t* getPosterior2(uchar* patch_data);
|
||||
const uint8_t* getPosterior2(uchar* patch_data) const;
|
||||
uchar* getPosterior2(uchar* patch_data);
|
||||
const uchar* getPosterior2(uchar* patch_data) const;
|
||||
|
||||
void read(const char* file_name, int num_quant_bits);
|
||||
void read(std::istream &is, int num_quant_bits);
|
||||
@ -677,7 +677,7 @@ private:
|
||||
int num_leaves_;
|
||||
std::vector<RTreeNode> nodes_;
|
||||
float **posteriors_; // 16-bytes aligned posteriors
|
||||
uint8_t **posteriors2_; // 16-bytes aligned posteriors
|
||||
uchar **posteriors2_; // 16-bytes aligned posteriors
|
||||
std::vector<int> leaf_counts_;
|
||||
|
||||
void createNodes(int num_nodes, RNG &rng);
|
||||
@ -689,8 +689,8 @@ private:
|
||||
int getIndex(uchar* patch_data) const;
|
||||
inline float* getPosteriorByIndex(int index);
|
||||
inline const float* getPosteriorByIndex(int index) const;
|
||||
inline uint8_t* getPosteriorByIndex2(int index);
|
||||
inline const uint8_t* getPosteriorByIndex2(int index) const;
|
||||
inline uchar* getPosteriorByIndex2(int index);
|
||||
inline const uchar* getPosteriorByIndex2(int index) const;
|
||||
//void makeRandomMeasMatrix(float *cs_phi, PHI_DISTR_TYPE dt, size_t reduced_num_dim);
|
||||
void convertPosteriorsToChar();
|
||||
void makePosteriors2(int num_quant_bits);
|
||||
@ -714,12 +714,12 @@ inline const float* RandomizedTree::getPosteriorByIndex(int index) const
|
||||
return posteriors_[index];
|
||||
}
|
||||
|
||||
inline uint8_t* RandomizedTree::getPosteriorByIndex2(int index)
|
||||
inline uchar* RandomizedTree::getPosteriorByIndex2(int index)
|
||||
{
|
||||
return const_cast<uint8_t*>(const_cast<const RandomizedTree*>(this)->getPosteriorByIndex2(index));
|
||||
return const_cast<uchar*>(const_cast<const RandomizedTree*>(this)->getPosteriorByIndex2(index));
|
||||
}
|
||||
|
||||
inline const uint8_t* RandomizedTree::getPosteriorByIndex2(int index) const
|
||||
inline const uchar* RandomizedTree::getPosteriorByIndex2(int index) const
|
||||
{
|
||||
return posteriors2_[index];
|
||||
}
|
||||
@ -766,16 +766,16 @@ public:
|
||||
size_t reduced_num_dim = RandomizedTree::DEFAULT_REDUCED_NUM_DIM,
|
||||
int num_quant_bits = DEFAULT_NUM_QUANT_BITS);
|
||||
|
||||
// sig must point to a memory block of at least classes()*sizeof(float|uint8_t) bytes
|
||||
void getSignature(IplImage *patch, uint8_t *sig) const;
|
||||
// sig must point to a memory block of at least classes()*sizeof(float|uchar) bytes
|
||||
void getSignature(IplImage *patch, uchar *sig) const;
|
||||
void getSignature(IplImage *patch, float *sig) const;
|
||||
void getSparseSignature(IplImage *patch, float *sig, float thresh) const;
|
||||
// TODO: deprecated in favor of getSignature overload, remove
|
||||
void getFloatSignature(IplImage *patch, float *sig) const { getSignature(patch, sig); }
|
||||
|
||||
static int countNonZeroElements(float *vec, int n, double tol=1e-10);
|
||||
static inline void safeSignatureAlloc(uint8_t **sig, int num_sig=1, int sig_len=176);
|
||||
static inline uint8_t* safeSignatureAlloc(int num_sig=1, int sig_len=176);
|
||||
static inline void safeSignatureAlloc(uchar **sig, int num_sig=1, int sig_len=176);
|
||||
static inline uchar* safeSignatureAlloc(int num_sig=1, int sig_len=176);
|
||||
|
||||
inline int classes() const { return classes_; }
|
||||
inline int original_num_classes() const { return original_num_classes_; }
|
||||
@ -799,8 +799,8 @@ public:
|
||||
private:
|
||||
int classes_;
|
||||
int num_quant_bits_;
|
||||
mutable uint8_t **posteriors_;
|
||||
mutable uint16_t *ptemp_;
|
||||
mutable uchar **posteriors_;
|
||||
mutable unsigned short *ptemp_;
|
||||
int original_num_classes_;
|
||||
bool keep_floats_;
|
||||
};
|
||||
@ -1584,11 +1584,11 @@ void CalonderDescriptorExtractor<T>::compute( const cv::Mat& image,
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CalonderDescriptorExtractor<T>::read( const FileNode &fn )
|
||||
void CalonderDescriptorExtractor<T>::read( const FileNode& )
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
void CalonderDescriptorExtractor<T>::write( FileStorage &fs ) const
|
||||
void CalonderDescriptorExtractor<T>::write( FileStorage&s ) const
|
||||
{}
|
||||
|
||||
CV_EXPORTS Ptr<DescriptorExtractor> createDescriptorExtractor( const string& descriptorExtractorType );
|
||||
|
@ -105,18 +105,18 @@ float* CSMatrixGenerator::getCSMatrix(int m, int n, PHI_DISTR_TYPE dt)
|
||||
if (dt == PDT_GAUSS) {
|
||||
float par = (float)(1./m);
|
||||
for (int i=0; i<m*n; ++i)
|
||||
*cs_phi++ = rng.gaussian(par);
|
||||
*cs_phi++ = (float)rng.gaussian(par);
|
||||
}
|
||||
else if (dt == PDT_BERNOULLI) {
|
||||
float par = (float)(1./sqrt(m));
|
||||
float par = (float)(1./sqrt((float)m));
|
||||
for (int i=0; i<m*n; ++i)
|
||||
*cs_phi++ = (rng(2)==0 ? par : -par);
|
||||
}
|
||||
else if (dt == PDT_DBFRIENDLY) {
|
||||
float par = (float)sqrt(3./m);
|
||||
for (int i=0; i<m*n; ++i) {
|
||||
int i = rng(6);
|
||||
*cs_phi++ = (i==0 ? par : (i==1 ? -par : 0.f));
|
||||
int r = rng(6);
|
||||
*cs_phi++ = (r==0 ? par : (r==1 ? -par : 0.f));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -151,7 +151,7 @@ inline void addVec(int size, const float* src1, const float* src2, float* dst)
|
||||
// final shift is 2 bits right
|
||||
// temp buffer should be twice as long as signature
|
||||
// sig and buffer need not be initialized
|
||||
inline void sum_50t_176c(uint8_t **pp, uint8_t *sig, uint16_t *temp)
|
||||
inline void sum_50t_176c(uchar **pp, uchar *sig, unsigned short *temp)
|
||||
{
|
||||
#if CV_SSE2
|
||||
__m128i acc, *acc1, *acc2, *acc3, *acc4, tzero;
|
||||
@ -293,10 +293,10 @@ void RandomizedTree::createNodes(int num_nodes, RNG &rng)
|
||||
{
|
||||
nodes_.reserve(num_nodes);
|
||||
for (int i = 0; i < num_nodes; ++i) {
|
||||
nodes_.push_back( RTreeNode(rng(RandomizedTree::PATCH_SIZE),
|
||||
rng(RandomizedTree::PATCH_SIZE),
|
||||
rng(RandomizedTree::PATCH_SIZE),
|
||||
rng(RandomizedTree::PATCH_SIZE)) );
|
||||
nodes_.push_back( RTreeNode((uchar)rng(RandomizedTree::PATCH_SIZE),
|
||||
(uchar)rng(RandomizedTree::PATCH_SIZE),
|
||||
(uchar)rng(RandomizedTree::PATCH_SIZE),
|
||||
(uchar)rng(RandomizedTree::PATCH_SIZE)) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,10 +352,10 @@ void RandomizedTree::allocPosteriorsAligned(int num_leaves, int num_classes)
|
||||
memset(posteriors_[i], 0, num_classes*sizeof(float));
|
||||
}
|
||||
|
||||
posteriors2_ = new uint8_t*[num_leaves];
|
||||
posteriors2_ = new uchar*[num_leaves];
|
||||
for (int i=0; i<num_leaves; ++i) {
|
||||
posteriors2_[i] = (uint8_t*)cvAlloc(num_classes*sizeof(posteriors2_[i][0]));
|
||||
memset(posteriors2_[i], 0, num_classes*sizeof(uint8_t));
|
||||
posteriors2_[i] = (uchar*)cvAlloc(num_classes*sizeof(posteriors2_[i][0]));
|
||||
memset(posteriors2_[i], 0, num_classes*sizeof(uchar));
|
||||
}
|
||||
|
||||
classes_ = num_classes;
|
||||
@ -394,7 +394,7 @@ void RandomizedTree::init(int num_classes, int depth, RNG &rng)
|
||||
leaf_counts_.resize(num_leaves_);
|
||||
|
||||
for (int i = 0; i < num_leaves_; ++i)
|
||||
memset((void*)posteriors2_[i], 0, num_classes*sizeof(uint8_t));
|
||||
memset((void*)posteriors2_[i], 0, num_classes*sizeof(uchar));
|
||||
|
||||
createNodes(num_nodes, rng);
|
||||
}
|
||||
@ -510,8 +510,8 @@ void RandomizedTree::estimateQuantPercForPosteriors(float perc[2])
|
||||
assert(posteriors_ != NULL);
|
||||
perc[0] = perc[1] = .0f;
|
||||
for (int i=0; i<num_leaves_; i++) {
|
||||
perc[0] += percentile(posteriors_[i], classes_, LOWER_QUANT_PERC);
|
||||
perc[1] += percentile(posteriors_[i], classes_, UPPER_QUANT_PERC);
|
||||
perc[0] += percentile(posteriors_[i], classes_, GET_LOWER_QUANT_PERC());
|
||||
perc[1] += percentile(posteriors_[i], classes_, GET_UPPER_QUANT_PERC());
|
||||
}
|
||||
perc[0] /= num_leaves_;
|
||||
perc[1] /= num_leaves_;
|
||||
@ -528,12 +528,12 @@ const float* RandomizedTree::getPosterior(uchar* patch_data) const
|
||||
return getPosteriorByIndex( getIndex(patch_data) );
|
||||
}
|
||||
|
||||
uint8_t* RandomizedTree::getPosterior2(uchar* patch_data)
|
||||
uchar* RandomizedTree::getPosterior2(uchar* patch_data)
|
||||
{
|
||||
return const_cast<uint8_t*>(const_cast<const RandomizedTree*>(this)->getPosterior2(patch_data));
|
||||
return const_cast<uchar*>(const_cast<const RandomizedTree*>(this)->getPosterior2(patch_data));
|
||||
}
|
||||
|
||||
const uint8_t* RandomizedTree::getPosterior2(uchar* patch_data) const
|
||||
const uchar* RandomizedTree::getPosterior2(uchar* patch_data) const
|
||||
{
|
||||
return getPosteriorByIndex2( getIndex(patch_data) );
|
||||
}
|
||||
@ -559,13 +559,13 @@ void RandomizedTree::quantizeVector(float *vec, int dim, int N, float bnds[2], i
|
||||
|
||||
}
|
||||
|
||||
void RandomizedTree::quantizeVector(float *vec, int dim, int N, float bnds[2], uint8_t *dst)
|
||||
void RandomizedTree::quantizeVector(float *vec, int dim, int N, float bnds[2], uchar *dst)
|
||||
{
|
||||
int map_bnd[2] = {0, N}; // bounds of quantized target interval we're mapping to
|
||||
int tmp;
|
||||
for (int k=0; k<dim; ++k) {
|
||||
tmp = int((*vec - bnds[0])/(bnds[1] - bnds[0])*(map_bnd[1] - map_bnd[0]) + map_bnd[0]);
|
||||
*dst = (uint8_t)((tmp<0) ? 0 : ((tmp>N) ? N : tmp));
|
||||
*dst = (uchar)((tmp<0) ? 0 : ((tmp>N) ? N : tmp));
|
||||
++vec;
|
||||
++dst;
|
||||
}
|
||||
@ -644,7 +644,7 @@ void RandomizedTree::savePosteriors2(std::string url, bool append)
|
||||
{
|
||||
std::ofstream file(url.c_str(), (append?std::ios::app:std::ios::out));
|
||||
for (int i=0; i<num_leaves_; i++) {
|
||||
uint8_t *post = posteriors2_[i];
|
||||
uchar *post = posteriors2_[i];
|
||||
for (int i=0; i<classes_; i++)
|
||||
file << int(*post++) << (i<classes_-1?" ":"");
|
||||
file << std::endl;
|
||||
@ -767,7 +767,7 @@ void RTreeClassifier::getSignature(IplImage* patch, float *sig) const
|
||||
#endif
|
||||
}
|
||||
|
||||
void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
|
||||
void RTreeClassifier::getSignature(IplImage* patch, uchar *sig) const
|
||||
{
|
||||
// Need pointer to 32x32 patch data
|
||||
uchar buffer[RandomizedTree::PATCH_SIZE * RandomizedTree::PATCH_SIZE];
|
||||
@ -792,13 +792,13 @@ void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
|
||||
// get posteriors
|
||||
if (posteriors_ == NULL)
|
||||
{
|
||||
posteriors_ = (uint8_t**)cvAlloc( trees_.size()*sizeof(posteriors_[0]) );
|
||||
ptemp_ = (uint16_t*)cvAlloc( classes_*sizeof(ptemp_[0]) );
|
||||
posteriors_ = (uchar**)cvAlloc( trees_.size()*sizeof(posteriors_[0]) );
|
||||
ptemp_ = (unsigned short*)cvAlloc( classes_*sizeof(ptemp_[0]) );
|
||||
}
|
||||
/// @todo What is going on in the next 4 lines?
|
||||
uint8_t **pp = posteriors_;
|
||||
uchar **pp = posteriors_;
|
||||
for (tree_it = trees_.begin(); tree_it != trees_.end(); ++tree_it, pp++)
|
||||
*pp = const_cast<uint8_t*>(tree_it->getPosterior2(patch_data));
|
||||
*pp = const_cast<uchar*>(tree_it->getPosterior2(patch_data));
|
||||
pp = posteriors_;
|
||||
|
||||
#if 1
|
||||
@ -808,19 +808,19 @@ void RTreeClassifier::getSignature(IplImage* patch, uint8_t *sig) const
|
||||
static bool warned = false;
|
||||
|
||||
memset((void*)sig, 0, classes_ * sizeof(sig[0]));
|
||||
uint16_t *sig16 = new uint16_t[classes_]; // TODO: make member, no alloc here
|
||||
unsigned short *sig16 = new unsigned short[classes_]; // TODO: make member, no alloc here
|
||||
memset((void*)sig16, 0, classes_ * sizeof(sig16[0]));
|
||||
for (tree_it = trees_.begin(); tree_it != trees_.end(); ++tree_it, pp++)
|
||||
addVec(classes_, sig16, *pp, sig16);
|
||||
|
||||
// squeeze signatures into an uint8_t
|
||||
// squeeze signatures into an uchar
|
||||
const bool full_shifting = true;
|
||||
int shift;
|
||||
if (full_shifting) {
|
||||
float num_add_bits_f = log((float)trees_.size())/log(2.f); // # additional bits required due to summation
|
||||
int num_add_bits = int(num_add_bits_f);
|
||||
if (num_add_bits_f != float(num_add_bits)) ++num_add_bits;
|
||||
shift = num_quant_bits_ + num_add_bits - 8*sizeof(uint8_t);
|
||||
shift = num_quant_bits_ + num_add_bits - 8*sizeof(uchar);
|
||||
//shift = num_quant_bits_ + num_add_bits - 2;
|
||||
//shift = 6;
|
||||
if (shift>0)
|
||||
@ -959,7 +959,7 @@ float RTreeClassifier::countZeroElements()
|
||||
for (int i=0; i<(int)trees_.size(); ++i)
|
||||
for (int k=0; k<(int)trees_[i].num_leaves_; ++k) {
|
||||
float *p = trees_[i].getPosteriorByIndex(k);
|
||||
uint8_t *p2 = trees_[i].getPosteriorByIndex2(k);
|
||||
uchar *p2 = trees_[i].getPosteriorByIndex2(k);
|
||||
assert(p); assert(p2);
|
||||
for (int j=0; j<num_elem; ++j, ++p, ++p2) {
|
||||
if (*p == 0.f) flt_zeros++;
|
||||
@ -967,8 +967,8 @@ float RTreeClassifier::countZeroElements()
|
||||
}
|
||||
}
|
||||
num_elem = trees_.size()*trees_[0].num_leaves_*num_elem;
|
||||
float flt_perc = 100.*flt_zeros/num_elem;
|
||||
float ui8_perc = 100.*ui8_zeros/num_elem;
|
||||
float flt_perc = 100.f*flt_zeros/num_elem;
|
||||
float ui8_perc = 100.f*ui8_zeros/num_elem;
|
||||
printf("[OK] RTC: overall %i/%i (%.3f%%) zeros in float leaves\n", flt_zeros, num_elem, flt_perc);
|
||||
printf(" overall %i/%i (%.3f%%) zeros in uint8 leaves\n", ui8_zeros, num_elem, ui8_perc);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user