Esempio n. 1
0
TEST(Path, normalize)
{
    cxx::sys::Path path4("/abc/./xyz/../a");
    ASSERT_STREQ(path4.name(), "/abc/a");

    cxx::sys::Path path5("/abc/");
    path5.append("abc");
    ASSERT_STREQ(path5.name(), "/abc/abc");
}
bool SparseRec2View::save()
{
	if(!_onlymatch) {
		//save reconstructed points
		string path1(dir+imgname1+string("-")+imgname2+string(".X"));
		std::ofstream o1(path1.c_str());
		o1 << "VERTEX " << (int)results.size() << endl;
		for(int i=0; i<(int)results.size(); ++i) {
			o1<<results[i].x<<" "<<results[i].y<<" "<<results[i].z<<endl;
		}
		o1.close();
		TagI("save reconstructed points to\n  %s\n",path1.c_str());

		//save cam par
		string path7(imgpath1+string(".par"));
		std::ofstream o7(path7.c_str());
		o7.setf(std::ios::scientific);
		o7 << "K(alphaX alphaY u0 v0)=" <<endl;
		o7 << K[0] << " " << K[4] << " " << K[2] << " " << K[5] << endl;
		o7 << "R=" << endl;
		o7 << "1 0 0\n0 1 0\n0 0 1" <<endl;
		o7 << "T=" << endl;
		o7 << "0 0 0" << endl;
		o7.close();
		TagI("save camera 1's parameters to\n  %s\n",path7.c_str());

		string path8(imgpath2+string(".par"));
		std::ofstream o8(path8.c_str());
		o8.setf(std::ios::scientific);
		o8 << "K(alphaX alphaY u0 v0)=" <<endl;
		o8 << K[0] <<" "<< K[4] <<" "<< K[2] <<" "<< K[5] << endl;
		o8 << "R=" << endl;
		for(int i=0; i<3; ++i) {
			for(int j=0; j<3; ++j) {
				o8 << R[i*3+j] << " ";
			}
			o8 << endl;
		}
		o8 << "T=" << endl;
		o8 << t[0] <<" "<< t[1] <<" "<< t[2] << endl;
		o8.close();
		TagI("save camera 2's parameters to\n  %s\n",path8.c_str());
	}

	double fontScale=0.5;
	CvPoint text_origin;
	//save matched point pairs
	string path2(dir+imgname1+string("-")+imgname2+string(".p1p2"));
	std::ofstream o2(path2.c_str());
	//out.setf(std::ios::scientific);
	int cnt = 0;
	for(int i=0; i<(int)p1.size(); ++i) {
		if(!inliers[i]) continue;

		o2 << p1[i].x <<" "<< p1[i].y <<" "<< p2[i].x <<" "<< p2[i].y <<endl;

		char tmp[256];
		sprintf(tmp, "%d", cnt++);
		text_origin.x = (int)p1[i].x+5;
		text_origin.y = (int)p1[i].y-5;
		putText(img1, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK);
		text_origin.x = (int)p2[i].x+5;
		text_origin.y = (int)p2[i].y-5;
		putText(img2, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK);
	}
	o2.close();
	TagI("save matched point pairs to\n  %s\n",path2.c_str());

	//save images
	string path3(imgpath1+string("-detect.jpg"));
	string path4(imgpath2+string("-detect.jpg"));
	string path5(dir+imgname1+string("-")+imgname2+string(".jpg"));
	if(!img1.empty()) cv::imwrite(path3, img1);
	else {
		TagE("no valid image to save!\n");
		return false;
	}
	if(!img2.empty()) cv::imwrite(path4, img2);
	if(!combined.empty()) cv::imwrite(path5, combined);
	TagI("save surfed image 1 to\n  %s\n",path3.c_str());
	TagI("save surfed image 2 to\n  %s\n",path4.c_str());
	TagI("save combined image to\n  %s\n",path5.c_str());

	//save F
	string path6(dir+imgname1+string("-")+imgname2+string(".fmatrix"));
	std::ofstream o6(path6.c_str());
	o6 << helper::PrintMat<>(3,3,F);
	o6.close();
	TagI("save fundamental matrix to\n  %s\n",path6.c_str());

	return true;
}