version initiale

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016S8V7WxoS7YRoM34BVBkeo
This commit is contained in:
AlexandClaude Opus 5.5 committed 2026-09-25 17:14:49 +02:00
commit 3c95582a5c
28 files changed
+6570

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm" height="297mm" viewBox="0 0 210 297">
<sodipodi:namedview id="namedview1"/>
</svg>

After

Width:  |  Height:  |  Size: 322 B

+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="800" height="600" viewBox="0 0 800 600">
<sodipodi:namedview id="namedview1"/>
<rect id="existing" x="10" y="10" width="96" height="48" fill="#cccccc"/>
</svg>

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

+82
View File
@@ -0,0 +1,82 @@
# coding=utf-8
"""
Faux serveur de capture pour les tests (memes routes que le serveur Flask).
python tests/fake_camera.py <photo.jpg> <dossier>
Ecrit son port sur la sortie standard, puis sert :
- /capture et /old : la photo (image/jpeg) ; /capture renvoie une erreur 500
« Error: Could not access the camera » si le fichier <dossier>/broken existe ;
- /text : une reponse texte (comme la route /photo du serveur Flask).
Chaque chemin demande est ajoute a <dossier>/calls.txt.
/cut annonce plus d'octets qu'il n'en envoie puis ferme : transmission
interrompue.
Il tourne dans son propre processus, comme la vraie camera.
"""
import os
import socket
import sys
import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
def main(photo, folder):
with open(photo, "rb") as handle:
jpeg = handle.read()
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
with open(os.path.join(folder, "calls.txt"), "a") as log:
log.write(self.path + "\n")
broken = os.path.exists(os.path.join(folder, "broken"))
if self.path == "/capture" and broken:
self.reply(500, "text/html", b"Error: Could not access the camera")
elif self.path in ("/capture", "/old"):
self.reply(200, "image/jpeg", jpeg)
elif self.path == "/cut":
self.send_response(200)
self.send_header("Content-Type", "image/jpeg")
self.send_header("Content-Length", str(len(jpeg)))
self.end_headers()
self.wfile.write(jpeg[:1000])
self.close_connection = True
elif self.path == "/text":
self.reply(200, "text/html", b"Photo save")
else:
self.reply(404, "text/html", b"Not found")
def reply(self, code, content_type, body):
self.send_response(code)
self.send_header("Content-Type", content_type)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
self.wfile.flush()
# Fermeture en douceur. Sur certaines machines Windows (filtre
# reseau, antivirus), fermer la connexion juste apres l'envoi fait
# perdre la fin de la reponse en boucle locale : constate avec curl
# comme avec urllib (environ 1 fois sur 5 sans cette pause, jamais
# avec). On laisse les donnees partir, puis on attend que le client
# ferme a son tour.
try:
time.sleep(0.5)
self.connection.shutdown(socket.SHUT_WR)
self.connection.settimeout(10)
while self.connection.recv(65536):
pass
except OSError:
pass
def log_message(self, *args):
pass
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
print(server.server_address[1], flush=True)
server.serve_forever()
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])
+115
View File
@@ -0,0 +1,115 @@
# coding=utf-8
"""
Photo synthetique d'une planche trouee sur la surface de travail.
Sert aux tests (et au schema) : on connait exactement la position des
reperes, du contour et des trous, puis on simule la prise de vue par une
perspective connue, un leger flou et du bruit. Si la chaine retrouve les
cotes a quelques dixiemes de millimetre, l'echelle est respectee.
"""
import os
import sys
import numpy as np
from PIL import Image, ImageDraw, ImageFilter
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import board_photo_core as core # noqa: E402
WIDTH, HEIGHT = 400.0, 400.0 # zone de travail (mm)
ORIGIN = (30.0, 30.0) # centre du repere origine (repere laser)
SPACING = (340.0, 340.0)
MARKER_SIZE = 20.0
BOARD = [(70.0, 90.0), (330.0, 80.0), (340.0, 300.0), (60.0, 310.0)] # repere SVG
HOLES = [((130.0, 150.0), 6.0), ((230.0, 190.0), 12.5), ((290.0, 260.0), 4.0)]
CAMERA = [(300.0, 150.0), (2150.0, 230.0), (2060.0, 1700.0), (370.0, 1610.0)]
PHOTO_SIZE = (2400, 1800)
def markers():
return core.marker_layout(HEIGHT, ORIGIN[0], ORIGIN[1], SPACING[0], SPACING[1])
def render_scene(res=8.0, bed=70, board=205, printed=False):
"""Vue de dessus parfaite, `res` pixels par mm.
`printed` : reperes imprimes colles sur leur gabarit de pose grave (piece
de papier, traits d'alignement, contour et croix du gabarit autour).
"""
size = (int(WIDTH * res), int(HEIGHT * res))
image = Image.new("L", size, bed)
draw = ImageDraw.Draw(image)
def poly(ring, fill):
draw.polygon([(x * res, y * res) for x, y in ring], fill=fill)
# Nid d'abeille schematise : grille claire sur fond sombre.
for k in range(0, int(WIDTH), 8):
draw.line([(k * res, 0), (k * res, size[1])], fill=bed + 35, width=int(res))
draw.line([(0, k * res), (size[0], k * res)], fill=bed + 35, width=int(res))
def lines(polylines, fill, width_mm):
for line in polylines:
draw.line([(x * res, y * res) for x, y in line], fill=fill,
width=max(1, int(round(width_mm * res))))
for index, center in enumerate(markers()):
if printed:
plate = MARKER_SIZE * 1.8
poly([(center[0] - plate, center[1] - plate), (center[0] + plate, center[1] - plate),
(center[0] + plate, center[1] + plate), (center[0] - plate, center[1] + plate)],
215)
lines(core.guide_lines(center, MARKER_SIZE), 90, 0.3)
poly(core.piece_outline(center, MARKER_SIZE)[:-1], 245)
lines(core.piece_ticks(center, MARKER_SIZE), 20, 0.3)
rings = core.marker_rings(center, MARKER_SIZE, origin=index == core.ORIGIN_MARKER)
poly(rings[0], 25)
for dot in rings[1:]:
poly(dot, 245)
continue
half = MARKER_SIZE * 0.85
poly([(center[0] - half, center[1] - half), (center[0] + half, center[1] - half),
(center[0] + half, center[1] + half), (center[0] - half, center[1] + half)], 235)
rings = core.marker_rings(center, MARKER_SIZE, origin=index == core.ORIGIN_MARKER)
poly(rings[0], 25)
for dot in rings[1:]:
poly(dot, 235)
poly(BOARD, board)
for center, radius in HOLES:
poly(core.circle_ring(center, radius, 180), bed)
return image
def camera_matrix():
"""Homographie mm (repere SVG) -> pixels de la photo simulee."""
corners = [(0.0, 0.0), (WIDTH, 0.0), (WIDTH, HEIGHT), (0.0, HEIGHT)]
return core.homography(corners, CAMERA)
def render_photo(seed=0, rotate=0, res=8.0, printed=False):
"""Photo simulee (PIL RGB) ; `rotate` en quarts de tour (appareil tourne)."""
scene = render_scene(res, printed=printed)
to_scene = np.diag([res, res, 1.0]) @ np.linalg.inv(camera_matrix())
to_scene = to_scene / to_scene[2, 2]
photo = scene.transform(PHOTO_SIZE, Image.PERSPECTIVE, tuple(to_scene.ravel()[:8]),
Image.BICUBIC, fillcolor=40)
photo = photo.filter(ImageFilter.GaussianBlur(1.2))
rng = np.random.default_rng(seed)
noisy = np.asarray(photo, dtype=float) + rng.normal(0, 6, (PHOTO_SIZE[1], PHOTO_SIZE[0]))
photo = Image.fromarray(np.clip(noisy, 0, 255).astype(np.uint8)).convert("RGB")
if rotate:
photo = photo.rotate(90 * rotate, expand=True)
return photo
def marker_pixels(rotate=0):
"""Position exacte des reperes dans la photo (ordre HG, HD, BD, BG du repere SVG)."""
points = core.apply_homography(camera_matrix(), markers())
w, h = PHOTO_SIZE
for _ in range(rotate % 4):
# Rotation de 90 deg dans le sens trigonometrique (PIL, expand=True).
points = np.column_stack([points[:, 1], w - points[:, 0]])
w, h = h, w
return [tuple(p) for p in points]