日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/20 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv与opengl混用实现三维点云图像 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/*

灰度圖轉換為高度圖,為雙目視覺三維重建做準備。

*/

#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;
}

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。