MrrCat 2019-02-18 11:07 采纳率: 0%
浏览 1640

Opencv使用Sobel与cvSobel计算的结果不一样吗?

程序见下,我测试了cvMat和Mat的数据是一样的,但是求出来的dx和dy值是不一样的,是我调用的有问题还是本身存在的问题。

#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void main()
{
    Mat src1 =imread("D:\\data_img\\MatchImage\\2.jpg",0);

    Mat gx1, gy1;
    Sobel(src1, gx1, CV_16S, 1, 0, 3);      //gradient in X direction           
    Sobel(src1, gy1, CV_16S, 0, 1, 3);  //gradient in Y direction

    IplImage imgTmp= src1;

    IplImage *templateImage = cvCloneImage(&imgTmp);

    CvMat *gx = 0;      //Matrix to store X derivative
    CvMat *gy = 0;      //Matrix to store Y derivative
    CvMat *nmsEdges = 0;//Matrix to store temp restult
    CvSize Ssize;
    const short* _sdx;
    const short* _sdy;
    const uchar* _src;
    short fdx, fdy, fdx0, fdy0;
    // Convert IplImage to Matrix for integer operations
    CvMat srcstub, *src = (CvMat*)templateImage;
    src = cvGetMat(src, &srcstub);

    Ssize.width = src->width;
    Ssize.height = src->height;

    gx = cvCreateMat(Ssize.height, Ssize.width, CV_16SC1);      //create Matrix to store X derivative
    gy = cvCreateMat(Ssize.height, Ssize.width, CV_16SC1);      //create Matrix to store Y derivative
    cvSobel(src, gx, 1, 0, 3);      //gradient in X direction           
    cvSobel(src, gy, 0, 1, 3);  //gradient in Y direction
    for (int i = 0; i < src1.rows; i++)
    {
        uchar *p = src1.ptr<uchar>(i);
        short *pdx = gx1.ptr<short>(i);
        short *pdy = gy1.ptr<short>(i);
        for (int j = 0; j < src1.cols; j++)
        {
            _sdx = (short*)(gx->data.ptr + gx->step*i);
            _sdy = (short*)(gy->data.ptr + gy->step*i);
            _src= (uchar*)(src->data.ptr + src->step*i);

            uchar usrc = p[j];
            uchar usrc2= _src[j];
            fdx0 = pdx[j];
            fdx = _sdx[j]; 

            fdy0 = pdy[j];
            fdy = _sdy[j];   
            if (fdy0 !=  fdy || fdx0 !=  fdx )
            {
                int qqqqqqq = 1111;
            }
            if (usrc != usrc2)
            {
                int qqqqqqq = 1111;
            }
        }
    }
}
  • 写回答

1条回答 默认 最新

  • MrrCat 2019-02-18 11:45
    关注

    Sobel和cvSobel的结果确实不一样,不过只在图像的border(即:第一行,第一列,最后一行和最后一列)不同,其余部分相同。

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?