Rotation image distante
This commit is contained in:
1 parent
ec155d775f
commit
5b8518c19c
10 files changed
+130
-1
No files matched your search
@@ -114,7 +114,9 @@ réduit la page :
|
||||
visibles ;
|
||||
- ou *Appareil distant* : saisir l'adresse IP de la machine qui porte la
|
||||
caméra (par exemple `192.168.1.20`) et choisir *nouvelle photo* ou
|
||||
*dernière photo*.
|
||||
*dernière photo* ; *Rotation de l'image* (0°, 90°, 180° ou 270° dans le
|
||||
sens horaire) remet droite l'image d'une caméra montée de côté ou à
|
||||
l'envers.
|
||||
4. *Appliquer*.
|
||||
|
||||
La page prend la taille du nid d'abeille, avec la photo redressée et le
|
||||
|
||||
@@ -68,6 +68,14 @@
|
||||
<option value="capture">Take a new photo (/capture)</option>
|
||||
<option value="old">Use the last photo taken (/old)</option>
|
||||
</param>
|
||||
<param name="remote_rotation" type="optiongroup" appearance="combo"
|
||||
gui-text="Rotation of the picture:"
|
||||
gui-description="Turns the received picture clockwise, for a camera mounted sideways or upside down">
|
||||
<option value="0">None (0°)</option>
|
||||
<option value="90">90° clockwise</option>
|
||||
<option value="180">180°</option>
|
||||
<option value="270">270° clockwise (90° anticlockwise)</option>
|
||||
</param>
|
||||
<param name="remote_timeout" type="int" min="1" max="300"
|
||||
gui-text="Timeout (s):">20</param>
|
||||
<separator/>
|
||||
|
||||
@@ -62,6 +62,7 @@ class BoardPhotoImport(inkex.EffectExtension):
|
||||
pars.add_argument("--remote_host", default="")
|
||||
pars.add_argument("--remote_port", type=int, default=5000)
|
||||
pars.add_argument("--remote_endpoint", default="capture")
|
||||
pars.add_argument("--remote_rotation", type=int, default=0)
|
||||
pars.add_argument("--remote_timeout", type=int, default=20)
|
||||
pars.add_argument("--resolution", type=float, default=4.0)
|
||||
pars.add_argument("--jpeg_quality", type=int, default=85)
|
||||
@@ -175,6 +176,9 @@ class BoardPhotoImport(inkex.EffectExtension):
|
||||
inkex.errormsg(_("The capture server did not return a readable image "
|
||||
"({}).").format(url))
|
||||
return None
|
||||
# Camera montee de travers : on tourne la photo avant la detection,
|
||||
# pour que l'image inseree en cas d'echec soit deja dans le bon sens.
|
||||
photo = vision.rotate_photo(photo, opt.remote_rotation)
|
||||
self.notes.append(_("Photo received from {} ({} x {} px).").format(
|
||||
url, photo.width, photo.height))
|
||||
return photo
|
||||
|
||||
@@ -60,6 +60,21 @@ def load_photo(source):
|
||||
return image.convert("RGB")
|
||||
|
||||
|
||||
def rotate_photo(image, angle):
|
||||
"""Photo tournee de `angle` degres (multiple de 90) dans le sens horaire.
|
||||
|
||||
PIL tourne dans le sens trigonometrique : d'ou l'angle negatif. Pour un
|
||||
quart de tour, rotate() passe par transpose (sans perte ni
|
||||
interpolation) et `expand` echange largeur et hauteur.
|
||||
"""
|
||||
angle = int(angle) % 360
|
||||
if angle % 90:
|
||||
raise ValueError("rotation must be a multiple of 90 degrees: {}".format(angle))
|
||||
if not angle:
|
||||
return image
|
||||
return image.rotate(-angle, expand=True)
|
||||
|
||||
|
||||
def gray_array(image):
|
||||
"""Niveaux de gris (0-255) en tableau numpy uint8."""
|
||||
return np.asarray(image.convert("L"), dtype=np.uint8)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -135,6 +135,30 @@ msgstr ""
|
||||
msgid "Use the last photo taken (/old)"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Rotation of the picture:"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Turns the received picture clockwise, for a camera mounted sideways or upside down"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "None (0°)"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "90° clockwise"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "180°"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "270° clockwise (90° anticlockwise)"
|
||||
msgstr ""
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Timeout (s):"
|
||||
msgstr ""
|
||||
|
||||
@@ -137,6 +137,30 @@ msgstr "Take a new photo (/capture)"
|
||||
msgid "Use the last photo taken (/old)"
|
||||
msgstr "Use the last photo taken (/old)"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Rotation of the picture:"
|
||||
msgstr "Rotation of the picture:"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Turns the received picture clockwise, for a camera mounted sideways or upside down"
|
||||
msgstr "Turns the received picture clockwise, for a camera mounted sideways or upside down"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "None (0°)"
|
||||
msgstr "None (0°)"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "90° clockwise"
|
||||
msgstr "90° clockwise"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "180°"
|
||||
msgstr "180°"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "270° clockwise (90° anticlockwise)"
|
||||
msgstr "270° clockwise (90° anticlockwise)"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Timeout (s):"
|
||||
msgstr "Timeout (s):"
|
||||
|
||||
@@ -137,6 +137,30 @@ msgstr "Prendre une nouvelle photo (/capture)"
|
||||
msgid "Use the last photo taken (/old)"
|
||||
msgstr "Reprendre la dernière photo prise (/old)"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Rotation of the picture:"
|
||||
msgstr "Rotation de l'image :"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Turns the received picture clockwise, for a camera mounted sideways or upside down"
|
||||
msgstr "Tourne l'image reçue dans le sens horaire, pour une caméra montée de côté ou à l'envers"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "None (0°)"
|
||||
msgstr "Aucune (0°)"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "90° clockwise"
|
||||
msgstr "90° sens horaire"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "180°"
|
||||
msgstr "180°"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "270° clockwise (90° anticlockwise)"
|
||||
msgstr "270° sens horaire (90° sens antihoraire)"
|
||||
|
||||
#: board_photo_import.inx
|
||||
msgid "Timeout (s):"
|
||||
msgstr "Délai d'attente (s) :"
|
||||
|
||||
@@ -719,6 +719,34 @@ def test_import_remote_last_photo(tmp_path, camera):
|
||||
assert camera.calls[-1] == "/old"
|
||||
|
||||
|
||||
def test_rotate_photo():
|
||||
from PIL import Image
|
||||
image = Image.new("RGB", (4, 2), (0, 0, 0))
|
||||
image.putpixel((0, 0), (255, 0, 0)) # coin haut gauche marque
|
||||
assert vision.rotate_photo(image, 0) is image
|
||||
turned = vision.rotate_photo(image, 90) # sens horaire
|
||||
assert turned.size == (2, 4) and turned.getpixel((1, 0)) == (255, 0, 0)
|
||||
turned = vision.rotate_photo(image, 180)
|
||||
assert turned.size == (4, 2) and turned.getpixel((3, 1)) == (255, 0, 0)
|
||||
turned = vision.rotate_photo(image, 270)
|
||||
assert turned.size == (2, 4) and turned.getpixel((0, 3)) == (255, 0, 0)
|
||||
with pytest.raises(ValueError):
|
||||
vision.rotate_photo(image, 45)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rotation", [90, 180, 270])
|
||||
def test_import_remote_rotated(tmp_path, camera, capsys, rotation):
|
||||
# La photo tournee reste calibree : les reperes donnent l'orientation.
|
||||
svg = run(tmp_path, "BoardPhotoImport", "board_photo_import", EMPTY_MM,
|
||||
"--photo_source=remote", "--remote_host=127.0.0.1",
|
||||
"--remote_port={}".format(camera.port), "--remote_endpoint=old",
|
||||
"--remote_rotation={}".format(rotation))
|
||||
width, height = syn.PHOTO_SIZE
|
||||
size = (height, width) if rotation in (90, 270) else (width, height)
|
||||
assert "({} x {} px)".format(*size) in capsys.readouterr().err
|
||||
assert_holes_match(outline_rings(svg)[1:])
|
||||
|
||||
|
||||
def test_import_remote_errors(tmp_path, camera, capsys):
|
||||
port = camera.port
|
||||
run(tmp_path, "BoardPhotoImport", "board_photo_import", EMPTY_MM,
|
||||
|
||||
Reference in new issue
Block a user