opencv / opencv/opencv-python

cv2.imread()读取的图文维度存在随机性

Open
#1,049 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

Expected behaviour

Write here how did you expect the library to function.

Actual behaviour

(160, 256)
(160, 256, 1)
(160, 256)
(160, 256, 1)

(160, 256)
(160, 256, 1)
(160, 256, 1)
(160, 256, 1)

多次运行,会不断改变,我不太明白是什么原因。我希望能保持单通道的1这个参数,在我的结果里。

Steps to reproduce

fundus_img = cv2.imread('/root/autodl-fs/Imag_split/processed_data/1-1 dose/0_0.jpg', cv2.IMREAD_GRAYSCALE)
print(fundus_img.shape)
name = np.expand_dims(fundus_img, axis=2)
print(name.shape)
nameimg = name.astype(np.float32)
nameimg2 = img_train_transforms(nameimg)
print(nameimg2.shape)
if len(nameimg2.shape) != 3:
nameimg2 = np.expand_dims(nameimg2, axis=2)

print(nameimg2.shape)

  • operating system
    linux
  • architecture (e.g. x86)
    x86
  • opencv-python version:opencv-python 4.10.0.84
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied cv2.imread and img_train_transforms snippet, checking the shapes before and after each step. No repository file or test is identified, and the issue concerns general OpenCV usage rather than this build toolchain; a useful resolution would first isolate which operation changes the channel dimension.

Written by the indexing model from the issue text.

Assessment

Tech stack
opencv, python
Domain
computer-vision
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
10/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.