Comments (3)
Maybe duplicated #25165
from opencv.
Umm, I read again. This behavious has been changed after 4.9.0, but I think OpenCV 4.9.0 behavious is correct
( More precisely, the case where src2 is Scalar is not described in the multiply function... )
- When using an integer as the multiplier, versions 4.5 to 4.8 only the blue channel is correctly multiplied by 2.0, while the green and red channels' pixel values become zero.
- When using a one-dimensional NumPy array (np.array([2.0])) as the multiplier, versions 4.5 to 4.8 correctly multiply all channels (BGR) of the image by the given value. However, in OpenCV 4.9, only the blue channel is correctly multiplied, while the green and red channels' pixel values are set to zero.
Please could you see atirhmertric function behavious at https://docs.opencv.org/4.9.0/d2/de8/group__core__array.html#ga10ac1bfb180e2cfda1701d06c24fdbd6 ?
- Precondition : src1(I) =
[50, 50, 50]
- Try to execute : dst = multiply( src1 , src2).
- If src2 =
2
then dst =[50x2, 50x2, 50x2]
=[100, 100, 100]
- If src2 =
[2,3,4]
then dst =[50x2, 50x3, 50x4]
=[100, 150, 200]
- If src2 =
[2]
then dst =[50x2, 50x0, 50x0]
=[100, 0, 0]
From https://docs.opencv.org/4.9.0/d2/de8/group__core__array.html#ga979d898a58d7f61c53003e162e7ad89f
Note
Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.
(Python) Be careful to difference behaviour between src1/src2 are single number and they are tuple/array. multiply(src,X) means multiply(src,(X,X,X,X)). multiply(src,(X,)) means multiply(src,(X,0,0,0)).
And This behavious is same as C++
#include <iostream>
#include <opencv2/core.hpp>
int main(void)
{
cv::Mat gray_img(400,400,CV_8UC3, cv::Scalar::all(50));
cv::Mat tmp_img_int;
cv::multiply(gray_img, 2, tmp_img_int);
std::cout << "INT = " << cv::format(tmp_img_int(cv::Rect(0,0,2,2)), cv::Formatter::FMT_NUMPY) << std::endl;
cv::Mat tmp_img_scalar;
cv::multiply(gray_img, cv::Scalar(2), tmp_img_scalar);
std::cout << "SCALAR = " << cv::format(tmp_img_scalar(cv::Rect(0,0,2,2)), cv::Formatter::FMT_NUMPY) << std::endl;
return 0;
}
Result
$ make && ./a.out
g++ main.cpp -o a.out \
-I/usr/local/include/opencv4 \
-lopencv_core
INT = array([[[100, 100, 100], [100, 100, 100]],
[[100, 100, 100], [100, 100, 100]]], dtype='uint8')
SCALAR = array([[[100, 0, 0], [100, 0, 0]],
[[100, 0, 0], [100, 0, 0]]], dtype='uint8')
from opencv.
@cocositu If OK, please could you close this issue ?
from opencv.
Related Issues (20)
- all: http://opencv.org/license.html returns 404 status. HOT 3
- Docs for Python imshow example improvement
- HWASan error in BufferArea tests
- OpenCV 4.10.0 segfault when using OpenVINO 2024.0.0 HOT 2
- phaseCorrelate fails with larger 16bit images
- dnn 5.x with OpenVINO 2022.1 backend doesn't pass integer tests because of the NaryEltwise layer
- HWASan error in G-API core test HOT 1
- CMake Error at cmake/OpenCVDetectCUDAUtils.cmake:297 (list): list GET given empty list HOT 8
- error: (-216:No CUDA support) OpenCV was not built to work with the selected device. Please check CUDA_ARCH_PTX or CUDA_ARCH_BIN in your build configuration. in function 'initCUDABackend'a support HOT 2
- Cant install latest opencv due to undefined reference (libcublas)
- G-API error in VASObjectTracker test HOT 1
- G-API error in some PatternMatchingIntegrationE2E tests HOT 1
- Does OpenCV really support FFmpeg 5.0+ on Windows?
- opencv still uses Concurrency Runtime in parallel_for_xxx functions on Windows
- Inconsistent result from segmentation sample for u2netp model HOT 1
- Possible memory leak in fastNlMeansDenoisingColored
- Opencv 4.5.4 with Cuda Build Error HOT 2
- dnn/video: TrackerVit crashes when target is lost
- ONNX does not work for BMM function HOT 8
- ONNX broken for identity function HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv.