MedianBlur randomly fails with OpenCV error
See original GitHub issueThis issue is a bit mysterious from my point of view, as it’s kind of complicated to reproduce it a single try.
In [1]: from albumentations import MedianBlur
...: import numpy as np
...:
...: success, fail = 0, 0
...: for _ in range(100):
...: img = np.random.rand(100, 100)
...: try:
...: img = MedianBlur()(image=img).get('image')
...: success += 1
...: except Exception:
...: fail += 1
...: print(success, fail)
...:
OpenCV Error: Assertion failed (src.depth() == CV_8U && (cn == 1 || cn == 3 || cn == 4)) in medianBlur, file /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/smooth.cpp, line 3538
OpenCV Error: Unsupported format or combination of formats () in medianBlur, file /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/smooth.cpp, line 3529
OpenCV Error: Unsupported format or combination of formats () in medianBlur, file
// some errors removed from the log
48 52
I’ve reproduced this stochastic issue on two different computers, both using opencv-python==3.3.0.10
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
medianBlur Assertion error (-215) - Python - OpenCV Forum
Hi, I am trying to run some code to perform a median blur. When I run: differenceImage = cv2.medianBlur(differenceImage,17) I get an error: ......
Read more >OpenCV Error: Assertion failed (ksize.width ... - Stack Overflow
As I understood from the trace, you are only allowed to use new Size(x,y) where x and y are odd.
Read more >Python | Image blurring using OpenCV - GeeksforGeeks
Median Blur : The Median Filter is a non-linear digital filtering technique, often used to remove noise from an image or signal.
Read more >OpenCV Smoothing Image Filters - Medium
medianBlur ). Like the blur filter Median Filter takes the median value all the values in the kernel and applies to the center...
Read more >error: (-215:assertion failed) !_src.empty() in function 'cvtcolor'
Opencv (in python) gives error - !_src.empty() in function 'cv2::cvtColor ' ... BTW: Sometimes cv2 has problem to find haarcascades file.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think there are 2 reasons why those errors appear:
np.random.rand
generates ndarrays with the float64 data type. This data type is not supported bycv2.medianBlur
which is used internally inMedianBlur
.cv2.medianBlur
are 3 and 5. Link to the OpenCV docsThis code that uses float32 inputs and ksize values 3 and 5 work without errors for me:
I am afraid as long as we are using OpenCV functions there is nothing we can do to support float64 inputs and ksize values larger than 5.
Maybe we should check the data type of input images in all our augmentations and raise an exception if the input data type is not supported, so users won’t get those cryptic OpenCV errors? @albu @ternaus what do you think?
@creafz may be, it can be replaced with
cv2.filter2D
with a manually created filter?