Example #1
0
bool LnkProperties::copyFile( DocLnk &newdoc )
{
    const char *linkExtn = ".desktop";
    QString fileExtn;
    int extnPos = lnk->file().findRev( '.' );
    if ( extnPos > 0 )
	fileExtn = lnk->file().mid( extnPos );

    QString safename = newdoc.name();
    safename.replace(QRegExp("/"),"_");

    QString fn = locations[ d->locationCombo->currentItem() ]
		  + "/Documents/" + newdoc.type();
    if (!createMimedir(locations[ d->locationCombo->currentItem() ],newdoc.type())) {
        return FALSE;
    }
    fn+="/"+safename;
    if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
	int n=1;
	QString nn = fn + "_" + QString::number(n);
	while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
	    n++;
	    nn = fn + "_" + QString::number(n);
	}
	fn = nn;
    }
    newdoc.setFile( fn + fileExtn );
    newdoc.setLinkFile( fn + linkExtn );

    // Copy file
    FileManager fm;
    if ( !fm.copyFile( *lnk, newdoc ) )
	return FALSE;
    return TRUE;
}
Example #2
0
/* fast cpy */
void OtherHandler::copy(const QString& src, const QString& file) {
    FileManager *fm;
    if(!fm->copyFile(src,file))
        owarn << "Copy failed" << oendl;
}
Example #3
0
/*!
	\fn clusterImageBasedonTopicDist
Params:
	@param1: string thetaFilename
return:
	cv::Mat center
	center topic distribution
cluster all image topic distribution into 20 groups by kmeans, the center topic distribution is returned
*/
cv::Mat WordModel::clusterImageBasedonTopicDist(string thetaFilename, string imgfolder)
{
	cv::Mat thetaMat;
	FileManager fm;
	ImageManager im;
	fm.ThetaDataReader(thetaFilename, &thetaMat);
	//fm.ReadMatFromDisk<float>(thetaFilename, &thetaMat);
	CV_Assert(thetaMat.data != 0);

	cv::Mat labels, centers;
	cv::kmeans(thetaMat, 32, labels, cv::TermCriteria(), 5, 0, centers);
	//fm.SaveMat2Disk<float>(centers, "model\\flann\\center.theta");

	vector<vector<int>> v_groups(32);
	for (int i=0; i<thetaMat.rows; i++)
	{
		int idx = labels.at<int>(i, 0);
		v_groups[idx].push_back(i);
	}

	cv::Mat gps_mat;
	fm.ReadMatFromDisk<double>("model\\gps.dat", &gps_mat);
	CubeMat cm = fm.CubeMatSampling(imgfolder, 5);

	//organize sampled images into one vector, only double side views will be inserted
	vector<string> imglist;
	for (int i=0; i<cm.size(); i++)
	{
		imglist.push_back(cm[i][1]);
		imglist.push_back(cm[i][3]);
	}

#if 0
	for (int i=0; i<v_groups.size(); i++)
	{
		vector<int> _v = v_groups[i];
		cv::Mat sift_features, gps_features;
		for (int j=0; j < _v.size(); j++)
		{
			int idx = _v[j];
			double lat = gps_mat.at<double>(idx, 0);
			double lng = gps_mat.at<double>(idx, 1);
			cv::Mat gps_row(1,2, CV_64F);
			gps_row.at<double>(0,0) = lat;
			gps_row.at<double>(0,1) = lng;

			string imgname = imglist[idx];

			cv::Mat imat = cv::imread(imgname);
			imat = im.ImageClipper(imat);
			cv::Mat descriptor;
			descriptor = im.ImgSiftCollector(imat, false, 0.9);
			sift_features.push_back(descriptor);
			for (int k=0; k<descriptor.rows; k++)
			{
				gps_features.push_back(gps_row);
			}			
		}
		char buffer[256];
		sprintf(buffer, "model\\flann\\%d.sift", i);
		fm.SaveMat2Disk<float>(sift_features, static_cast<string>(buffer));
		sprintf(buffer, "model\\flann\\%d.gps", i);
		fm.SaveMat2Disk<double>(gps_features, static_cast<string>(buffer));
	}
#else
	string trainingimgclusterfolder = "imgs\\pitts";

	for (int i=0; i<v_groups.size(); i++)
	{
		vector<int> _v=v_groups[i];
		for (int j=0; j<_v.size(); j++)
		{
			int idx = _v[j];
			string imgname = imglist[idx];
			char buffer[256];
			sprintf(buffer, "%s\\%d\\", trainingimgclusterfolder.c_str(), i);
			string dstfolder = fm.DirectoryBuilder(static_cast<string>(buffer));
			
			vector<string> _v;
			fm.file_name_splitter(imgname, &_v, "\\");
			dstfolder = dstfolder + _v[_v.size() - 1];

			fm.copyFile(imgname, dstfolder);
		}
	}
#endif

	/*
	cv::flann::Index index(centers, cv::flann::KMeansIndexParams());

	cv::Mat thetaMat_test, indices, distance;
	string thetafilename_test = "model\\test_docs.dat.theta";
	fm.ThetaDataReader(thetafilename_test, &thetaMat_test);
	index.knnSearch(thetaMat_test, indices, distance, 1);
	
	for (int i=0; i < indices.rows; i++)
	{
		cout << indices.row(i) << endl;
	}
	getchar();
	*/
	return centers;
}