main.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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                 //two paths
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 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:16