cos function calculation in Opencv

asked 2016-03-15 04:14:37 -0600

I need to calculate cos of a (float) matrix (14 rows and one column), is there any function for it in OpenCV that gives the same result as in MATLAB?

edit retag flag offensive close merge delete

Comments

1

I don't think this function exist.

static Mat Cos(Mat m)
{
    if (m.depth() != CV_32F )
    {
        cv::Exception e;
        e.code = -1;
        e.msg = "Mat must be float for Cos function";
        throw e;
    }


    Mat t(m.size(),CV_32FC(m.channels()));

    for (int i = 0; i < m.rows; i++)
        float *ptr1 = (float*)m.ptr(i);
        float *ptr2 = (float*)t.ptr(i);
        for (int j=0;j<m.cols*m.channels();j++,ptr1++,ptr2++)
            *ptr2 = cos(*ptr1);
    }

    return t;
}
LBerger gravatar imageLBerger ( 2016-03-15 07:30:10 -0600 )edit

Thankyou but I need to calculate power, absolute, sinc and exponents too. Do I need to write the codes for all of them

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-03-15 12:56:06 -0600 )edit
1
LBerger gravatar imageLBerger ( 2016-03-15 13:25:41 -0600 )edit

Thankyou. I visited this page and forgot it while coding. I couldn't find any reference for sinc function in OpenCV.

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-03-15 13:49:20 -0600 )edit
1

sinc or

  if abs(*ptr1)<1e-7
       *ptr2=1;
else
     *ptr2 =sin(*ptr1)/*ptr1;
LBerger gravatar imageLBerger ( 2016-03-15 14:07:22 -0600 )edit

@LBerger please help me here link text

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-06-16 02:17:59 -0600 )edit