opencv triangulatePoints() giving NaN values
I'm trying to implement standard Structure from Motion code but the triangulatePoints is resulting in NaN values. I do the following steps -
- get ORB features for image 1 and image 2.
- Match the features.
- get essential matrix from the matched features and camera intrinsic info available, using findEssentialMat()
- using recoverPose() to get pose of camera 2. Camera 1 is assumed to be at the origin.
- get projection matrices for camera1 and camera2.
- use triangulatePoints() to get 3D points.
I have tried the Matlab triangulate() function as well with the projection matrices for camera1 and camera2 as well as matched points obtained above. In case of Matlab I get good results. But using opencv in C++ (Opencv 3.3) I get NaN values.
I'm not sure what's wrong with triangulate, but you can try using THIS module, which can handle more than two cameras.
Can you post your projection matrices, a few points, and the results you expect?
Here are the two matrices - Cam1 = [1000 0 500 0 0 1000 500 0 0 0 1 0]
cam2 = [720.6221455223817, -103.3307817561171, 848.5437366007654, -951.8867514749264; -177.5149711798716, 950.5881039101392, 561.1333992122866, -148.7626862924559; -0.3953628981993094, -0.08757713995677291, 0.9143404307392484, 0.0602672098669313]
A few points - image1 - [363, 240] [226, 308] [204, 308] [217, 310] [260, 281]
image2 - [325.2, 264] [157.2, 324] [132, 324] [147, 325] [198, 301.2]
result i expect (that i get from matlab) - -0.2931 -0.55565 2.1387 -0.5184 -0.36494 1.893 -0.54948 -0.35738 1.8569 -0.53127 -0.35903 1.8787 -0.46763 -0.42688 1.9486