簡體   English   中英

opencv代碼錯誤:C ++

[英]Error in opencv code: 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_noise_planes或將其設置為輸入的大小。

我想高斯Mattype是這里的問題。 如果不確定img_a類型,則可以移動gauss_noise創建並使其取決於拆分通道的類型。 例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM