Image.draw_* fail on images from Image.Read: pixel data is not C-contiguous (cv2 line/circle/putText layout error)
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #162 de @petercorke — fusionado
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- opencv, python
- Área
- backend, computer-vision
Línea de trabajo
Start in base/graphics.py, where draw_point calls cv2.putText, and inspect the other draw_* functions that pass the image to OpenCV drawing calls. Reproduce with the issue's Image.Read("monalisa.png") example and check the array's contiguity; add the requested regression test for drawing text on an image read this way. Done when the drawing call succeeds on OpenCV 5 and the regression test passes; pull request #162 is already open.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On OpenCV 5.0, Image.draw_point(..., text) raises when the image comes straight from Image.Read. This breaks the example in its own docstring, so the published docs show a traceback.
Reproduce
OpenCV 5.0.0 (also 5.0.0.93 from PyPI), origin/main at 77a3da9c:
from machinevisiontoolbox import Image
img = Image.Read("monalisa.png")
img.draw_point((270, 194), "+", "eye", fontsize=1, color="yellow")
File ".../machinevisiontoolbox/base/graphics.py", line 782, in draw_point
cv2.putText(
cv2.error: OpenCV(5.0.0) :-1: error: (-5:Bad argument) in function 'putText'
> Overload resolution failed:
> - Layout of the output array img is incompatible with cv::Mat
> - Expected Ptr<cv::UMat> for argument 'img'
Likely cause
The array that Image.Read returns is not C-contiguous. For monalisa.png it has shape (700, 677, 3), strides (677, 1, 473900) and flags["C_CONTIGUOUS"] == False: the memory is planar (channel-first) and the Image holds a transposed view. cv2.putText on 5.0 rejects an output array in that layout.
Not yet checked:
- whether OpenCV 4 accepts it (the test machines used here all had OpenCV 5.0.0);
- why
Image.Readproduces a planar layout; - whether the other
draw_*functions inbase/graphics.pythat pass the image tocv2drawing calls fail the same way.
Fix ideas
- Make the
draw_*functions work on a contiguous copy and write the result back (or return it), or - have
Image.Read/Imageconstruction keep arrays C-contiguous, which is the more general fix but touches more code.
Whichever is chosen, add a regression test that draws text onto an Image.Read image on OpenCV 5 (the existing suite passes on 4 and 5, so it does not exercise this path).
Found while investigating broken examples in the docs build; see the tech-debt issue #159.
- Lenguaje dominante
- Python
- Estrellas
- 224
- Forks
- 35
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 34
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de petercorke/machinevision-toolbox-python
-
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
petercorke/machinevision-toolbox-python#160 ·
Los mantenedores suelen responder en 1 día
-
tech-debt
Dificultad 4/5 3-5 días Aptitud para principiantes 39/100
petercorke/machinevision-toolbox-python#159 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 42/100
petercorke/machinevision-toolbox-python#157 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
petercorke/machinevision-toolbox-python#152 ·
Los mantenedores suelen responder en 1 día
-
ROSBag: RealSense bags have a 4-byte depth-units trailer that is guessed, not parsedQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertobug help wanted
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
petercorke/machinevision-toolbox-python#151 ·
Los mantenedores suelen responder en 1 día
Todos los issues de petercorke/machinevision-toolbox-python
Issues similares
-
[Resource]: glyphcss-diagramsAbiertoresource-submission validation-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
hesreallyhim/awesome-claude-code#3214 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
room-commons replace accepts an empty old string and silently prepends the new text to the pageAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
doobidoo/mcp-memory-service#1650 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ml-explore/mlx-lm#2002 ·
Los mantenedores suelen responder en 2 días