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

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(即:第一行,第一列,最后一行和最后一列)不同,其余部分相同。

    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境