Image.draw_* fail on images from Image.Read: pixel data is not C-contiguous (cv2 line/circle/putText layout error)
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- opencv, python
- Domínio
- backend, computer-vision
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 224
- Forks
- 35
- Merge médio
- 1d 22h
- PRs com merge (30d)
- 29
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de petercorke/machinevision-toolbox-python
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 76/100
petercorke/machinevision-toolbox-python#160 ·
Mantenedores costumam responder em até 1 dia
-
tech-debt
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 39/100
petercorke/machinevision-toolbox-python#159 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 42/100
petercorke/machinevision-toolbox-python#157 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
petercorke/machinevision-toolbox-python#152 ·
Mantenedores costumam responder em até 1 dia
-
ROSBag: RealSense bags have a 4-byte depth-units trailer that is guessed, not parsedTalvez já em andamento @theluckystrike assumiu há 4 dias. Abertabug help wanted
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
petercorke/machinevision-toolbox-python#151 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de petercorke/machinevision-toolbox-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
volcengine/OpenViking#6445 ·
Mantenedores costumam responder em até 1 dia
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedTalvez já em andamento @ManyaJain111 assumiu hoje. Abertabug enhancement possible-duplicate
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
AOSSIE-Org/PictoPy#1637 · 4 comentários ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
deepspeedai/DeepSpeed#8884 ·
Mantenedores costumam responder em até 3 dias
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
flagos-ai/FlagQuantum#718 ·
Mantenedores costumam responder em até 1 dia
-
bug CI-failure high priority
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 86/100
vllm-project/afd-plugin#483 ·
Mantenedores costumam responder em até 1 dia