2016-12-29 43 views
1

画像の単一チャンネルにのみガウスノイズを追加しようとしています。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(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_planeschannel=1を持っているとimg_aは3つのチャンネルがあり、あるとして、私はそこに3を入れているので、私はに私のaddweighted()機能を変更しました合併によって作られた。

+0

「img_a」の深さは? 'CV_16SC3'の場合を除き、' addWeighted'に出力の深さを指定する必要があります。 – beaker

答えて

1

ここでは、Mattypeがガウスの問題であると思います。 img_aタイプが不明な場合は、gauss_noiseの作成を移動して、分割チャンネルのタイプに応じて変更することができます。例:

+0

私の 'gauss_noise'定義を変更しました。これは編集と同じエラーを返します –

+0

私はaddweighted関数に行った変更を取り除きました。ありがとう! –

1

img_a_noise_planesのように見えるエラーメッセージに基づいて、入力が行われたり、入力のサイズに設定されたりしませんでした。

+0

分割が必要な割り当てを行う必要があるので、これは当てはまりません – Dusteh

関連する問題