Mat画像を宣言し、値を割り当てます。単一チャンネルOpenCV Mat.at <>が間違った値を返します
Mat magnitude = Mat(gradient_columns.cols, gradient_columns.rows, CV_64FC1);
for(int i = 0; i < gradient_columns.cols; i++)
{
for(int j = 0; j < gradient_columns.rows; j++)
{
magnitude.at<double>(Point(i,j)) = (double)hypot(gradient_columns.at<double>(Point(i,j)), gradient_rows.at<double>(Point(i,j)));
}
}
上記マットを印刷:
cout << "M = " << magnitude << endl;
結果:
M = [0, 0, 0.1257399049164523, 12.36316814720732, 12.50461780753356, 0.2674320707434279, 10.39230484541326, 12.03299037437945, 5.430256687374658,
12.03299037437945, 4.684492386402418, 4.72934192083521, 12.16431633381293, 5.397674732957373, 12.30042244512288, 10.25834261322606, 0.3944487245360109,
12.16431633381293, 11.84297951775486, 12.44187210544911, 12.10132213098092,
0.4088817310696626, 10.15078660267586, 12.09573607646389, 2.076275433221507, 0, 0.1257399049164523, 0, 0.1257399049164523, 0;
.....
.....]
上記結果は完全に正確であると期待されます。私は、個々の値を印刷しようとした場合
は、しかし、私は間違った結果を得る:
cout.precision(20);
cout << "CHANNELS: " << magnitude.channels() << endl;
cout << magnitude.at<double>(Point(0, 2)) << endl;
cout << magnitude.at<double>(Point(0, 3)) << endl;
cout << magnitude.at<double>(Point(0, 4)) << endl;
cout << magnitude.at<double>(Point(0, 5)) << endl;
Result | Actual Value:
CHANNELS: 1
0.062870 | 0.1257399049164523,
0.000000 | 12.36316814720732,
0.031404 | 12.50461780753356,
0.000000 | 0.2674320707434279
私はそのいくつかのデータ型変換の問題を理解しますが、もし誰もが任意の解決策を提案することができますか?
ありがとうございました。
'Mat.at(Point(i、j))'の代わりに 'Mat.at (j、i)' –
Sunreef
と書くと、パフォーマンスを向上させるには、両方のループを交換する必要があります(外側のループの行を繰り返します)。 – Micka