-
-
Notifications
You must be signed in to change notification settings - Fork 55.7k
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
Strange behaviour of cv2.add operation #25165
Comments
Check if there are any known compatibility issues with OpenCV version 4.9.0.80 on Ubuntu 22.04.4 LTS (WSL). The issue may be platform-specific.(Try this first)If the issue is critical for your work, you may consider downgrading OpenCV to version 3.4.18.65 as a temporary solution until the problem is resolved in a future release. If the issue is Open, kindly assign the issue to me so that I can work upon it and dig deeper to find the exact issue and the root cause. |
Anyways, someone with more experience needs to look into this and ascertain if this is really a issue or not. Currently I don't have time to look into this otherwise I myself would have digged in deeper into this. |
As x and y are not 2 or 3 dimensional array opencv python binding make casting
result array([[255]], dtype=uint8) result for cv.add(10,250) and
|
I'm sorry, this bug is occured by #24074 patch. Following code is temporary disable this patch for add function. kmtr@kmtr-None:~/work/opencv$ git diff
diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py
index d4a5b26a9f..d52f5fdfbf 100755
--- a/modules/python/src2/hdr_parser.py
+++ b/modules/python/src2/hdr_parser.py
@@ -539,12 +539,11 @@ class CppHeaderParser(object):
funcname = self.get_dotted_name(funcname)
# see https://github.com/opencv/opencv/issues/24057
- is_arithm_op_func = funcname in {"cv.add",
+ is_arithm_op_func = funcname in {"Xcv.add",
"cv.subtract",
"cv.absdiff",
"cv.multiply",
"cv.divide"}
-
if not self.wrap_mode:
decl = self.parse_func_decl_no_wrap(decl_str, static_method, docstring)
decl[0] = funcname kmtr@kmtr-None:~/work/build4-main_python3.12.0$ python issue25165.py
[[255]]
kmtr@kmtr-None:~/work/build4-main_python3.12.0$ cd ../opencv I think it would be difficult to fix the previous problem ( #24057 ) and this problem at the same time. |
the Stack Overflow questions that those people came from:
I'd say it's not a bug but an unexpected feature that trips newbies up because they aren't aware of how numpy array shapes are translated into |
I challenged to make patch to avoid convertion single long/double argument to cv::Mat for add/subtract/... Currently python binding doesn't support changing argument-types. This patch is able to use manual some implementation functions instead of auto-generation functions. However, this brute-force fix may not be suitable to maintainance for us. |
System Information
OpenCV python version: 4.9.0.80
Operating System / Platform: Ubuntu 22.04.4 LTS (WSL)
Python version: 3.10.12
Detailed description
I am expecting that cv2.add will truncate the results of addition between [0, 255], but that's not happening in cv2 4.9.0.80 as can be seen below :
I tested the same behavior in other environment which is having cv2 3.4.18.65 and there it is working as expected.
Steps to reproduce
To repro the problem, just follow the OpenCV tutorials here with cv2 version 4.9.0.80
Issue submission checklist
The text was updated successfully, but these errors were encountered: