Skip to content

python: inconsistant behaviour with more than 512 channels #20070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
berak opened this issue May 12, 2021 · 2 comments
Closed
4 tasks done

python: inconsistant behaviour with more than 512 channels #20070

berak opened this issue May 12, 2021 · 2 comments
Labels

Comments

@berak
Copy link
Contributor

berak commented May 12, 2021

System information (version)
  • OpenCV => 4.5.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler => python3.8
Detailed description

opencv's Mat is restricted to <= 512 channels, but numpy arrays can have any number

Steps to reproduce
>>> a = np.ones((10,10,600),np.uint8)
>>> cv2.add(a,a) # no problem ???
>>> cv2.copyMakeBorder(a,3,3,3,3,cv2.BORDER_REFLECT101)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.5.2-pre) C:\p\opencv\modules\core\src\copy.cpp:1026: error: (-215:Assertion failed) top >= 0 && bottom >= 0 && left >= 0 && right >= 0 && _src.dims() <= 2 in function 'copyMakeBorder'

as an unrelated sidenote, cv::Mat will silently wrap around, given more than 512 channels:

cv::Mat m(10,10,CV_8UC(600)); // no exception !
cout << m.channels() << endl;

88

which isn't nice, either.

Issue submission checklist
  • I report the issue, it's not a question an error he
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc
@alalek
Copy link
Member

alalek commented May 12, 2021

With Python use cv.utils.dumpInputArray() to see converted parameter internals.

CV_8UC(...) is a macro. It is caller responsibility to check passed values. There is no problem with cv::Mat itself (as wrong value is passed).

@berak
Copy link
Contributor Author

berak commented May 12, 2021

ah, that's indeed useful (we can see, that the dims() are changing, like the exeption in the 1st post):

>>> a = np.ones((10,10,600),np.uint8)
>>> cv2.utils.dumpInputArray(a)
'InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=60000 dims(-1)=3 size(-1)=[10 10 600] type(-1)=CV_8UC1'
>>> b = np.ones((10,10,60),np.uint8)
>>> cv2.utils.dumpInputArray(b)
'InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=100 dims(-1)=2 size(-1)=10x10 type(-1)=CV_8UC60'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants