JNI之OpenCV卷积操作
// [
// 0,-1,0,
// -1,5,-1,
// 0,-1,0
// ]
// 卷积操作
Mat source;
bitmap2mat(env, source, bitmap);
// 生成一个全零矩阵
Mat dest = Mat::zeros(source.size(), source.type());
// 获取列数
int cols = (source.cols - 1) * source.channels();
int rows = source.rows;
int offset_x = source.channels();
for (int row = 1; row < rows - 1; row++) {
// 上一行
uchar *pre = source.ptr<uchar>(row - 1);
// 当前行
uchar *current = source.ptr<uchar>(row);
// 下一行
uchar *next = source.ptr<uchar>(row + 1);
// 输出
uchar *output = dest.ptr<uchar>(row);
for (int col = offset_x; col < cols; col++) {
output[col] = saturate_cast<uchar>(
5 * current[col] - current[col - offset_x] - current[col + offset_x] - pre[col] - next[col]);
}
}
// Mat dest;
// Mat kennel = (Mat_<char>(3,3) << 0,-1,0,-1,5,-1,0,-1,0);
// filter2D(source,dest,source.depth(),kennel);
mat2bitmap(env,dest,bitmap);
版权声明:本文为shuzhuchengfu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。