Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

cv2.imread() from 16-bit TIFF creates arrays where np.maximum() fails in function context but works directly

未关闭
#1,182 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
numpy, python

调研方向

首先,在报告中的 Python、OpenCV 和 NumPy 版本下,使用附带的 0000.tif 运行 test_cv2_issue.py,然后比较直接调用 np.maximum() 与在函数上下文中调用所得的结果。完成的标准是复现出依赖上下文的失败,并确定其范围或原因,同时根据报告检查 HLS 色调结果和数组布局。

由索引模型根据 Issue 内容生成。

描述

Environment (fill in your exact versions):

  • Platform: macOS-15.6.1 (arm64)
  • Python 3.14.2
  • OpenCV: 4.11.0
  • NumPy: 2.2.6

Bug Description:

  • cv2.imread() with 16-bit TIFF files creates float32 arrays that cause np.maximum() and np.minimum() to behave inconsistently. When these numpy functions are called inside another function, they return incorrect values, but when called directly on the same arrays, they work correctly.

Key Symptoms:

  • Context-dependent failure: np.maximum() works when called directly, fails when called inside functions
  • Incorrect HLS conversion: Causes hue channel (H) to be 0 instead of ≈46.6
  • Array properties: Non-C-contiguous (strides: (24000, 12) for 1300×2000 image)
  • Specific to: Photoshop-created 16-bit TIFFs (random syntetic TIFFs generated by CV2 don't trigger bug)

Impact:

  • Any image processing using np.maximum()/np.minimum() on OpenCV-loaded float32 arrays in functions produces wrong results.

Workaround:

  • Use Python's max()/min() instead of np.maximum()/np.minimum(). But it is extremely slower for large images.

The bug does not show up with python 3.12.

In attachment a sample image and the script that allows to reproduce the bug.

test_cv2_issue.py

0000.tif

主要语言
Python
星标
5.4k
派生
1k
平均合并
22 小时 17 分钟
30 天内合并 PR
3

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

opencv/opencv-python 的其他 Issue

查看 opencv/opencv-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。