我想通過指針執行平均平滑。使用圖像平滑過程圖像指針 - 需要幫助來糾正我的代碼
我的目標是通過指針處理圖像。
這就是我編碼。
代碼:
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函數如圖像: 模糊 高斯模糊 medianBlur 雙邊濾波器 http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter .html –
請讓我有興趣使用指針。僅平均平滑。 – Abc