OpenCv & EmguCv equavalent method?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 10:07:06

问题


As berak said in the comments, it seems this code is deprecated

In Opencv there is a method "cvmget", the sample usage is:

bool niceHomography(const CvMat * H)
{
  const double det = cvmGet(H, 0, 0) * cvmGet(H, 1, 1) - cvmGet(H, 1, 0) * cvmGet(H, 0, 1);
  if (det < 0)
    return false;

  const double N1 = sqrt(cvmGet(H, 0, 0) * cvmGet(H, 0, 0) + cvmGet(H, 1, 0) * cvmGet(H, 1, 0));
  if (N1 > 4 || N1 < 0.1)
    return false;

  const double N2 = sqrt(cvmGet(H, 0, 1) * cvmGet(H, 0, 1) + cvmGet(H, 1, 1) * cvmGet(H, 1, 1));
  if (N2 > 4 || N2 < 0.1)
    return false;

  const double N3 = sqrt(cvmGet(H, 2, 0) * cvmGet(H, 2, 0) + cvmGet(H, 2, 1) * cvmGet(H, 2, 1));
  if (N3 > 0.002)
    return false;

  return true;
}

is there any method in like cvmget in EmguCV?


回答1:


cvmget function returns the element of the single channel array. This function is a fast replacement for GetReal2D

In EmguCV you can use the cvGetReal2D method of the CvInvoke class

So, the code in the link you provided should be like:

    bool niceHomography(Image<Gray, byte> H)
    {
        double det = CvInvoke.cvGetReal2D(H, 0, 0) * CvInvoke.cvGetReal2D(H, 1, 1) - CvInvoke.cvGetReal2D(H, 1, 0) * CvInvoke.cvGetReal2D(H, 0, 1);
        if (det < 0)
            return false;

        double N1 = Math.Sqrt(CvInvoke.cvGetReal2D(H, 0, 0) * CvInvoke.cvGetReal2D(H, 0, 0) + CvInvoke.cvGetReal2D(H, 1, 0) * CvInvoke.cvGetReal2D(H, 1, 0));
        if (N1 > 4 || N1 < 0.1)
            return false;

        double N2 = Math.Sqrt(CvInvoke.cvGetReal2D(H, 0, 1) * CvInvoke.cvGetReal2D(H, 0, 1) + CvInvoke.cvGetReal2D(H, 1, 1) * CvInvoke.cvGetReal2D(H, 1, 1));
        if (N2 > 4 || N2 < 0.1)
            return false;

        double N3 = Math.Sqrt(CvInvoke.cvGetReal2D(H, 2, 0) * CvInvoke.cvGetReal2D(H, 2, 0) + CvInvoke.cvGetReal2D(H, 2, 1) * CvInvoke.cvGetReal2D(H, 2, 1));
        if (N3 > 0.002)
            return false;

        return true;
    }



PS. Be sure that your array(Image) has just one channel(Grayscale) otherwise a runtime error will be raised. If your array has multiple channels use the cvGet2D method instead.

OpenCV Documentation: mGet



来源:https://stackoverflow.com/questions/25596981/opencv-emgucv-equavalent-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!