Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rtabmap/utilite/ULogger.h"
00029 #include "rtabmap/utilite/UTimer.h"
00030 #include "rtabmap/utilite/UDirectory.h"
00031 #include "rtabmap/utilite/UFile.h"
00032 #include "rtabmap/utilite/UConversion.h"
00033 #include <opencv2/core/core.hpp>
00034 #include <opencv2/highgui/highgui.hpp>
00035
00036 void showUsage()
00037 {
00038 printf("Usage:\n"
00039 "imagesJoiner.exe [option] path\n"
00040 "imagesJoiner.exe path_left path_right\n"
00041 " Options:\n"
00042 " -inv option for copying odd images on the right\n\n");
00043 exit(1);
00044 }
00045
00046 int main(int argc, char * argv[])
00047 {
00048 if(argc < 2)
00049 {
00050 showUsage();
00051 }
00052
00053 bool inv = false;
00054 for(int i=1; i<argc-1; ++i)
00055 {
00056 if(strcmp(argv[i], "-inv") == 0)
00057 {
00058 inv = true;
00059 printf(" Inversing option activated...\n");
00060 continue;
00061 }
00062 if(argc > 3)
00063 {
00064 showUsage();
00065 printf(" Not recognized option: \"%s\"\n", argv[i]);
00066 }
00067 }
00068
00069 std::string path, pathRight;
00070
00071 if(argc == 3 && !inv)
00072 {
00073
00074 path = argv[1];
00075 pathRight = argv[2];
00076
00077 printf(" Path left = %s\n", path.c_str());
00078 printf(" Path right = %s\n", pathRight.c_str());
00079 }
00080 else
00081 {
00082 path = argv[argc-1];
00083 printf(" Path = %s\n", path.c_str());
00084 }
00085
00086 UDirectory dir(path, "jpg bmp png tiff jpeg");
00087 UDirectory dirRight(pathRight, "jpg bmp png tiff jpeg");
00088 if(!dir.isValid() || (!pathRight.empty() && !dirRight.isValid()))
00089 {
00090 printf("Path invalid!\n");
00091 exit(-1);
00092 }
00093
00094 std::string targetDirectory = path+"_joined";
00095 UDirectory::makeDir(targetDirectory);
00096 printf(" Creating directory \"%s\"\n", targetDirectory.c_str());
00097
00098
00099 std::string fileNameA = dir.getNextFilePath();
00100 std::string fileNameB;
00101 if(dirRight.isValid())
00102 {
00103 fileNameB = dirRight.getNextFilePath();
00104 }
00105 else
00106 {
00107 fileNameB = dir.getNextFilePath();
00108 }
00109
00110 int i=1;
00111 while(!fileNameA.empty() && !fileNameB.empty())
00112 {
00113 if(inv)
00114 {
00115 std::string tmp = fileNameA;
00116 fileNameA = fileNameB;
00117 fileNameB = tmp;
00118 }
00119
00120 std::string ext = UFile::getExtension(fileNameA);
00121
00122 std::string targetFilePath = targetDirectory+UDirectory::separator()+uNumber2Str(i++)+"."+ext;
00123
00124 cv::Mat imageA = cv::imread(fileNameA.c_str());
00125 cv::Mat imageB = cv::imread(fileNameB.c_str());
00126
00127 fileNameA.clear();
00128 fileNameB.clear();
00129
00130 if(!imageA.empty() && !imageB.empty())
00131 {
00132 cv::Size sizeA = imageA.size();
00133 cv::Size sizeB = imageB.size();
00134 cv::Size targetSize(0,0);
00135 targetSize.width = sizeA.width + sizeB.width;
00136 targetSize.height = sizeA.height > sizeB.height ? sizeA.height : sizeB.height;
00137 cv::Mat targetImage(targetSize, imageA.type());
00138
00139 cv::Mat roiA(targetImage, cv::Rect( 0, 0, sizeA.width, sizeA.height ));
00140 imageA.copyTo(roiA);
00141 cv::Mat roiB( targetImage, cvRect( sizeA.width, 0, sizeB.width, sizeB.height ) );
00142 imageB.copyTo(roiB);
00143
00144 if(!cv::imwrite(targetFilePath.c_str(), targetImage))
00145 {
00146 printf("Error : saving to \"%s\" goes wrong...\n", targetFilePath.c_str());
00147 }
00148 else
00149 {
00150 printf("Saved \"%s\" \n", targetFilePath.c_str());
00151 }
00152
00153 fileNameA = dir.getNextFilePath();
00154 if(dirRight.isValid())
00155 {
00156 fileNameB = dirRight.getNextFilePath();
00157 }
00158 else
00159 {
00160 fileNameB = dir.getNextFilePath();
00161 }
00162 }
00163 else
00164 {
00165 printf("Error: loading images failed!\n");
00166 }
00167 }
00168 printf("%d files processed\n", i-1);
00169
00170 return 0;
00171 }