gpt4 book ai didi

c++ - opencv错误代码: C++

转载 作者:太空宇宙 更新时间:2023-11-03 22:25:24 28 4
gpt4 key购买 nike

我正在尝试将高斯噪声添加到图像中的单个 channel 。这是我写的代码:

  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] 中的颜色 channel 值为 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 个 channel 并且是通过合并。

最佳答案

我猜测高斯 Mattype 是这里的问题。如果您不确定 img_a 类型,那么您可以移动 gauss_noise 创建并使其依赖于分离 channel 的类型。例如:

Mat gauss_noise = Mat(img_a.size(), img_a_noise_planes[1].type());

关于c++ - opencv错误代码: C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41386082/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com