Upload livro.py
Browse files
livro.py
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
import cv2
|
2 |
import numpy as np
|
3 |
from reportlab.pdfgen import canvas
|
@@ -27,8 +30,6 @@ def detectar_pontos(imagem_array, mascara_array=None, idade=6):
|
|
27 |
thresh = cv2.bitwise_and(thresh, mask_thresh)
|
28 |
except Exception as e:
|
29 |
print("Erro ao processar máscara:", e)
|
30 |
-
_, mask_thresh = cv2.threshold(mask, 10, 255, cv2.THRESH_BINARY)
|
31 |
-
thresh = cv2.bitwise_and(thresh, mask_thresh)
|
32 |
|
33 |
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
|
34 |
if not contours:
|
@@ -40,10 +41,32 @@ def detectar_pontos(imagem_array, mascara_array=None, idade=6):
|
|
40 |
return sorted(approx, key=lambda p: (p[1], p[0]))
|
41 |
|
42 |
def gerar_preview_com_pontos(pontos):
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
cv2.circle(preview, (x, y), 4, (0, 0, 0), -1)
|
46 |
cv2.putText(preview, str(i+1), (x + 5, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 0), 1)
|
|
|
47 |
preview_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
|
48 |
cv2.imwrite(preview_path, preview)
|
49 |
return preview_path
|
@@ -76,3 +99,11 @@ def gerar_preview_kdp():
|
|
76 |
capa_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
|
77 |
img.save(capa_path)
|
78 |
return capa_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gerar novo livro.py com visualização centralizada e escala adequada para preview
|
2 |
+
|
3 |
+
livro_corrigido = '''
|
4 |
import cv2
|
5 |
import numpy as np
|
6 |
from reportlab.pdfgen import canvas
|
|
|
30 |
thresh = cv2.bitwise_and(thresh, mask_thresh)
|
31 |
except Exception as e:
|
32 |
print("Erro ao processar máscara:", e)
|
|
|
|
|
33 |
|
34 |
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
|
35 |
if not contours:
|
|
|
41 |
return sorted(approx, key=lambda p: (p[1], p[0]))
|
42 |
|
43 |
def gerar_preview_com_pontos(pontos):
|
44 |
+
largura = 600
|
45 |
+
altura = 800
|
46 |
+
margem = 50
|
47 |
+
|
48 |
+
preview = np.ones((altura, largura, 3), dtype=np.uint8) * 255
|
49 |
+
|
50 |
+
if not pontos:
|
51 |
+
return None
|
52 |
+
|
53 |
+
x_coords, y_coords = zip(*pontos)
|
54 |
+
min_x, max_x = min(x_coords), max(x_coords)
|
55 |
+
min_y, max_y = min(y_coords), max(y_coords)
|
56 |
+
|
57 |
+
escala_x = (largura - 2 * margem) / (max_x - min_x + 1e-5)
|
58 |
+
escala_y = (altura - 2 * margem) / (max_y - min_y + 1e-5)
|
59 |
+
escala = min(escala_x, escala_y)
|
60 |
+
|
61 |
+
pontos_normalizados = [(
|
62 |
+
int((x - min_x) * escala + margem),
|
63 |
+
int((y - min_y) * escala + margem)
|
64 |
+
) for x, y in pontos]
|
65 |
+
|
66 |
+
for i, (x, y) in enumerate(pontos_normalizados):
|
67 |
cv2.circle(preview, (x, y), 4, (0, 0, 0), -1)
|
68 |
cv2.putText(preview, str(i+1), (x + 5, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 0), 1)
|
69 |
+
|
70 |
preview_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
|
71 |
cv2.imwrite(preview_path, preview)
|
72 |
return preview_path
|
|
|
99 |
capa_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
|
100 |
img.save(capa_path)
|
101 |
return capa_path
|
102 |
+
'''
|
103 |
+
|
104 |
+
# Salvar como arquivo Python
|
105 |
+
livro_path = "/mnt/data/livro.py"
|
106 |
+
with open(livro_path, "w", encoding="utf-8") as f:
|
107 |
+
f.write(livro_corrigido)
|
108 |
+
|
109 |
+
livro_path
|