日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

opencv与opengl混用实现三维点云图像

發(fā)布時(shí)間:2025/3/20 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv与opengl混用实现三维点云图像 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

/*

灰度圖轉(zhuǎn)換為高度圖,為雙目視覺(jué)三維重建做準(zhǔn)備。

*/

#include <iostream> ?

#include <stdlib.h> ?
//#include <cv.h> ?
//#include <cxcore.h> ?
//#include <highgui.h> ?
#include "opencv2/calib3d/calib3d.hpp" ? ?
#include "opencv2/imgproc/imgproc.hpp" ? ?
#include "opencv2/highgui/highgui.hpp" ? ?
#include "opencv2/contrib/contrib.hpp" ??
#include <cmath> ?
#include <glut.h> ? ?
#include <iostream> ?

#pragma comment(lib,"opencv_highgui248.lib") ? ?
#pragma comment(lib,"opencv_core248.lib") ? ?
#pragma comment(lib,"opencv_imgproc248.lib") ? ?




using namespace cv;
using namespace std;


#define MAX_SIZE 1024 ?


float imgdata[MAX_SIZE][MAX_SIZE];


int w = 0;
int h = 0;
float scalar = 50;


void renderScene(void)
{


glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity(); ? ? ? ? ? ? ?
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotatef(-90, 0.0, 1.0, 0.0);
glRotatef(-90, 0.0, 0.0, 1.0);?
glRotatef(-180, 0.0, 1.0, 0.0);


float imageCenterX = w*0.5;
float imageCenterY = h*0.5;
float x, y, z;
glPointSize(1.0);
glBegin(GL_POINTS);//GL_POINTS ?
for (int i = 0; i<h; i++)
{
for (int j = 0; j<w; j++)
{
// color interpolation ?
glColor3f(1 - imgdata[i][j] / 255, imgdata[i][j] / 255, imgdata[i][j] / 255);
x = ((float)j - imageCenterX) / scalar;
y = ((float)i - imageCenterY) / scalar;
z = imgdata[i][j] / scalar;
glVertex3f(x, y, z);
}
}
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}


void displayDisparity(IplImage* disparity)
{
double xyscale = 100;
int j = 0;
int i = 0;
CvScalar s;


//accessing the image pixels ?
for (i = 0; i<h; i++)
{
for (j = 0; j<w; j++)
{
s = cvGet2D(disparity, i, j);
imgdata[i][j] = s.val[0];//for disparity is a grey image. ?
}
}
}
int main(int argc,char *argv[])
{
string imgname="1.jpg";
IplImage* grey = cvLoadImage(imgname.c_str(), 1); //read image as a grey one ?
if (grey == NULL)
{
cout << "No valid image input." << endl;
char c = getchar();
return 1;
}
w = grey->width;
h = grey->height;


displayDisparity(grey);
cvNamedWindow("original", CV_WINDOW_AUTOSIZE);
cvShowImage("original", grey);


//------------------OpenGL------------------------- ?
glutInit(&argc, (char**)argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("3D disparity image");
glutDisplayFunc(renderScene);
glutReshapeFunc(reshape);
glutMainLoop();
cvWaitKey(0);
//release opencv stuff. ?
cvReleaseImage(&grey);
cvDestroyWindow("Original");


return 0;
}

總結(jié)

以上是生活随笔為你收集整理的opencv与opengl混用实现三维点云图像的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。