私はポインターによる平均スムージングを実行しようとしています。イメージを使用したイメージのスムージングポインタを使用したスムージング
私の目的は、ポインタで画像を処理することです。
これは私がコード化したものです。
コード:
int main() {
Mat img = imread("best-testimg.jpg");
Mat src = img.clone();
int const templeteWindowSize = 3;
int tr = templeteWindowSize >> 1; //templateRegion
int bb = tr; //backgroundBorder
//create large size image for bounding box;
Mat im;
copyMakeBorder(src, im, bb, bb, bb, bb, cv::BORDER_DEFAULT); //left= right= bottom= top = border = bb
//=========================================================
Mat dest = Mat::zeros(src.size(), src.type());
int T = templeteWindowSize * templeteWindowSize;
int count = T - 1;
//step of template to image
const int cstep = im.step - templeteWindowSize;
for (int j = 0; j < src.rows; j++) {
//src ptr
uchar* d = dest.ptr(j);
for (int i = 0; i < src.cols; i++) {
uchar* tprt = im.data + im.step*(tr + j) + (tr + i); //pointer of image data amd step at 3x3
double tweight = 0.0;
for (int n = templeteWindowSize; n--;)
{
for (int m = templeteWindowSize; m--;)
{
tweight += *tprt++;
}
tprt += cstep;
}
tweight /= 9;
*(d++) = (saturate_cast<uchar>(tweight));
}//i
}//j
imshow("dest", dest);
waitKey(0);
return 0;
}
入力画像:
出力イメージ
問題:画像がポインタでうまく処理されません。コードで私の間違いを訂正することはできますか?ありがとう
誰でも私のコードを修正するのに手伝ってください。ありがとう。
は、次のようなOpenCVの関数を使用して画像を滑らかにするために、多様な線形フィルタを適用しよう.html –
私はポインタで作業することに興味があります。平均スムージングのみ。 – Abc