Browse Source

update scene used by application

Jérôme BUISINE 2 months ago
parent
commit
71e72b37e2

+ 74 - 46
experimentConfig.default.js

@@ -52,52 +52,80 @@ export const experiments = {
     scenesConfig: {},
     availableScenes: {
       whitelist: [
-        'p3d_arcsphere_800_800',
-        'p3d_bathroom_800_800',
-        'p3d_bedroom_800_800',
-        'p3d_bidir_800_800',
-        'p3d_bmw-m6_800_800',
-        'p3d_bunny-fur_800_800',
-        'p3d_car2_800_800',
-        'p3d_caustic_800_800',
-        'p3d_chopper-titan_800_800',
-        'p3d_classroom_800_800',
-        'p3d_coffee-splash_800_800',
-        'p3d_contemporary-bathroom_800_800',
-        'p3d_crown_800_800',
-        'p3d_dining-room_800_800',
-        'p3d_dragon_250_800_800',
-        'p3d_dragon_800_800',
-        'p3d_ecosys_800_800',
-        'p3d_ganesha_800_800',
-        'p3d_glass-of-water_800_800',
-        'p3d_glass_800_800',
-        'p3d_kitchen_800_800',
-        'p3d_lamp_800_800',
-        'p3d_landscape-view-0_800_800',
-        'p3d_landscape-view-1_800_800',
-        'p3d_landscape-view-2_800_800',
-        'p3d_landscape-view-3_800_800',
-        'p3d_landscape-view-4_800_800',
-        'p3d_living-room-2_800_800',
-        'p3d_living-room-3_800_800',
-        'p3d_living-room_800_800',
-        'p3d_pavilion-day_800_800',
-        'p3d_pavilion-night_800_800',
-        'p3d_sanmiguel_800_800',
-        'p3d_sanmiguel_cam18_800_800',
-        'p3d_sanmiguel_cam1_800_800',
-        'p3d_sanmiguel_cam3_800_800',
-        'p3d_staircase2_800_800',
-        'p3d_staircase_800_800',
-        'p3d_tt_800_800',
-        'p3d_tungsten_veach-mis_800_800',
-        'p3d_veach-ajar_800_800',
-        'p3d_villa-daylight_800_800',
-        'p3d_vw-van_800_800',
-        // 'p3d_water-caustic_800_800',
-        // 'p3d_whiteroom-daytime_800_800',
-        'p3d_whiteroom-night_800_800'
+        'p3d_arcsphere-view0_part6',
+        'p3d_bathroom-view0_part6',
+        'p3d_bedroom-view0_part6',
+        'p3d_bedroom-view1_part6',
+        'p3d_bidir-view0_part6',
+        'p3d_bmw-m6-view0_part6',
+        'p3d_bunny-fur-view0_part6',
+        'p3d_car2-view0_part6',
+        'p3d_caustic-view0_part6',
+        'p3d_chopper-titan-view0_part6',
+        'p3d_classroom-view0_part6',
+        'p3d_classroom-view1_part6',
+        'p3d_coffee-splash-view0_part6',
+        'p3d_contemporary-bathroom-view0_part6',
+        'p3d_contemporary-bathroom-view1_part6',
+        'p3d_crown-view0_part6',
+        'p3d_dining-room-view0_part6',
+        'p3d_dining-room-view1_part6',
+        'p3d_dragon-view0_part6',
+        'p3d_dragon_250-view0_part6',
+        'p3d_echecs-view0_part6',
+        'p3d_echecs-view1_part6',
+        'p3d_echecs-view2_part6',
+        'p3d_ecosys-view0_part6',
+        'p3d_eponge-fractal-5-view0_part6',
+        'p3d_eponge-fractal-5-view1_part6',
+        'p3d_eponge-fractal-6-view0_part6',
+        'p3d_eponge-fractal-6-view1_part6',
+        'p3d_ganesha-view0_part6',
+        'p3d_glass-of-water-view0_part6',
+        'p3d_glass-view0_part6',
+        'p3d_kitchen-view0_part6',
+        'p3d_kitchen-view1_part6',
+        'p3d_lamp-view0_part6',
+        'p3d_landscape-view0_part6',
+        'p3d_landscape-view1_part6',
+        'p3d_landscape-view2_part6',
+        'p3d_landscape-view3_part6',
+        'p3d_landscape-view4_part6',
+        'p3d_living-room-2-view0_part6',
+        'p3d_living-room-2-view1_part6',
+        'p3d_living-room-3-view0_part6',
+        'p3d_living-room-3-view1_part6',
+        'p3d_living-room-view0_part6',
+        'p3d_living-room-view1_part6',
+        'p3d_living-room-view2_part6',
+        'p3d_living-room_part6',
+        'p3d_pavilion-day-view0_part6',
+        'p3d_pavilion-day-view1_part6',
+        'p3d_pavilion-day-view2_part6',
+        'p3d_pavilion-night-view0_part6',
+        'p3d_pavilion-night-view1_part6',
+        'p3d_pavilion-night-view2_part6',
+        'p3d_sanmiguel-view0_part6',
+        'p3d_sanmiguel-view1_part6',
+        'p3d_sanmiguel-view2_part6',
+        'p3d_sanmiguel-view3_part6',
+        'p3d_spaceship-view0_part6',
+        'p3d_sportscar-view0_part6',
+        'p3d_staircase-view0_part6',
+        'p3d_staircase-view1_part6',
+        'p3d_staircase2-view0_part6',
+        'p3d_staircase2-view1_part6',
+        'p3d_tt-view0_part6',
+        'p3d_tungsten_veach-mis-view0_part6',
+        'p3d_veach-ajar-view0_part6',
+        'p3d_veach-ajar-view1_part6',
+        'p3d_villa-daylight-view0_part6',
+        'p3d_villa-daylight-view1_part6',
+        'p3d_villa-daylight-view2_part6',
+        'p3d_vw-van-view0_part6',
+        // 'p3d_water-caustic_view0_part6',
+        // 'p3d_whiteroom-daytime-view0_part6',
+        'p3d_whiteroom-night-view0_part6'
       ],
       blacklist: null
       // No whitelist = Select all scenes

+ 133 - 0
src/views/Experiments/MatchExtractsWithReferenceAll.vue

@@ -0,0 +1,133 @@
+<template>
+  <ExperimentBlock
+    :experiment-name="experimentName"
+    :scene-name="sceneName"
+    :loading-message="loadingMessage"
+    :loading-error-message="loadingErrorMessage"
+  >
+    <template v-slot:header>
+      <!-- Extract configuration -->
+      <extract-configuration
+        v-if="lockConfig === false"
+        @setExtractConfig="setExtractConfig($event, $refs.configurator)"
+        :loading-error-message="loadingErrorMessage"
+        ref="configurator"
+      />
+      <!--/ Extract configuration -->
+    </template>
+
+    <template v-slot:content>
+      <v-flex xs12 sm6 :style="{ 'max-width': maxWidth + 'px', 'min-width': maxWidth + 'px', 'margin-right': 20 + 'px' }">
+        <v-card dark color="primary" :max-width="maxWidth" :min-width="maxWidth">
+          <!-- <v-card-text class="px-0">Experiment image</v-card-text> -->
+
+          <v-container class="pa-1">
+            <template v-for="i in extractConfig.y">
+              <v-layout row wrap :key="`row-${i}`">
+                <v-flex
+                  v-for="(anExtract, index) in extracts.slice(extractConfig.x * (i - 1), (extractConfig.x * i))"
+                  :key="`extract-${i}-${extractConfig.x}-${extractConfig.y}-${index}-${anExtract.quality}`"
+                  class="pa-0"
+                >
+                  <v-card flat tile class="d-flex height100">
+                    <div
+                      v-if="anExtract.loading"
+                      class="img-extract-loader"
+                      @click.right.prevent
+                    >
+                      <v-progress-circular
+                        :indeterminate="true"
+                      />
+                    </div>
+                    <v-img
+                      v-else
+                      :src="anExtract.link"
+                      @click.left.prevent="extractAction($event, anExtract)"
+                      @click.right.prevent="extractAction($event, anExtract)"
+                      class="cursor"
+                      :class="{ 'extract-hover-border': showHoverBorder === true }"
+                      @error="extractsRemovedFromServerFallback"
+                    >
+                      <template v-slot:placeholder>
+                        <v-layout fill-height align-center justify-center ma-0>
+                          <v-progress-circular indeterminate color="grey lighten-5" />
+                        </v-layout>
+                      </template>
+                    </v-img>
+                  </v-card>
+                </v-flex>
+              </v-layout>
+            </template>
+          </v-container>
+        </v-card>
+      </v-flex>
+      <v-flex sm6 xs12 :style="{ 'max-width': maxWidth + 'px', 'min-width': maxWidth + 'px' }">
+        <v-card dark color="primary" :max-width="maxWidth" :min-width="maxWidth">
+          <!-- <v-card-text>Reference image</v-card-text> -->
+          <v-img v-if="referenceImage" :src="referenceImage" :max-height="maxHeight" :max-width="maxWidth" :min-width="maxWidth" />
+        </v-card>
+      </v-flex>
+      <!-- Experiment validation button -->
+      <v-layout justify-end align-content-end>
+        <v-text-field
+          v-model="comment"
+          label="Add a comment here"
+        />
+        <v-btn @click="finishExperiment" color="primary" large right>Finish experiment</v-btn>
+      </v-layout>
+      <!--/ Experiment validation button -->
+    </template>
+  </ExperimentBlock>
+</template>
+
+<script>
+import ExperimentBlock from '@/components/ExperimentBlock.vue'
+import ExperimentBaseExtracts from '@/mixins/ExperimentBaseExtracts'
+import ExtractConfiguration from '@/components/ExperimentsComponents/ExtractConfiguration.vue'
+
+export default {
+  components: {
+    ExperimentBlock,
+    ExtractConfiguration
+  },
+  mixins: [ExperimentBaseExtracts],
+
+  data() {
+    return {
+      referenceImage: null,
+      maxWidth: null,
+      maxHeight: null
+    }
+  },
+
+  async mounted() {
+    // Load config for this scene to local state
+    this.loadConfig()
+
+    // Load progress from store into local state
+    this.loadProgress()
+
+    let reference = null
+
+    // Load scene data from the API
+    await Promise.all([
+      this.getImage('max').then(res => (reference = res)),
+      this.getQualitiesList()
+    ])
+
+    this.referenceImage = reference.link
+
+    this.maxWidth = reference.metadata.width
+    this.maxHeight = reference.metadata.height
+
+    // Load the cached configuration in the configurator component
+    if (this.lockConfig === false) this.$refs.configurator.setDefaultConfig(this.extractConfig)
+
+    // Load extracts if none were cached
+    // if (this.extracts.length === 0)
+    await this.setExtractConfig(this.extractConfig, this.$refs.configurator)
+
+    this.saveProgress()
+  }
+}
+</script>

+ 1 - 1
src/views/GdprNotice.vue

@@ -96,7 +96,7 @@ This website's main goal is to collect data as part of public research. By using
              <!-- eslint-enable -->
             </v-card-text>
 
-            <v-btn color="primary" @click="setGdprValidated">I concent to this privacy policy</v-btn>
+            <v-btn color="primary" @click="setGdprValidated">I consent to this privacy policy</v-btn>
           </v-layout>
         </v-container>
       </v-card>

+ 78 - 0
utils/check_indices.py

@@ -0,0 +1,78 @@
+# main import
+import os
+import argparse
+import shutil
+
+# parameters
+scene_image_quality_separator     = '_'
+scene_image_extension             = '.png'
+
+def get_scene_image_quality(img_path):
+
+    # if path getting last element (image name) and extract quality
+    img_postfix = img_path.split('/')[-1].split(scene_image_quality_separator)[-1]
+    img_quality = img_postfix.replace(scene_image_extension, '')
+
+    return int(img_quality)
+
+def rename_folder_images(folder, output, expected):
+
+    folders = os.listdir(folder)
+
+    for folder_name in folders:
+
+        folder_path = os.path.join(folder, folder_name)
+        output_folder_path = os.path.join(output, folder_name)
+
+        images = sorted(os.listdir(folder_path))
+
+        last_index = get_scene_image_quality(images[-1])
+
+        if last_index != expected:
+            
+            print('Update images indices for %s' % folder_path)
+
+            if not os.path.exists(output_folder_path):
+                os.makedirs(output_folder_path)
+
+            for img in images:
+                img_path = os.path.join(folder_path, img)
+                current_quality = get_scene_image_quality(img_path)
+
+                img_prefix_split = img_path.split('/')[-1].split(scene_image_quality_separator)
+                del img_prefix_split[-1]
+
+                img_prefix = "_".join(img_prefix_split)
+
+                index_str = str(current_quality * 20)
+
+                while len(index_str) < 5:
+                    index_str = "0" + index_str
+
+                img_output_name = img_prefix + '_' + index_str + '.png'
+                img_output_path = os.path.join(output_folder_path, img_output_name)
+
+                shutil.copy2(img_path, img_output_path)
+
+        else:
+            print('Max expected found for', folder_path, '(no need to update)')
+
+        
+def main():
+
+    parser = argparse.ArgumentParser(description="rename image with correct indices")
+
+    parser.add_argument('--folder', type=str, help="folder with HD images", required=True)
+    parser.add_argument('--output', type=str, help="output folder", required=True)
+    parser.add_argument('--expected', type=int, help="max expected index", required=True)
+
+    args = parser.parse_args()
+
+    p_folder = args.folder
+    p_output = args.output
+    p_expected = args.expected
+
+    rename_folder_images(p_folder, p_output, p_expected)
+
+if __name__ == "__main__":
+    main()

+ 32 - 0
utils/convert_parts.sh

@@ -0,0 +1,32 @@
+#! /bin/bash
+
+if [ -z "$1" ]
+  then
+    echo "No argument supplied"
+    echo "Need data folder"
+    exit 1
+fi
+
+if [ -z "$2" ]
+  then
+    echo "No argument supplied"
+    echo "Need output folder"
+    exit 1
+fi
+
+prefix="p3d_"
+
+data_folder=$1
+output_folder=$2
+mkdir -p $output_folder
+
+for folder_path in $(ls -d ${data_folder}*)
+do
+    IFS='/' read -ra ADDR <<< "${folder_path}"
+    folder=${ADDR[-1]}
+
+    if [[ "$folder" == ${prefix}* ]]; then
+
+        python utils/extract_parts.py --folder ${folder_path} --output ${output_folder}
+    fi
+done

+ 30 - 0
utils/count_elements.py

@@ -0,0 +1,30 @@
+# main import
+import os
+import argparse
+
+def count_folder_elements(folder):
+
+    folders = os.listdir(folder)
+
+    for folder_name in folders:
+
+        folder_path = os.path.join(folder, folder_name)
+
+        images = sorted(os.listdir(folder_path))
+        print('Folder %s has %s elements' % (folder_name, len(images)))
+
+        
+def main():
+
+    parser = argparse.ArgumentParser(description="extract and create 7 parts of image from HD one")
+
+    parser.add_argument('--folder', type=str, help="folder with HD images", required=True)
+
+    args = parser.parse_args()
+
+    p_folder = args.folder
+
+    count_folder_elements(p_folder)
+
+if __name__ == "__main__":
+    main()

+ 69 - 41
utils/extract_parts.py

@@ -23,53 +23,56 @@ def get_parts(img):
     m_h_img_block = int(h_block/2)
     m_w_img_block = int(w_block/2)
 
-    # extract left up  image
-    h_start = int((h % h_zone) / 2)
-    w_start = int((w % w_zone) / 2)
-    left_up_image = img[h_start:h_block+h_start, w_start:w_start+w_block]
 
-    parts.append(left_up_image)
+    if h > h_block and w > w_block:
 
-    # extract middle up image
-    h_start = int((h % h_zone) / 2)
+        # extract left up  image
+        h_start = int((h % h_zone) / 2)
+        w_start = int((w % w_zone) / 2)
+        left_up_image = img[h_start:h_block+h_start, w_start:w_start+w_block]
 
-    middle_up_image = img[h_start:h_block+h_start, m_w-m_w_img_block:m_w+m_w_img_block]
+        parts.append(left_up_image)
 
-    parts.append(middle_up_image)
+        # extract middle up image
+        h_start = int((h % h_zone) / 2)
 
-    # extract right up  image
-    h_start = int((h % h_zone) / 2)
-    w_end = w - int((w % w_zone) / 2)
+        middle_up_image = img[h_start:h_block+h_start, m_w-m_w_img_block:m_w+m_w_img_block]
 
-    right_up_image = img[h_start:h_block+h_start, w_end-w_block:w_end]
+        parts.append(middle_up_image)
 
-    parts.append(right_up_image)
+        # extract right up  image
+        h_start = int((h % h_zone) / 2)
+        w_end = w - int((w % w_zone) / 2)
 
-    # extract left bottom image
-    h_end = h - int((h % h_zone) / 2)
-    h_start = h_end - h_block
-    w_start = int((w % w_zone) / 2)
+        right_up_image = img[h_start:h_block+h_start, w_end-w_block:w_end]
 
-    left_bottom_image = img[h_start:h_end, w_start:w_start+w_block]
+        parts.append(right_up_image)
 
-    parts.append(left_bottom_image)
+        # extract left bottom image
+        h_end = h - int((h % h_zone) / 2)
+        h_start = h_end - h_block
+        w_start = int((w % w_zone) / 2)
 
-    # extract middle bottom image
-    h_end = h - int((h % h_zone) / 2)
-    h_start = h_end - h_block
-    
-    middle_bottom_image = img[h_start:h_end, m_w-m_w_img_block:m_w+m_w_img_block]
+        left_bottom_image = img[h_start:h_end, w_start:w_start+w_block]
 
-    parts.append(middle_bottom_image)
+        parts.append(left_bottom_image)
 
-    # extract left bottom image
-    h_end = h - int((h % h_zone) / 2)
-    h_start = h_end - h_block
-    w_end = w - int((w % w_zone) / 2)
+        # extract middle bottom image
+        h_end = h - int((h % h_zone) / 2)
+        h_start = h_end - h_block
+        
+        middle_bottom_image = img[h_start:h_end, m_w-m_w_img_block:m_w+m_w_img_block]
+
+        parts.append(middle_bottom_image)
 
-    right_bottom_image = img[h_start:h_end,  w_end-w_block:w_end]
+        # extract left bottom image
+        h_end = h - int((h % h_zone) / 2)
+        h_start = h_end - h_block
+        w_end = w - int((w % w_zone) / 2)
 
-    parts.append(right_bottom_image)
+        right_bottom_image = img[h_start:h_end,  w_end-w_block:w_end]
+
+        parts.append(right_bottom_image)
 
     # extract middle center image
     middle_image = img[m_h-m_h_img_block:m_h+m_h_img_block, m_w-m_w_img_block:m_w+m_w_img_block]
@@ -83,8 +86,10 @@ def extract(folder, output):
 
     images_path = sorted(os.listdir(folder))
 
+    check_exists = False
+
     # for each image get sub parts
-    for img_name in images_path:
+    for img_index, img_name in enumerate(images_path):
 
         img_path = os.path.join(folder, img_name)
         img = np.array(Image.open(img_path))
@@ -92,25 +97,47 @@ def extract(folder, output):
         # get all expected parts from image
         parts = get_parts(img)
 
-        for index, part in enumerate(parts):
+        if len(parts) > 1:
+            for index, part in enumerate(parts):
 
-            # get part output folder and create it if not exists
-            prefix_image_folder_path = os.path.join(output, folder.replace('/', '') + '_part' + str(index))
+                # get part output folder and create it if not exists
+                prefix_image_folder_path = os.path.join(output, folder.split('/')[-1].replace('/', '') + '_part' + str(index))
+
+                if not os.path.exists(prefix_image_folder_path):
+                    os.makedirs(prefix_image_folder_path)
+                elif img_index == 0:
+                    check_exists = True
+
+                if not check_exists:
+                    # build output image path and save it
+                    image_output_folder_path = os.path.join(prefix_image_folder_path, img_name)
+                    
+                    Image.fromarray(part).save(image_output_folder_path)
+        else:
+            # only middle of the scene
+            part = parts[0]
+            prefix_image_folder_path = os.path.join(output, folder.split('/')[-1].replace('/', '') + '_part6')
 
             if not os.path.exists(prefix_image_folder_path):
                 os.makedirs(prefix_image_folder_path)
+            elif img_index == 0:
+                check_exists = True
+
+            if not check_exists:
+                # build output image path and save it
+                image_output_folder_path = os.path.join(prefix_image_folder_path, img_name)
+                
+                Image.fromarray(part).save(image_output_folder_path)
 
-            # build output image path and save it
-            image_output_folder_path = os.path.join(prefix_image_folder_path, img_name)
-            
-            Image.fromarray(part).save(image_output_folder_path)
+        if check_exists:
+            break
 
         
 def main():
 
     parser = argparse.ArgumentParser(description="extract and create 7 parts of image from HD one")
 
-    parser.add_argument('--folder', type=str, help="folder which HD images", required=True)
+    parser.add_argument('--folder', type=str, help="folder with HD images", required=True)
     parser.add_argument('--output', type=str, help="output data folder", required=True)
 
     args = parser.parse_args()
@@ -118,6 +145,7 @@ def main():
     p_folder = args.folder
     p_output = args.output
 
+    print('Start extraction for folder %s' % p_folder)
     extract(p_folder, p_output)
 
 if __name__ == "__main__":