Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Image.draw_* fail on images from Image.Read: pixel data is not C-contiguous (cv2 line/circle/putText layout error)

Đang mở
#158 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@petercorke đang làm issue này rồi.

Từ ngày 21/10/2026.

  • #162 của @petercorke — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
opencv, python
Lĩnh vực
backend, computer-vision

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

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.Read produces a planar layout;
  • whether the other draw_* functions in base/graphics.py that pass the image to cv2 drawing 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 / Image construction 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.

Ngôn ngữ chính
Python
Star
224
Fork
31
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
29

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của petercorke/machinevision-toolbox-python

Tất cả issue của petercorke/machinevision-toolbox-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.