-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportarAJSON.py
More file actions
50 lines (33 loc) · 1.15 KB
/
importarAJSON.py
File metadata and controls
50 lines (33 loc) · 1.15 KB
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
import cv2
import numpy as np
import json
import os
#Imagen a introducir en un nuevo
directorioActual = os.path.abspath("")
carpetaImagen = "imagenes"
nombreImagen = "TemploSaturnoAhora"
extensionImagen = ".jpg"
nombreImagenNueva = "TemploSAturnoAntes"
extensionImagenNueva = ".jpg"
imagenAJson=os.path.join(directorioActual, carpetaImagen, nombreImagen + extensionImagen)
imgLigada=os.path.join(directorioActual, carpetaImagen, nombreImagenNueva + extensionImagenNueva)
img = cv2.imread(imagenAJson)
imggris = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgh, imgw, _ = img.shape
F = cv2.SIFT_create()
kpimg, descimg = F.detectAndCompute(imggris, None)
temp = [{'point0':k.pt[0],'point1':k.pt[1],'size':k.size,'angle': k.angle, 'response': k.response, "octave":k.octave,
"id":k.class_id} for k in kpimg]
data = {
"kpimg":temp,
"descimg": descimg.tolist(),
"imgh": imgh,
"imgw": imgw ,
"imagenLigada": imgLigada
#"nombreWikipedia":
}
carpetaJson = "KPJsons"
jsonExt = ".json"
archivoIntroducir=os.path.join(directorioActual, carpetaJson, nombreImagen + jsonExt)
with open(archivoIntroducir, 'w') as archivo:
json.dump(data, archivo)