Image.draw_* fail on images from Image.Read: pixel data is not C-contiguous (cv2 line/circle/putText layout error)
維護者通常 3 天內回覆
已經有一個關聯 PR 被合併了。
- #162 來自 @petercorke —— 已合併
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- opencv, python
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Python
- 星號
- 225
- 分支
- 35
- 平均合併
- 1 天 18 小時
- 30 天內合併 PR
- 23
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
petercorke/machinevision-toolbox-python 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 94/100
petercorke/machinevision-toolbox-python#169 ·
維護者通常 3 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
petercorke/machinevision-toolbox-python#168 ·
維護者通常 3 天內回覆
-
_isnotebook() does not recognise JupyterLite可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 3/5 半天 新手友好度 45/100
petercorke/machinevision-toolbox-python#166 ·
維護者通常 3 天內回覆
-
難度 3/5 1-2 天 新手友好度 76/100
petercorke/machinevision-toolbox-python#160 ·
維護者通常 3 天內回覆
-
tech-debt
難度 4/5 3-5 天 新手友好度 39/100
petercorke/machinevision-toolbox-python#159 ·
維護者通常 3 天內回覆
查看 petercorke/machinevision-toolbox-python 的全部 Issue
相似的 Issue
-
ChatBedrockConverse changes the keys of JSON tool results to camelCase (`order_id` becomes `orderId`)可能已有人在做 @geyazheng 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
langchain-ai/langchain-aws#1469 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
b4b usability
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
fix(schedule): align list_tasks since cursor filter boundary from strict > to >=可能已有人在做 @bfs2021 今天認領。 未關閉agent-ready bug p2 schedule
難度 2/5 1-3 小時 新手友好度 83/100
allenporter/supernote#540 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
frazane/scoringrules#164 ·
維護者通常 1 天內回覆