FeatureValue FeatureAverageColor::getNormedAccumulate() { auto ret = FeatureValue(); ret.push_back( accu[0] / count ); ret.push_back( accu[1] / count ); ret.push_back( accu[2] / count ); return ret; }
std::vector<FeatureValue> FeatureValue::compute_all_values(std::vector<TestImage>& tests, Feature& feature) { std::vector<FeatureValue> values; for (size_t i = 0; i < tests.size(); ++i) { auto feature_value = feature.compute_value(tests[i].image_); values.push_back(FeatureValue((short) i, Feature::normalize_feature(feature_value, tests[i].derivation_))); } return values; }
FeatureValue FeatureAverageColor::calculateP( cv::InputArray image ) { auto ret = FeatureValue(); Scalar_< double > avgColor = mean( image, noArray() ); ret.push_back( avgColor[2] ); ret.push_back( avgColor[1] ); ret.push_back( avgColor[0] ); // cout << "r:" << ret.at( 0 ) << ", g:" << ret.at( 1 ) << ", b:" << ret.at( 2 ) << endl; return ret; }
// * FeatureValue FeatureAverageColor::calculate( cv::InputArray _image ) { Mat image_gray; Mat shiImg( _image.rows(), _image.cols(), CV_32SC1, Scalar( 0 ) ); cvtColor( _image, image_gray, CV_BGR2GRAY ); FeatureShiCorner shi; shi.computeRawCornerMat( image_gray, shiImg ); auto points = shi.genPoints( shiImg ); if( points.empty() ) { return { 0, 0, 0 }; } // --------------------------------------------------------------------- auto image = _image.getMat(); auto ret = FeatureValue(); uint64 r, g, b, n; const int radius = 15; r = g = b = 0; n = 0; const auto width = _image.cols(); const auto height = _image.rows(); for( auto p : points ) { int x = p.first, y = p.second; for( int dy = -radius; dy <= radius; dy++ ) { for( int dx = -radius; dx <= radius; dx++ ) { int fx = x + dx; if( (fx < 0) || (fx >= width) ) { continue; } int fy = y + dy; if( (fy < 0) || (fy >= height) ) { continue; } Pixel ptr = image.at< Pixel >( fy, fx ); b += ptr.x; g += ptr.y; r += ptr.z; n++; } } } ret.push_back( r / (n * 1.0) ); ret.push_back( g / (n * 1.0) ); ret.push_back( b / (n * 1.0) ); return ret; }