Parcourir la source

add of rawls version converter

Jérôme BUISINE il y a 3 ans
Parent
commit
a868d485cc
5 fichiers modifiés avec 132 ajouts et 3 suppressions
  1. 4 1
      main/CMakeLists.txt
  2. 51 0
      main/rawls_update.cpp
  3. 1 1
      rawls/rawls.cpp
  4. 1 1
      rawls/rawls_v1.cpp
  5. 75 0
      utils/update_rawls.py

+ 4 - 1
main/CMakeLists.txt

@@ -5,6 +5,7 @@ add_executable(rawls_merge_mean_incr rawls_merge_mean_incr.cpp)
 add_executable(rawls_merge_median_incr rawls_merge_median_incr.cpp)
 add_executable(rawls_merge_MON_incr rawls_merge_MON_incr.cpp)
 add_executable(rawls_merge_MON_pct_incr rawls_merge_MON_pct_incr.cpp)
+add_executable(rawls_update rawls_update.cpp)
 
 target_link_libraries(rawls_convert LINK_PUBLIC rawls)
 target_link_libraries(rawls_merge_mean LINK_PUBLIC rawls)
@@ -13,6 +14,7 @@ target_link_libraries(rawls_merge_mean_incr LINK_PUBLIC rawls)
 target_link_libraries(rawls_merge_median_incr LINK_PUBLIC rawls)
 target_link_libraries(rawls_merge_MON_incr LINK_PUBLIC rawls)
 target_link_libraries(rawls_merge_MON_pct_incr LINK_PUBLIC rawls)
+target_link_libraries(rawls_update LINK_PUBLIC rawls rawls_v1)
 
 set_property(TARGET rawls_merge_mean PROPERTY CXX_STANDARD 17)
 set_property(TARGET rawls_convert PROPERTY CXX_STANDARD 17)
@@ -20,4 +22,5 @@ set_property(TARGET rawls_h_flip PROPERTY CXX_STANDARD 17)
 set_property(TARGET rawls_merge_mean_incr PROPERTY CXX_STANDARD 17)
 set_property(TARGET rawls_merge_median_incr PROPERTY CXX_STANDARD 17)
 set_property(TARGET rawls_merge_MON_incr PROPERTY CXX_STANDARD 17)
-set_property(TARGET rawls_merge_MON_pct_incr PROPERTY CXX_STANDARD 17)
+set_property(TARGET rawls_merge_MON_pct_incr PROPERTY CXX_STANDARD 17)
+set_property(TARGET rawls_update PROPERTY CXX_STANDARD 17)

+ 51 - 0
main/rawls_update.cpp

@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <string.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <tuple>
+
+#include "lodepng.h"
+#include "rawls.h"
+#include "rawls_v1.h"
+
+int main(int argc, char *argv[]){
+
+    std::string imageName;
+    std::string outfileName;
+
+    for (int i = 1; i < argc; ++i) {
+        if (!strcmp(argv[i], "--image") || !strcmp(argv[i], "-image")) {
+            imageName = argv[++i];
+        } else if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-outfile")) {
+            outfileName = argv[++i];
+        }
+    }
+    
+    if (!(rawls::HasExtension(imageName, ".rawls"))){
+        std::cout << "Unexpected `rawls` image name extension" << std::endl;
+        return 1;
+    }
+
+    // std::cout << "Read image `" << imageName << "` and save it into " << outfileName << " into new RAWLS format" << std::endl;
+
+    // get dimensions and data information from image
+    unsigned width, height, nbChanels;
+    float* buffer;
+
+    std::tuple<unsigned, unsigned, unsigned, float*> data = rawls_v1::getDataRAWLS(imageName);
+
+    width = std::get<0>(data);
+    height = std::get<1>(data);
+    nbChanels = std::get<2>(data);
+    buffer = std::get<3>(data);
+
+    auto comments = rawls_v1::getCommentsRAWLS(imageName);
+
+    if (!(rawls::HasExtension(outfileName, ".rawls"))){
+        std::cout << "Unexpected `rawls` image name extension" << std::endl;
+        return 1;
+    }
+
+    rawls::saveAsRAWLS(width, height, nbChanels, comments, buffer, outfileName);
+}

+ 1 - 1
rawls/rawls.cpp

@@ -163,7 +163,7 @@ bool rawls::saveAsRAWLS(unsigned width, unsigned height, unsigned nbChanels, std
         return false;
     }
 
-    std::cout << "Image is now saved as .rawls into " << outfileName << std::endl;
+    // std::cout << "Image is now saved as .rawls into " << outfileName << std::endl;
 
     return true;
 }

+ 1 - 1
rawls/rawls_v1.cpp

@@ -165,7 +165,7 @@ bool rawls_v1::saveAsRAWLS(unsigned width, unsigned height, unsigned nbChanels,
         return false;
     }
 
-    std::cout << "Image is now saved as .rawls into " << outfileName << std::endl;
+    // std::cout << "Image is now saved as .rawls into " << outfileName << std::endl;
 
     return true;
 }

+ 75 - 0
utils/update_rawls.py

@@ -0,0 +1,75 @@
+import os, sys
+import argparse
+import subprocess
+
+def write_progress(progress):
+    '''
+    Display progress information as progress bar
+    '''
+    barWidth = 150
+
+    output_str = "["
+    pos = barWidth * progress
+    
+    for i in range(barWidth):
+        if i < pos:
+           output_str = output_str + "="
+        elif i == pos:
+           output_str = output_str + ">"
+        else:
+            output_str = output_str + " "
+
+    output_str = output_str + "] " + str(int(progress * 100.0)) + " %\r"
+    print(output_str)
+    sys.stdout.write("\033[F")
+
+
+def main():
+
+    parser = argparse.ArgumentParser(description="Update whole scene folder .rawls files to new .rawls version format")
+
+    parser.add_argument('--folder', type=str, help='folder with all .rawls scenes sub folder', required=True)
+    parser.add_argument('--output', type=str, help='output expected folder (can be the same)', required=True)
+
+    args = parser.parse_args()
+
+    p_folder   = args.folder
+    p_output   = args.output
+
+    # check if executable file is available
+    executable_filepath = './build/main/rawls_update'
+
+    if not os.path.exists(executable_filepath):
+        print("Executable '{0}' does not exist or is not accessible as expected.".format(executable_filepath))
+
+    scenes = sorted(os.listdir(p_folder))
+
+    for scene in scenes:
+
+        scene_path = os.path.join(p_folder, scene)
+
+        # create output scene path if does not exist
+        output_scene_path = os.path.join(p_output, scene)
+
+        if not os.path.exists(output_scene_path):
+            os.makedirs(output_scene_path)
+
+        print('Convert .rawls for: {0}'.format(scene))
+
+        images = sorted(os.listdir(scene_path))
+        n_images = len(images)
+
+        for i, img in enumerate(images):
+
+            img_path = os.path.join(scene_path, img)
+            out_img_path = os.path.join(output_scene_path, img)
+
+            # create and launch command
+            subprocess.call([executable_filepath, '--image', img_path, '--outfile', out_img_path])
+
+            write_progress((i + 1 ) / float(n_images))
+
+        print('\n')
+
+if __name__ == "__main__":
+    main()