Convert opencv 3 code to opencv 4

Hi, I have some opencv 3 code as below, how can I conver them to opencv 4? THanks a lot

 CvMat * PW0 = cvCreateMat(3, 3, CV_64F);

  double pw0tpw0[3 * 3], dc[3], uct[3 * 3];
  CvMat PW0tPW0 = cvMat(3, 3, CV_64F, pw0tpw0);
  CvMat DC      = cvMat(3, 1, CV_64F, dc);
  CvMat UCt     = cvMat(3, 3, CV_64F, uct);

  for(int i = 0; i < number_of_correspondences; i++)
    for(int j = 0; j < 3; j++)
      PW0->data.db[3 * i + j] = pws[3 * i + j] - cws[0][j];

  cvMulTransposed(PW0, &PW0tPW0, 1);
  cvSVD(&PW0tPW0, &DC, &UCt, 0, CV_SVD_MODIFY_A | CV_SVD_U_T);

  cvReleaseMat(&PW0);

that’s not opencv3 code, but friggin 1.0 c-api (dead since A LONG TIME)

@berak . THanks. Could you please show me how to change the code to opencv 4?

https://docs.opencv.org/master/de/d7a/tutorial_table_of_content_core.html

I’m sure you can translate that stuff adequately.

docs for that old stuff should be in the docs to v2.4.

it’s just a few Mats. use regular Mat constructors that use their own memory. get rid of the double arrays.

pws and cws aren’t shown so only you know what they contain.

How about SVD? I could not find CV_SVD_U_T in opencv 4…

SVD is still there. it’s a class now.

it’s not even in the 2.4 docs

questions:

  • what does this code try to achieve ?
  • what are the inputs, and what are you doing with the result ?
  • why is there no V ?
  • why does it want to transpose U (instead of V)?
  • CV_SVD_U_T was defined as 2, which would be SVD_NO_UV today (meaning, it only calculates singular W values, not U at all)

maybe you can run the original c code with some random dummy values, and show the output (& compare it to the c++ version) ? you probably have to skip the flag, and transpose U manually (but this is just a guess)

found some older docs

2.x docs don’t list it, 3.x docs do…
https://docs.opencv.org/3.4/d2/df8/group__core__c.html#ga6593e7074d83a1586b43e5385495dfd6

I have found the full original code was there,
it’s solver from ORB_SLAM2.