Image.draw_* fail on images from Image.Read: pixel data is not C-contiguous (cv2 line/circle/putText layout error)
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- opencv, python
- Bereich
- backend, computer-vision
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 224
- Forks
- 31
- Ø Merge
- 1 T. 22 Std.
- Gemergte PRs (30 T.)
- 29
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus petercorke/machinevision-toolbox-python
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
petercorke/machinevision-toolbox-python#160 ·
Maintainer antworten meist innerhalb von 1 Tag
-
tech-debt
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 39/100
petercorke/machinevision-toolbox-python#159 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 42/100
petercorke/machinevision-toolbox-python#157 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
petercorke/machinevision-toolbox-python#152 ·
Maintainer antworten meist innerhalb von 1 Tag
-
ROSBag: RealSense bags have a 4-byte depth-units trailer that is guessed, not parsedEvtl. vergeben @theluckystrike hat das vor 4 Tagen übernommen. Offenbug help wanted
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
petercorke/machinevision-toolbox-python#151 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in petercorke/machinevision-toolbox-python
Ähnliche Issues
-
bug good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
yunaremaia/proto-drift#22 ·
-
bug good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
yunaremaia/memwatch#96 ·
-
bug good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
yunaremaia/ci-gate-watch#34 ·
-
bug good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
yunaremaia/agent-capability-attestation#64 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 86/100
yunaremaia/agent-call-graph#43 ·
Maintainer antworten meist innerhalb von 1 Tag