File size: 7,377 Bytes
b4f9490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<template>

  <div class="export-view">

    <div class="export-content">

      <div class="export-header">

        <h3>Export</h3>

      </div>

      

      <div class="export-info">

        <div class="info-row">

          <span>{{ objectCount }} objets, {{ annotationCount }} annotations</span>

        </div>

        <div class="info-row filename">

          <span>{{ fileName }}</span>

        </div>

      </div>

      

      <div class="export-actions">

        <button 

          class="export-button"

          @click="exportAnnotations"

          :disabled="!hasAnnotations"

        >

          <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">

            <path d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>

          </svg>

          Télécharger

        </button>

        

        <p v-if="!hasAnnotations" class="no-data-message">

          Aucune donnée à exporter

        </p>

      </div>

    </div>

  </div>

</template>



<script>

import { useAnnotationStore } from '@/stores/annotationStore'

import { useVideoStore } from '@/stores/videoStore'

import { computed } from 'vue'



export default {

  name: 'EmptyView',

  

  setup() {

    const annotationStore = useAnnotationStore()

    const videoStore = useVideoStore()



    const videoName = computed(() => {

      if (videoStore.selectedVideo?.name) {

        return videoStore.selectedVideo.name.replace(/\.[^/.]+$/, '') // Enlever l'extension

      }

      return 'default_video'

    })



    const fileName = computed(() => {

      return `${videoName.value}_config.json`

    })



    const objectCount = computed(() => {

      return Object.keys(annotationStore.objects).length

    })



    const annotationCount = computed(() => {

      let count = 0

      Object.values(annotationStore.frameAnnotations).forEach(frameAnnotations => {

        count += frameAnnotations.length

      })

      return count

    })



    const hasAnnotations = computed(() => {

      return annotationCount.value > 0

    })



    const exportAnnotations = () => {

      // Créer la structure objects selon le format demandé

      const objects = Object.values(annotationStore.objects).map(obj => {

        const objData = {

          obj_id: parseInt(obj.id)

        }



        // Analyser le label pour extraire le type et l'équipe

        if (obj.label) {

          const label = obj.label.toLowerCase()

          

          if (label.includes('ball')) {

            objData.obj_type = 'ball'

            objData.team = null

          } else if (label.includes('player')) {

            objData.obj_type = 'player'

            

            // Extraire le numéro d'équipe

            if (label.includes('team 1') || label.includes('team1')) {

              objData.team = 1

            } else if (label.includes('team 2') || label.includes('team2')) {

              objData.team = 2

            } else {

              objData.team = null

            }

          } else {

            objData.obj_type = null

            objData.team = null

          }

        } else {

          objData.obj_type = null

          objData.team = null

        }



        return objData

      })



      // Créer la structure initial_annotations selon le format demandé

      const initial_annotations = []

      

      // Parcourir toutes les frames qui ont des annotations

      Object.keys(annotationStore.frameAnnotations).forEach(frameNumber => {

        const frameAnnotations = annotationStore.frameAnnotations[frameNumber]

        const frameData = {

          frame: parseInt(frameNumber),

          annotations: []

        }



        // Grouper les annotations par objet pour cette frame

        const annotationsByObject = {}

        frameAnnotations.forEach(annotation => {

          if (!annotationsByObject[annotation.objectId]) {

            annotationsByObject[annotation.objectId] = []

          }



          // Extraire les points selon le type d'annotation

          if (annotation.type === 'point') {

            annotationsByObject[annotation.objectId].push({

              x: Math.round(annotation.x),

              y: Math.round(annotation.y),

              label: annotation.pointType === 'positive' ? 1 : 0

            })

          } else if (annotation.type === 'mask' && annotation.points) {

            // Ajouter tous les points du masque

            annotation.points.forEach(point => {

              annotationsByObject[annotation.objectId].push({

                x: Math.round(point.x),

                y: Math.round(point.y),

                label: point.type === 'positive' ? 1 : 0

              })

            })

          }

        })



        // Créer les annotations pour cette frame

        Object.keys(annotationsByObject).forEach(objectId => {

          const points = annotationsByObject[objectId]

          if (points.length > 0) {

            frameData.annotations.push({

              obj_id: parseInt(objectId),

              points: points

            })

          }

        })



        // Ajouter la frame seulement si elle a des annotations

        if (frameData.annotations.length > 0) {

          initial_annotations.push(frameData)

        }

      })



      // Structure finale selon le format demandé

      const exportData = {

        objects: objects,

        initial_annotations: initial_annotations

      }



      // Créer le blob et le télécharger

      const jsonString = JSON.stringify(exportData, null, 2)

      const blob = new Blob([jsonString], { type: 'application/json' })

      const url = URL.createObjectURL(blob)

      

      const link = document.createElement('a')

      link.href = url

      link.download = fileName.value

      document.body.appendChild(link)

      link.click()

      document.body.removeChild(link)

      URL.revokeObjectURL(url)



      console.log('Annotations exportées:', fileName.value)

    }



    return {

      videoName,

      fileName,

      objectCount,

      annotationCount,

      hasAnnotations,

      exportAnnotations

    }

  }

}

</script>



<style scoped>

.export-view {

  height: 100%;

  display: flex;

  align-items: center;

  justify-content: center;

  color: white;

  padding: 20px;

}



.export-content {

  text-align: center;

  width: 100%;

}



.export-header {

  margin-bottom: 20px;

}



.export-header h3 {

  margin: 0;

  font-size: 1rem;

  color: #fff;

  font-weight: 500;

}



.export-info {

  margin-bottom: 20px;

}



.info-row {

  margin-bottom: 8px;

  color: #ccc;

  font-size: 0.9rem;

}



.info-row.filename {

  color: #fff;

  font-family: monospace;

  font-size: 0.8rem;

}



.export-actions {

  text-align: center;

}



.export-button {

  display: inline-flex;

  align-items: center;

  gap: 6px;

  padding: 8px 16px;

  background: #4a4a4a;

  color: white;

  border: none;

  border-radius: 4px;

  font-size: 0.8rem;

  cursor: pointer;

  transition: background 0.2s;

}



.export-button:hover:not(:disabled) {

  background: #5a5a5a;

}



.export-button:disabled {

  background: #3c3c3c;

  color: #666;

  cursor: not-allowed;

}



.no-data-message {

  margin: 12px 0 0 0;

  color: #666;

  font-size: 0.8rem;

  font-style: italic;

}

</style>