Image.draw_* fail on images from Image.Read: pixel data is not C-contiguous (cv2 line/circle/putText layout error)
维护者通常 1 天内回复
已经有一个关联 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
- 星标
- 224
- 派生
- 35
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 34
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
petercorke/machinevision-toolbox-python 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 76/100
petercorke/machinevision-toolbox-python#160 ·
维护者通常 1 天内回复
-
tech-debt
难度 4/5 3-5 天 新手友好度 39/100
petercorke/machinevision-toolbox-python#159 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 42/100
petercorke/machinevision-toolbox-python#157 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
petercorke/machinevision-toolbox-python#152 ·
维护者通常 1 天内回复
-
ROSBag: RealSense bags have a 4-byte depth-units trailer that is guessed, not parsed可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug help wanted
难度 5/5 一周以上 新手友好度 25/100
petercorke/machinevision-toolbox-python#151 ·
维护者通常 1 天内回复
查看 petercorke/machinevision-toolbox-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
khuisman/mcp-gee-sweet#1166 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
lugassawan/swe-workbench#823 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
gramaziokohler/compas_timber#870 ·
-
security-scan-failure
难度 2/5 1-3 小时 新手友好度 78/100
semantica-agi/semantica#2089 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
autowarefoundation/autoware_carla_scenario#500 ·
维护者通常 1 天内回复