Opencv OpenGL中从图像到用户定义的点集(点云)的纹理映射
我在世界上有一组三维点。我使用OpenCV校准了相机的外部参数 现在我可以将三维点映射到二维图像中相应的像素 i、 对于[X Y Z],我在图像中有相应的[u v] 在OpenGL中,我规范化了世界上的3-D点,并定义了一个曲面,我希望在这里进行纹理映射 从代码中获得的三维表面如下图所示。 它是一个碗状表面 现在我想将图像中的纹理映射到OpenGL中的三维点 我所掌握的资料: 1。从世界点获取openGL中抛物线曲面的三维坐标。 2。对应的二维图像坐标和像素的R-G-B颜色信息。 我该怎么做呢 下面是我的代码片段,用于使用真实世界坐标获取链接中显示的模型曲面上的三维点 它还将相应的(u v)像素坐标的RGB颜色信息存储在图像中以进行渲染:Opencv OpenGL中从图像到用户定义的点集(点云)的纹理映射,opencv,opengl,texture-mapping,triangulation,point-clouds,Opencv,Opengl,Texture Mapping,Triangulation,Point Clouds,我在世界上有一组三维点。我使用OpenCV校准了相机的外部参数 现在我可以将三维点映射到二维图像中相应的像素 i、 对于[X Y Z],我在图像中有相应的[u v] 在OpenGL中,我规范化了世界上的3-D点,并定义了一个曲面,我希望在这里进行纹理映射 从代码中获得的三维表面如下图所示。 它是一个碗状表面 现在我想将图像中的纹理映射到OpenGL中的三维点 我所掌握的资料: 1。从世界点获取openGL中抛物线曲面的三维坐标。 2。对应的二维图像坐标和像素的R-G-B颜色信息。 我该怎么做呢
for (int z_3D = 0; z_3D < 30; z_3D+=1)
{
for (int x_3D = 0; x_3D < 102; x_3D+=1)
{
for (int y_3D = 0; y_3D < 135.5; y_3D+=1)
{
//3-D point in real world(in cms)
x = x_3D;
y = y_3D;
z = z_3D;
object_point[0].x = x;
object_point[1].y = y;
object_point[2].z = z;
//Project 3-D point to 2-D image and get the corresponding (u,v)
//rvec and tvec Obtained using SolvPnP in openCV
projectPoints(object_point, rvec_front, tvec_front, cameraMatrix_Front, distCoeffs_Front, check_front_image_pts);
//Store colour information in the corresponding 2-D point
//Points not lying on the surface is black
rgb.r = 0;
rgb.g = 0;
rgb.b = 0;
//Convert real world coordinates into openGl coordinates(-1 to +1)
x = (x - CHART_WIDTH / 2) / (CHART_WIDTH / 2);
y = -(y - CHART_LENGTH / 2) / (CHART_LENGTH / 2);
z = z / CHART_HEIGHT;
//Parabolic surface model
float x_4 = x*x*x*x;
float y_4 = y*y*y*y;
if (x_4 + y_4 < r_4)
{
//Store 3-D point
vertex_obj.vertex_x.push_back(x);
vertex_obj.vertex_y.push_back(y);
vertex_obj.vertex_z.push_back((x_4 + y_4) / (a_4));
/**/
//Store colour information in the corresponding 2-D point
rgb.r = front.at<Vec3b>(check_front_image_pts[0].y, check_front_image_pts[0].x)[2];
rgb.g = front.at<Vec3b>(check_front_image_pts[0].y, check_front_image_pts[0].x)[1];
rgb.b = front.at<Vec3b>(check_front_image_pts[0].y, check_front_image_pts[0].x)[0];
//printf("%f %f %f\n", rgb.r, rgb.g, rgb.b);
vertex_obj.vertex_colour.push_back(rgb);
}
else if (sqrt((x_4 + y_4 - r_4)*(x_4 + y_4 - r_4)) < 0.0001)
{
//Store 3-D point
vertex_obj.vertex_x.push_back(x);
vertex_obj.vertex_y.push_back(y);
//vertex_obj.vertex_z.push_back(1.0);
vertex_obj.vertex_z.push_back((x_4 + y_4) / (a_4)+0.0001);
/*
//Store colour information in the corresponding 2-D point
rgb.r = front.at<Vec3b>(check_front_image_pts[0].y, check_front_image_pts[0].x)[2];
rgb.g = front.at<Vec3b>(check_front_image_pts[0].y, check_front_image_pts[0].x)[1];
rgb.b = front.at<Vec3b>(check_front_image_pts[0].y, check_front_image_pts[0].x)[0];*/
vertex_obj.vertex_colour.push_back(rgb);
}
}
}
}
for(int z_3D=0;z_3D<30;z_3D+=1)
{
对于(int x_3D=0;x_3D<102;x_3D+=1)
{
对于(int y_3D=0;y_3D<135.5;y_3D+=1)
{
//真实世界中的三维点(cms)
x=x_3D;
y=y_3D;
z=z_3D;
对象_点[0]。x=x;
对象_点[1]。y=y;
对象_点[2]。z=z;
//将三维点投影到二维图像,并获得相应的(u,v)
//在openCV中使用SolvPnP获得rvec和tvec
项目点(对象点、rvec点、tvec点、cameraMatrix点、Discoefs点、check点、图像点);
//将颜色信息存储在相应的二维点中
//不在曲面上的点为黑色
rgb.r=0;
rgb.g=0;
rgb.b=0;
//将真实世界坐标转换为openGl坐标(-1到+1)
x=(x-图表宽度/2)/(图表宽度/2);
y=-(y-图表长度/2)/(图表长度/2);
z=z/图表高度;
//抛物面模型
浮点数x_4=x*x*x*x;
浮动y_4=y*y*y*y;
if(x_4+y_4
这是我的渲染代码片段
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); // Reset the model-view matrix
glRotated(ph, 1, 0, 0);
glRotated(th, 0, 1, 0);
glBegin(GL_POINTS);
for (int i = 0; i < vertex_obj.vertex_x.size(); i++)
{
//Give the colour info from the pixel in the image
glColor3f(vertex_obj.vertex_colour[i].r/255.0, vertex_obj.vertex_colour[i].g/255.0, vertex_obj.vertex_colour[i].b/255.0);
//Give the vertex of points lying on the surface defined
glVertex3f(vertex_obj.vertex_x[i], vertex_obj.vertex_y[i], vertex_obj.vertex_z[i]);
}
//glColor3f(0, 0, 1);
//glVertex2f(1.0, -1.0);
glEnd();
glutSwapBuffers();
}
void render()
{
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
glLoadIdentity();//重置模型视图矩阵
gl(ph,1,0,0);
(th,0,1,0);
glBegin(总分);
对于(int i=0;i
问题
我该怎么做呢 我假设纹理图像的形状类似于要将其绘制到的曲面,例如,应用于3D半球的人脸 首先,将曲面定义为曲面,而不是点云。您已经在为曲面上的点生成顶点坐标,所以只需将它们链接到三角形网格中即可。(三角带) 其次,不要将颜色应用于曲面的顶点。改为设置纹理坐标。(在OpenGL中,它们通常被称为s,t,而不是u,v,但其含义是相同的。)顶点颜色应该是纯白色。使用glTexture2D将图像传递给OpenGL 通过这种方式,您可以让GPU查找纹理坐标、插值和填充曲面,而不是进行书写