# Opencv - 立体声系统的三角测量起源(Opencv - Triangulation origin with stereo system)

``` 我正在使用立体声系统，因此我试图获得某些点的世界坐标。 我可以为每个摄像机进行特定校准，然后计算旋转矩阵和平移向量。 最后我进行了三角测量，但我不确定世界坐标的起源。
正如您在我的图中所看到的，值对应于深度值，但它们平坦时应接近400。 所以我认为原点是左相机，这就是为什么它会变化......

我的代码与我的投射数组和三角函数：
```#C1 and C2 are the cameras matrix (left and rig)
#R_0 and T_0 are the transformation between cameras
#Coord1 and Coord2 are the correspondant coordinates of left and right respectively
P1 = np.dot(C1,np.hstack((np.identity(3),np.zeros((3,1)))))

P2 =np.dot(C2,np.hstack(((R_0),T_0)))

for i in range(Coord1.shape[0])
z = cv2.triangulatePoints(P1, P2, Coord1[i,],Coord2[i,])
```
我的相机呈现一个角度，Z轴方向（深度方向）与我的表面不正常。 我想要从基线方向的深度。 所以我必须转动我的观点？
I m using a stereo system and so i m trying to get world coordinates of some points. I can do it with specific calibration for each camera and then i calculate rotation matrix and translation vector. And finally i triangulate but i m not sure of the origin of the world coordinates.
As you can see on my figure, values correspond to depth value but they shoud be close of 400 as it is flat. So i suppose that the origin is the left camera that s why it variates...

A piece of my code with my projective arrays and triangulate function :
```#C1 and C2 are the cameras matrix (left and rig)
#R_0 and T_0 are the transformation between cameras
#Coord1 and Coord2 are the correspondant coordinates of left and right respectively
P1 = np.dot(C1,np.hstack((np.identity(3),np.zeros((3,1)))))

P2 =np.dot(C2,np.hstack(((R_0),T_0)))

for i in range(Coord1.shape[0])
z = cv2.triangulatePoints(P1, P2, Coord1[i,],Coord2[i,])
```
My cameras present an angle, the Z axis direction (direction of the depth) is not normal to my surface. And i want the depth from the baseline direction. So i have to rotate my points?

## 最满意答案

``` 在以下代码中，points4DNorm将包含世界坐标中的3D点。 我根本没有使用矫正器，我只使用了几个2d / 3d点对，然后在这些对上解决了PnPRansac。
```// rotMat1, rotMat2,tvec1 and tvec2 are retrieved from solvePnPRansac and Rodrigues
Mat points4D;
rotMat1.copyTo(myCam1.ProjectionMat(Rect(0, 0, 3, 3)));
tvec1.copyTo(myCam1.ProjectionMat(Rect(3, 0, 1, 3)));

rotMat2.copyTo(myCam2.ProjectionMat(Rect(0, 0, 3, 3)));
tvec2.copyTo(myCam2.ProjectionMat(Rect(3, 0, 1, 3)));

myCam1.ProjectionMat = myCam1.NewCameraMat* myCam1.ProjectionMat;
myCam2.ProjectionMat = myCam2.NewCameraMat* myCam2.ProjectionMat;
triangulatePoints(myCam1.ProjectionMat, myCam2.ProjectionMat, balls12d, balls22d, points4D);
Mat points4DNorm;
for (int k = 0; k < points4D.cols;k++)
{
points4D.at<float>(0, k) = (points4D.at<float>(0, k) / points4D.at<float>(3, k))/304.8;
points4D.at<float>(1, k) = (points4D.at<float>(1, k) / points4D.at<float>(3, k)) / 304.8;
points4D.at<float>(2, k) = (points4D.at<float>(2, k) / points4D.at<float>(3, k)) / 304.8;
points4D.at<float>(3, k) = (points4D.at<float>(3, k) / points4D.at<float>(3, k)) / 304.8;
std::cout << std::setprecision(9) << points4D.at<float>(0, k) << "," << points4D.at<float>(1, k) << "," << points4D.at<float>(2, k) << std::endl;
}
```In the following code, points4DNorm will contains the 3D points in world coordinates. I didn't use rectify at all, I just used a few 2d/3d point pairs and then solvePnPRansac on these pairs.
```// rotMat1, rotMat2,tvec1 and tvec2 are retrieved from solvePnPRansac and Rodrigues
Mat points4D;
rotMat1.copyTo(myCam1.ProjectionMat(Rect(0, 0, 3, 3)));
tvec1.copyTo(myCam1.ProjectionMat(Rect(3, 0, 1, 3)));

rotMat2.copyTo(myCam2.ProjectionMat(Rect(0, 0, 3, 3)));
tvec2.copyTo(myCam2.ProjectionMat(Rect(3, 0, 1, 3)));

myCam1.ProjectionMat = myCam1.NewCameraMat* myCam1.ProjectionMat;
myCam2.ProjectionMat = myCam2.NewCameraMat* myCam2.ProjectionMat;
triangulatePoints(myCam1.ProjectionMat, myCam2.ProjectionMat, balls12d, balls22d, points4D);
Mat points4DNorm;
for (int k = 0; k < points4D.cols;k++)
{
points4D.at<float>(0, k) = (points4D.at<float>(0, k) / points4D.at<float>(3, k))/304.8;
points4D.at<float>(1, k) = (points4D.at<float>(1, k) / points4D.at<float>(3, k)) / 304.8;
points4D.at<float>(2, k) = (points4D.at<float>(2, k) / points4D.at<float>(3, k)) / 304.8;
points4D.at<float>(3, k) = (points4D.at<float>(3, k) / points4D.at<float>(3, k)) / 304.8;
std::cout << std::setprecision(9) << points4D.at<float>(0, k) << "," << points4D.at<float>(1, k) << "," << points4D.at<float>(2, k) << std::endl;
}
``````
2016-03-15

## 在sqoop查询中连接两个表时的算术运算(Arithmetic operation while joining two tables in a sqoop query)

YEAR和MONTH无效Teradata SQL，都是ODBC语法，由ODBC驱动程序自动重写。 尝试EXTRACT(YEAR FROM A.dt) 。 YEAR and MONTH are not valid Teradata SQL, both are ODBC syntax, which is automatically rewritten by the ODBC driver. Try EXTRACT(YEAR FROM A.dt) instead.