Descriptor DominantColor::extract_(MyImage *image, bool makeVisRep, Magick::Image *repr){ cv::Mat &img = *image->getOpenCVMat(); Frame* frame = new Frame(img); XM::DominantColorDescriptor *dcd = Mpeg7Feature::getDominantColorD( frame , false ); // don't normalize size_t nColors = dcd->GetDominantColorsNumber(); XM::DOMCOL *colors = dcd->GetDominantColors(); cout << "we've got: " << nColors << " dominant colors" << endl; Descriptor desc; for(size_t i = 0; i < nColors; ++i){ cout << "color " << i << " percentage: " << colors[i].m_Percentage; for(size_t j = 0; j < 3; ++j){ cout << " " << j << " " << colors[i].m_ColorValue[j]; desc.push_back((float) colors[i].m_ColorValue[j]); } // for j cout << endl; } // for i desc.resize(24, 0.0); return desc; }
// Dominant Color //void FexWrite::computeWriteDCD( Frame* frame, // bool normalize, bool variance, bool spatial, // int bin1, int bin2, int bin3 ) unsigned int FexWrite::computeWriteDCD( Frame* frame, int num, unsigned int *arr, bool normalize, bool variance, bool spatial, int bin1, int bin2, int bin3 ) { if(!frame) return 0; // compute the descriptor XM::DominantColorDescriptor* dcd = Feature::getDominantColorD( frame, normalize, variance, spatial, bin1, bin2, bin3 ); // write to screen // number of dominant colors int ndc = dcd->GetDominantColorsNumber(); //std::cout << "num of dominant colors " << ndc << " " << std::endl; //my add // spatial coherency if(spatial) std::cout << dcd->GetSpatialCoherency(); // dominant colors: percentage(1) centroid value (3) color variance (3) XM::DOMCOL* domcol = dcd->GetDominantColors(); /* for( int i = 0; i < ndc; i++ ) { std::cout << " " << domcol[i].m_Percentage << " " << domcol[i].m_ColorValue[0] << " " << domcol[i].m_ColorValue[1] << " " << domcol[i].m_ColorValue[2] << std::endl; if(variance) std::cout << " " << domcol[i].m_ColorVariance[0] << " " << domcol[i].m_ColorVariance[1] << " " << domcol[i].m_ColorVariance[2]; } std::cout << std::endl; */ using namespace std; char tmpStr[30]; sprintf(tmpStr, "feature\\%d_1.txt", num); ofstream f(tmpStr); int numArr[8]; for( int i = 0; i < ndc; i++ ) { f << " " << domcol[i].m_Percentage << " " << domcol[i].m_ColorValue[0] << " " << domcol[i].m_ColorValue[1] << " " << domcol[i].m_ColorValue[2]; //<< std::endl; numArr[i] = domcol[i].m_Percentage; unsigned int a1 = (unsigned int)(domcol[i].m_ColorValue[0]) << 10; unsigned int a2 = (unsigned int)(domcol[i].m_ColorValue[1]) << 5; unsigned int a3 = (unsigned int)(domcol[i].m_ColorValue[2]); arr[i] = a1 | a2 | a3; if(variance) f << " " << domcol[i].m_ColorVariance[0] << " " << domcol[i].m_ColorVariance[1] << " " << domcol[i].m_ColorVariance[2]; } //f << std::endl; f.close(); insertion_sort(numArr, arr, 0, ndc - 1); // release the descriptor delete dcd; //return 0; return ndc; }