opencv 求图像梯度值,该怎么处理
答案:1 悬赏:70 手机版
解决时间 2021-04-06 15:43
- 提问者网友:椧運幽默
- 2021-04-06 05:48
opencv 求图像梯度值,该怎么处理
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-04-06 06:42
求助!!不甚感激!!
------解决方案--------------------------------------------------------
你得到的dst不就是算过的包含梯度信息的图像吗,实在不行你就自己写代码来取梯度也行,就几行代码而已
另外,附上我的一份不完整的代码,仅供参考啊
IplImage *pSrc = cvLoadImage(图片路径,..,..);//参数不说了
int nWidth = pSrc-width;
int nHeight = pSrc-height;
int nLineBytes = pSrc-widthStep;
uchar *uData = reinterpret_cast<uchar *(pSrc-imageData);
uchar uNeighbourPixel[8];//对于Sobel算子,计算的是8领域
for(int j = 1; j < nHeight - 1; j++)
for(int i = 1; i < nWidth - 1; i++){{uNeighbourPixel[0] = uDataY[(j - 1) * nLineBytesY + i - 1];
uNeighbourPixel[1] = uDataY[(j - 1) * nLineBytesY + i];
uNeighbourPixel[2] = uDataY[(j - 1) * nLineBytesY + i + 1];
uNeighbourPixel[3] = uDataY[j * nLineBytesY + i - 1];
uNeighbourPixel[4] = uDataY[j * nLineBytesY + i + 1];
uNeighbourPixel[5] = uDataY[(j + 1) * nLineBytesY + i - 1];
uNeighbourPixel[6] = uDataY[(j + 1) * nLineBytesY + i];
uNeighbourPixel[7] = uDataY[(j + 1) * nLineBytesY + i + 1];
uData[j * nLineBytes + i] = abs((1 * uNeighbourPixel[0] + 2 * uNeighbourPixel[1] + 1 * uNeighbourPixel[0]) - (1 * uNeighbourPixel[5] + 2 * uNeighbourPixel[6] + 1 * uNeighbourPixel[7]));}}最终uData数组里保存的就是Sobel算子计算的梯度信息了。
希望能帮到您!
------解决方案--------------------------------------------------------
你得到的dst不就是算过的包含梯度信息的图像吗,实在不行你就自己写代码来取梯度也行,就几行代码而已
另外,附上我的一份不完整的代码,仅供参考啊
IplImage *pSrc = cvLoadImage(图片路径,..,..);//参数不说了
int nWidth = pSrc-width;
int nHeight = pSrc-height;
int nLineBytes = pSrc-widthStep;
uchar *uData = reinterpret_cast<uchar *(pSrc-imageData);
uchar uNeighbourPixel[8];//对于Sobel算子,计算的是8领域
for(int j = 1; j < nHeight - 1; j++)
for(int i = 1; i < nWidth - 1; i++){{uNeighbourPixel[0] = uDataY[(j - 1) * nLineBytesY + i - 1];
uNeighbourPixel[1] = uDataY[(j - 1) * nLineBytesY + i];
uNeighbourPixel[2] = uDataY[(j - 1) * nLineBytesY + i + 1];
uNeighbourPixel[3] = uDataY[j * nLineBytesY + i - 1];
uNeighbourPixel[4] = uDataY[j * nLineBytesY + i + 1];
uNeighbourPixel[5] = uDataY[(j + 1) * nLineBytesY + i - 1];
uNeighbourPixel[6] = uDataY[(j + 1) * nLineBytesY + i];
uNeighbourPixel[7] = uDataY[(j + 1) * nLineBytesY + i + 1];
uData[j * nLineBytes + i] = abs((1 * uNeighbourPixel[0] + 2 * uNeighbourPixel[1] + 1 * uNeighbourPixel[0]) - (1 * uNeighbourPixel[5] + 2 * uNeighbourPixel[6] + 1 * uNeighbourPixel[7]));}}最终uData数组里保存的就是Sobel算子计算的梯度信息了。
希望能帮到您!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯