我想向圖像中的單個通道添加高斯噪聲。這是我寫的代碼:在opencv代碼中的錯誤:C++
double Mean = 0.0;
double StdDev = 10.0;
Mat gauss_noise = Mat(img_a.size(), CV_16SC1);
randn(gauss_noise, Scalar::all(Mean), Scalar::all(StdDev));
Mat img_a_noise_planes[3];
split(img_a, img_a_noise_planes);
addWeighted(gauss_noise, 1.0, img_a_noise_planes[1], 1.0, 1.0, img_a_noise_planes[1]);
merge(img_a_noise_planes, 3, img_a);
我有在代碼中addWeighted()
行的錯誤。
錯誤:
OpenCV Error: Bad argument (When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified) in arithm_op, file /home/cortana/Libraries/opencv/modules/core/src/arithm.cpp, line 683
terminate called after throwing an instance of 'cv::Exception'
what(): /home/cortana/Libraries/opencv/modules/core/src/arithm.cpp:683: error: (-5) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function arithm_op
Aborted (core dumped)
我在做什麼錯在這裏?
編輯: img_a_noise_planes[1]
的顏色通道價值是1
。所以我改變了我的addweighted()
功能:
addWeighted(gauss_noise, 1.0, img_a_noise_planes[1], 1.0, 1.0, img_a_noise_planes[1], 1);
現在的錯誤是:
OpenCV Error: Assertion failed (mv[i].size == mv[0].size && mv[i].depth() == depth) in merge, file /home/cortana/Libraries/opencv/modules/core/src/convert.cpp, line 222
terminate called after throwing an instance of 'cv::Exception'
what(): /home/cortana/Libraries/opencv/modules/core/src/convert.cpp:222: error: (-215) mv[i].size == mv[0].size && mv[i].depth() == depth in function merge
Aborted (core dumped)
在合併功能,每個img_a_noise_planes
有channel=1
,我已經把3在那裏爲img_a
有3個通道,併合並而成。
'img_a'的深度是多少?除非它是'CV_16SC3',否則你需要在'addWeighted'中指定輸出深度。 – beaker