Capture distante
This commit is contained in:
1 parent
5b8518c19c
commit
38f9b094a9
11 files changed
+284
-13
No files matched your search
@@ -27,6 +27,7 @@ puis on les envoie à la laser avec *Export to LaserGRBL*.
|
||||
- [Ce qu'il faut](#ce-quil-faut)
|
||||
- [Installation](#installation)
|
||||
- [Utilisation](#utilisation)
|
||||
- [Mettre en place la caméra distante](#mettre-en-place-la-caméra-distante)
|
||||
- [Réglages utiles](#réglages-utiles)
|
||||
- [En cas de problème](#en-cas-de-problème)
|
||||
- [Limites](#limites)
|
||||
@@ -37,7 +38,7 @@ puis on les envoie à la laser avec *Export to LaserGRBL*.
|
||||
- Une **imprimante** pour les 4 repères de calibration.
|
||||
- Un **appareil photo** (smartphone) ou une **caméra fixe** au-dessus de la
|
||||
laser, reliée à une machine du réseau local qui fait tourner un serveur de
|
||||
capture.
|
||||
capture (voir [Mettre en place la caméra distante](#mettre-en-place-la-caméra-distante)).
|
||||
- Pour découper : l'extension **Export to LaserGRBL**.
|
||||
|
||||
## Installation
|
||||
@@ -141,6 +142,72 @@ que la découpe tombe au bon endroit :
|
||||
en chemin*), dans une couleur de l'export (gravure ou découpe) ;
|
||||
- ne pas mettre de formes remplies dans un groupe que l'on a déplacé.
|
||||
|
||||
## Mettre en place la caméra distante
|
||||
|
||||
Au lieu de photographier la planche à la main, l'extension peut demander la
|
||||
photo à une **webcam USB fixée au-dessus de la laser**, branchée sur un
|
||||
**Raspberry Pi** du réseau local. Le Raspberry Pi fait tourner le petit
|
||||
serveur web [`raspberry/capture_server.py`](raspberry/capture_server.py)
|
||||
(Flask + OpenCV), qui prend la photo dans la meilleure résolution de la
|
||||
caméra.
|
||||
|
||||
### Installer le serveur sur le Raspberry Pi
|
||||
|
||||
1. Brancher la webcam en USB et vérifier qu'elle est vue
|
||||
(`/dev/video0`) :
|
||||
|
||||
```bash
|
||||
sudo apt install v4l-utils python3-opencv python3-flask
|
||||
v4l2-ctl --list-devices
|
||||
```
|
||||
|
||||
2. Copier `raspberry/capture_server.py` dans le dossier personnel du
|
||||
Raspberry Pi (par exemple avec `scp`), puis le lancer :
|
||||
|
||||
```bash
|
||||
python3 ~/capture_server.py
|
||||
```
|
||||
|
||||
Le serveur écoute sur le **port 5000**, sur toutes les interfaces.
|
||||
|
||||
3. Depuis le PC, ouvrir `http://<adresse du Raspberry Pi>:5000/info` dans
|
||||
un navigateur : la page affiche la résolution et le format retenus. Puis
|
||||
`…/capture` doit afficher une photo.
|
||||
|
||||
4. Pour que le serveur démarre avec le Raspberry Pi, ajouter à la crontab
|
||||
(`crontab -e`) la ligne :
|
||||
|
||||
```text
|
||||
@reboot python3 $HOME/capture_server.py
|
||||
```
|
||||
|
||||
Réglages en tête du script : `DEVICE` (numéro de la caméra, 0 pour
|
||||
`/dev/video0`), `WARMUP_FRAMES` (images jetées le temps que l'exposition se
|
||||
règle ; à augmenter si les photos sont sombres ou floues), `JPEG_QUALITY`.
|
||||
|
||||
| Adresse | Rôle |
|
||||
| ------- | ---- |
|
||||
| `/capture` | Prend une nouvelle photo et la renvoie (utilisée par l'extension). |
|
||||
| `/old` | Renvoie la dernière photo prise, sans en reprendre une. |
|
||||
| `/photo` | Prend une photo et renvoie seulement sa résolution (JSON). |
|
||||
| `/info` | Résolution et format choisis pour la caméra (JSON). |
|
||||
|
||||
Conseil : donner au Raspberry Pi une **adresse IP fixe** (réservation DHCP
|
||||
dans la box) pour ne pas avoir à la ressaisir dans Inkscape.
|
||||
|
||||
### Régler l'extension
|
||||
|
||||
Dans **Importer et calibrer**, onglet **Photo** :
|
||||
|
||||
- *Source de la photo* : **Appareil distant** ;
|
||||
- *Adresse de la machine distante* : l'adresse IP du Raspberry Pi (par
|
||||
exemple `192.168.1.20`), *Port* : `5000` ;
|
||||
- *Image* : *Prendre une nouvelle photo* (`/capture`) ou *Reprendre la dernière photo prise* (`/old`) ;
|
||||
- *Rotation de l'image* : selon le montage de la caméra, pour que le repère
|
||||
à deux pastilles apparaisse en bas à gauche ;
|
||||
- *Délai d'attente* : 20 s par défaut, à augmenter si la caméra est lente à régler son
|
||||
exposition.
|
||||
|
||||
## Réglages utiles
|
||||
|
||||
Dans **Importer et calibrer** :
|
||||
@@ -148,6 +215,7 @@ Dans **Importer et calibrer** :
|
||||
| Réglage | Par défaut | À quoi il sert |
|
||||
| ------- | ---------- | -------------- |
|
||||
| Largeur / Hauteur (onglet *Zone de travail*) | 400 × 400 mm | Taille du nid d'abeille. |
|
||||
| Décalage du nid d'abeille X / Y | 0 mm | Position du coin bas gauche du nid par rapport au 0 de la laser, si le nid n'y est pas aligné (X vers la droite, Y vers le haut). Mesurer en envoyant la tête au 0,0. Sert seulement avec les repères autour du nid d'abeille. |
|
||||
| Taille des repères | 20 mm | Côté du carré noir imprimé. À corriger si l'impression l'a réduit. |
|
||||
| Position des repères | Autour du nid d'abeille | Laisser ainsi avec des repères collés aux angles du nid. |
|
||||
| Teinte de la planche (onglet *Détection de la planche*) | Plus claire que le fond | Choisir *plus foncée* pour une planche sombre. |
|
||||
@@ -169,6 +237,8 @@ schéma ci-dessus.
|
||||
| « Aucune planche trouvée » | Changer la *Teinte de la planche*, ou régler le *Seuil* à la main. |
|
||||
| Contour qui déborde, trous parasites | Augmenter le *Lissage* ou l'*Aire minimale d'un trou*. |
|
||||
| « La machine distante est injoignable » | Vérifier l'adresse IP, que la machine est allumée et que le serveur de capture tourne. |
|
||||
| « Le serveur de capture a renvoyé une erreur : 500 Impossible d'accéder à la caméra » | Vérifier que la webcam est branchée (`v4l2-ctl --list-devices`) et qu'aucun autre programme ne l'utilise ; corriger `DEVICE` dans le script. |
|
||||
| Erreur 500 avec *dernière photo* | Aucune photo n'a encore été prise depuis le démarrage du Raspberry Pi : choisir *nouvelle photo*. |
|
||||
| Document trop lourd | Baisser la *Résolution* ou la *Qualité JPEG*. |
|
||||
|
||||
## Limites
|
||||
|
||||
+6
-4
@@ -221,16 +221,18 @@ def sheet_layout(size, page=A4, margin=12.0, header=38.0, footer=22.0, gap=14.0)
|
||||
return [(x0 + c * pitch, y0 + r * pitch) for c, r in cells]
|
||||
|
||||
|
||||
def corner_layout(width, height, size):
|
||||
def corner_layout(width, height, size, offset_x=0.0, offset_y=0.0):
|
||||
"""Reperes colles autour de la zone de travail, le coin interieur de chaque
|
||||
piece de papier touchant un angle de la zone (nid d'abeille).
|
||||
|
||||
Le centre de chaque repere est a une demi-piece (= taille du repere) de
|
||||
l'angle, en X et en Y. Renvoie (origin_x, origin_y, spacing_x, spacing_y),
|
||||
en mm, repere laser (origine a l'angle bas gauche de la zone).
|
||||
l'angle, en X et en Y. (offset_x, offset_y) est la position de l'angle bas
|
||||
gauche du nid par rapport au zero de la laser (nid decale sur la machine).
|
||||
Renvoie (origin_x, origin_y, spacing_x, spacing_y), en mm, repere laser.
|
||||
"""
|
||||
half = piece_side(size) / 2.0
|
||||
return -half, -half, float(width) + 2 * half, float(height) + 2 * half
|
||||
return (float(offset_x) - half, float(offset_y) - half,
|
||||
float(width) + 2 * half, float(height) + 2 * half)
|
||||
|
||||
|
||||
def piece_ticks(center, size):
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
gui-text="Width (mm):">400.0</param>
|
||||
<param name="work_height" type="float" precision="1" min="10" max="5000"
|
||||
gui-text="Height (mm):">400.0</param>
|
||||
<param name="offset_x" type="float" precision="2" min="-1000" max="1000"
|
||||
gui-text="Honeycomb offset X (mm):"
|
||||
gui-description="Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along X; positive when the honeycomb starts to the right of the origin">0.0</param>
|
||||
<param name="offset_y" type="float" precision="2" min="-1000" max="1000"
|
||||
gui-text="Honeycomb offset Y (mm):"
|
||||
gui-description="Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along Y (upwards); positive when the honeycomb starts above the origin">0.0</param>
|
||||
<param name="set_page" type="bool"
|
||||
gui-text="Set the page to the work area size">true</param>
|
||||
<separator/>
|
||||
@@ -31,7 +37,7 @@
|
||||
<param name="marker_size" type="float" precision="1" min="5" max="200"
|
||||
gui-text="Marker size (mm):"
|
||||
gui-description="Side of the black square; the paper piece is twice as large">20.0</param>
|
||||
<label>Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position.</label>
|
||||
<label>Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is at the offset above from the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position, measured from the laser origin (the offset does not apply).</label>
|
||||
<param name="origin_x" type="float" precision="2" min="-1000" max="5000"
|
||||
gui-text="Origin marker centre X (mm):"
|
||||
gui-description="Distance from the laser origin to the centre of the two-dot marker, along X; negative when the markers are around the work area (left of the origin)">30.0</param>
|
||||
|
||||
@@ -50,6 +50,8 @@ class BoardPhotoImport(inkex.EffectExtension):
|
||||
pars.add_argument("--tab", default="work_area")
|
||||
pars.add_argument("--work_width", type=float, default=400.0)
|
||||
pars.add_argument("--work_height", type=float, default=400.0)
|
||||
pars.add_argument("--offset_x", type=float, default=0.0)
|
||||
pars.add_argument("--offset_y", type=float, default=0.0)
|
||||
pars.add_argument("--origin_x", type=float, default=30.0)
|
||||
pars.add_argument("--origin_y", type=float, default=30.0)
|
||||
pars.add_argument("--spacing_x", type=float, default=340.0)
|
||||
@@ -82,9 +84,11 @@ class BoardPhotoImport(inkex.EffectExtension):
|
||||
opt = self.options
|
||||
self.notes = []
|
||||
if opt.marker_placement == "corners":
|
||||
# Pieces de papier aux angles du nid d'abeille : positions deduites.
|
||||
# Pieces de papier aux angles du nid d'abeille : positions deduites,
|
||||
# decalees de la position du nid par rapport au zero de la laser.
|
||||
opt.origin_x, opt.origin_y, opt.spacing_x, opt.spacing_y = \
|
||||
core.corner_layout(opt.work_width, opt.work_height, opt.marker_size)
|
||||
core.corner_layout(opt.work_width, opt.work_height, opt.marker_size,
|
||||
opt.offset_x, opt.offset_y)
|
||||
problems = core.layout_problems(opt.work_width, opt.work_height, opt.origin_x,
|
||||
opt.origin_y, opt.spacing_x, opt.spacing_y,
|
||||
opt.marker_size)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+17
-1
@@ -27,6 +27,22 @@ msgstr ""
|
||||
msgid "Height (mm):"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Honeycomb offset X (mm):"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along X; positive when the honeycomb starts to the right of the origin"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Honeycomb offset Y (mm):"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along Y (upwards); positive when the honeycomb starts above the origin"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx board_photo_markers.inx
|
||||
msgid "Set the page to the work area size"
|
||||
msgstr ""
|
||||
@@ -56,7 +72,7 @@ msgid "Side of the black square; the paper piece is twice as large"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position."
|
||||
msgid "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is at the offset above from the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position, measured from the laser origin (the offset does not apply)."
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx board_photo_markers.inx
|
||||
|
||||
@@ -29,6 +29,22 @@ msgstr "Width (mm):"
|
||||
msgid "Height (mm):"
|
||||
msgstr "Height (mm):"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Honeycomb offset X (mm):"
|
||||
msgstr "Honeycomb offset X (mm):"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along X; positive when the honeycomb starts to the right of the origin"
|
||||
msgstr "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along X; positive when the honeycomb starts to the right of the origin"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Honeycomb offset Y (mm):"
|
||||
msgstr "Honeycomb offset Y (mm):"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along Y (upwards); positive when the honeycomb starts above the origin"
|
||||
msgstr "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along Y (upwards); positive when the honeycomb starts above the origin"
|
||||
|
||||
#: board_photo_import.inx board_photo_markers.inx
|
||||
msgid "Set the page to the work area size"
|
||||
msgstr "Set the page to the work area size"
|
||||
@@ -58,8 +74,8 @@ msgid "Side of the black square; the paper piece is twice as large"
|
||||
msgstr "Side of the black square; the paper piece is twice as large"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position."
|
||||
msgstr "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position."
|
||||
msgid "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is at the offset above from the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position, measured from the laser origin (the offset does not apply)."
|
||||
msgstr "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is at the offset above from the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position, measured from the laser origin (the offset does not apply)."
|
||||
|
||||
#: board_photo_import.inx board_photo_markers.inx
|
||||
msgid "Origin marker centre X (mm):"
|
||||
|
||||
@@ -29,6 +29,22 @@ msgstr "Largeur (mm) :"
|
||||
msgid "Height (mm):"
|
||||
msgstr "Hauteur (mm) :"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Honeycomb offset X (mm):"
|
||||
msgstr "Décalage du nid d'abeille X (mm) :"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along X; positive when the honeycomb starts to the right of the origin"
|
||||
msgstr "Position du coin bas gauche du nid d'abeille par rapport à l'origine de la laser (0, 0), selon X ; positif quand le nid commence à droite de l'origine"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Honeycomb offset Y (mm):"
|
||||
msgstr "Décalage du nid d'abeille Y (mm) :"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Position of the bottom left corner of the honeycomb from the laser origin (0, 0), along Y (upwards); positive when the honeycomb starts above the origin"
|
||||
msgstr "Position du coin bas gauche du nid d'abeille par rapport à l'origine de la laser (0, 0), selon Y (vers le haut) ; positif quand le nid commence au-dessus de l'origine"
|
||||
|
||||
#: board_photo_import.inx board_photo_markers.inx
|
||||
msgid "Set the page to the work area size"
|
||||
msgstr "Mettre la page à la taille de la zone de travail"
|
||||
@@ -58,8 +74,8 @@ msgid "Side of the black square; the paper piece is twice as large"
|
||||
msgstr "Côté du carré noir ; la pièce de papier est deux fois plus grande"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position."
|
||||
msgstr "Autour du nid d'abeille, tout est déduit : l'angle bas gauche du nid est l'origine laser (bas gauche de la page) et l'écart vaut la taille du nid plus deux fois la taille des repères. Les valeurs ci-dessous ne servent que pour une position personnalisée."
|
||||
msgid "Around the honeycomb, everything is deduced: the bottom left corner of the honeycomb is at the offset above from the laser origin (bottom left of the page), and the spacing is the honeycomb size plus twice the marker size. The values below are only used for a custom position, measured from the laser origin (the offset does not apply)."
|
||||
msgstr "Autour du nid d'abeille, tout est déduit : le coin bas gauche du nid est au décalage ci-dessus par rapport à l'origine de la laser (bas gauche de la page), et l'écart vaut la taille du nid plus deux fois la taille des repères. Les valeurs ci-dessous ne servent que pour une position personnalisée, mesurée depuis l'origine de la laser (le décalage ne s'applique pas)."
|
||||
|
||||
#: board_photo_import.inx board_photo_markers.inx
|
||||
msgid "Origin marker centre X (mm):"
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
"""
|
||||
Serveur Flask pour prendre une photo à distance avec une webcam USB (ex. Creative)
|
||||
sur Raspberry Pi, dans la meilleure résolution supportée par la caméra.
|
||||
|
||||
Prérequis :
|
||||
sudo apt install v4l-utils python3-opencv python3-flask
|
||||
"""
|
||||
import re
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
import cv2
|
||||
from flask import Flask, jsonify, send_file
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
PHOTO_PATH = "/tmp/photo.jpg"
|
||||
DEVICE = 0 # /dev/video0
|
||||
WARMUP_FRAMES = 15 # images jetées le temps que l'auto-exposition / balance des blancs se stabilise
|
||||
JPEG_QUALITY = 95 # 0-100 (OpenCV met 95 par défaut, 100 = fichier plus gros)
|
||||
|
||||
camera_lock = threading.Lock() # évite deux accès simultanés à la caméra
|
||||
_best_mode = None # cache : (largeur, hauteur, fourcc)
|
||||
|
||||
|
||||
def get_best_mode():
|
||||
"""Interroge la caméra via v4l2-ctl et retourne la plus grande résolution
|
||||
supportée, avec le format (MJPG ou YUYV) qui la permet."""
|
||||
global _best_mode
|
||||
if _best_mode:
|
||||
return _best_mode
|
||||
|
||||
best = None # (pixels, largeur, hauteur, fourcc)
|
||||
try:
|
||||
out = subprocess.run(
|
||||
["v4l2-ctl", "-d", f"/dev/video{DEVICE}", "--list-formats-ext"],
|
||||
capture_output=True, text=True, timeout=5,
|
||||
).stdout
|
||||
fmt = None
|
||||
for line in out.splitlines():
|
||||
m = re.search(r"\[\d+\]:\s*'(\w{4})'", line)
|
||||
if m:
|
||||
fmt = m.group(1)
|
||||
continue
|
||||
m = re.search(r"Size: Discrete (\d+)x(\d+)", line)
|
||||
if m and fmt:
|
||||
w, h = int(m.group(1)), int(m.group(2))
|
||||
candidate = (w * h, w, h, fmt)
|
||||
# À résolution égale, on préfère MJPG (moins de bande passante USB)
|
||||
if (best is None or candidate[0] > best[0]
|
||||
or (candidate[0] == best[0] and fmt == "MJPG")):
|
||||
best = candidate
|
||||
except (FileNotFoundError, subprocess.TimeoutExpired):
|
||||
pass
|
||||
|
||||
if best:
|
||||
_best_mode = (best[1], best[2], best[3])
|
||||
else:
|
||||
# Repli : on demande une résolution énorme, le pilote choisira le max possible
|
||||
_best_mode = (9999, 9999, "MJPG")
|
||||
return _best_mode
|
||||
|
||||
|
||||
def capture():
|
||||
"""Prend une photo à la résolution max et l'enregistre dans PHOTO_PATH.
|
||||
Retourne la résolution réellement obtenue."""
|
||||
width, height, fourcc = get_best_mode()
|
||||
|
||||
with camera_lock:
|
||||
cam = cv2.VideoCapture(DEVICE, cv2.CAP_V4L2)
|
||||
if not cam.isOpened():
|
||||
raise RuntimeError("Impossible d'accéder à la caméra")
|
||||
try:
|
||||
# Le format doit être défini AVANT la résolution
|
||||
cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*fourcc))
|
||||
cam.set(cv2.CAP_PROP_FRAME_WIDTH, width)
|
||||
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
||||
cam.set(cv2.CAP_PROP_BUFFERSIZE, 1)
|
||||
|
||||
# Laisser l'auto-exposition / le focus se régler
|
||||
for _ in range(WARMUP_FRAMES):
|
||||
cam.grab()
|
||||
|
||||
ret, frame = cam.read()
|
||||
if not ret or frame is None:
|
||||
raise RuntimeError("Échec de la capture")
|
||||
|
||||
real_w = int(cam.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||
real_h = int(cam.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||
finally:
|
||||
cam.release()
|
||||
|
||||
cv2.imwrite(PHOTO_PATH, frame, [cv2.IMWRITE_JPEG_QUALITY, JPEG_QUALITY])
|
||||
return real_w, real_h
|
||||
|
||||
|
||||
@app.route("/photo")
|
||||
def take_photo():
|
||||
try:
|
||||
w, h = capture()
|
||||
except RuntimeError as e:
|
||||
return str(e), 500
|
||||
return jsonify(status="ok", width=w, height=h, path=PHOTO_PATH)
|
||||
|
||||
|
||||
@app.route("/capture")
|
||||
def capture_photo():
|
||||
try:
|
||||
capture()
|
||||
except RuntimeError as e:
|
||||
return str(e), 500
|
||||
return send_file(PHOTO_PATH, mimetype="image/jpeg")
|
||||
|
||||
|
||||
@app.route("/old")
|
||||
def use_old_photo():
|
||||
return send_file(PHOTO_PATH, mimetype="image/jpeg")
|
||||
|
||||
|
||||
@app.route("/info")
|
||||
def info():
|
||||
w, h, fourcc = get_best_mode()
|
||||
return jsonify(width=w, height=h, format=fourcc)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, threaded=True)
|
||||
@@ -966,6 +966,20 @@ def test_corner_layout():
|
||||
"""Pieces de 40 mm (reperes de 20) aux angles d'un nid de 400 x 400 mm."""
|
||||
assert core.corner_layout(400, 400, 20) == pytest.approx((-20, -20, 440, 440))
|
||||
assert core.corner_layout(400, 300, 17.5) == pytest.approx((-17.5, -17.5, 435, 335))
|
||||
# Nid decale de (5, -3) mm par rapport au zero de la laser.
|
||||
assert core.corner_layout(400, 400, 20, 5, -3) == pytest.approx((-15, -23, 440, 440))
|
||||
|
||||
|
||||
def test_import_honeycomb_offset(tmp_path, photo_file):
|
||||
"""Reperes autour d'un nid de 300 mm decale de 50 mm : ce sont exactement
|
||||
ceux de la scene synthetique (centre origine a 30 mm, ecart 340 mm).
|
||||
La page ne fait que 300 mm de haut au lieu de 400 : les trous remontent
|
||||
de 100 mm dans le repere SVG."""
|
||||
svg = run(tmp_path, "BoardPhotoImport", "board_photo_import", EMPTY_MM,
|
||||
"--photo={}".format(photo_file), "--marker_placement=corners",
|
||||
"--work_width=300", "--work_height=300",
|
||||
"--offset_x=50", "--offset_y=50")
|
||||
assert_holes_match(outline_rings(svg)[1:], offset=(0.0, -100.0))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", ["board_photo_import", "board_photo_markers"])
|
||||
|
||||
Reference in new issue
Block a user