C_and_CPP 板


LINE

开发平台(Platform): (Ex: Win10, Linux, ...) win 7 编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出) VC++ 2013 额外使用到的函数库(Library Used): (Ex: OpenGL, ...) OpenCV, OpenGL, OpenVR 问题(Question): 我用2台IP CAM抓即时影像丢入Htc vive的双眼虚拟实境里,每秒30张, 但在VR里的影像有一点不连续,能否帮我看是不是openGL的frame buffer有写错 因为我对OpenGL不太熟,程式也是从网路抓下来修修改改测试的 程式码(Code):(请善用置底文网页, 记得排版) int framebufferWidth = 704, framebufferHeight = 480; int numEyes = 2; //左右眼 GLuint framebuffer[numEyes]; glGenFramebuffers(numEyes, framebuffer); //主要while回圈,在VR里显示影像 while (!glfwWindowShouldClose(window)) { for (int eye = 0; eye < numEyes; ++eye) { glBindFramebuffer(GL_FRAMEBUFFER, framebuffer[eye]); glViewport(0, 0, framebufferWidth, framebufferHeight); glBindFramebuffer(GL_FRAMEBUFFER, 0); //(这行是不是不需要) glClearColor(0.1f, 0.2f, 0.3f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLuint colorRenderTarget[numEyes]; if (eye == 0) //将左眼的OpenCV mat转成OpenGL texture格式 colorRenderTarget[eye] = matToTexture(left_image, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP); else if (eye == 1) //将右眼的OpenCV mat转成OpenGL texture格式 colorRenderTarget[eye] = matToTexture(right_image, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, colorRenderTarget[eye]); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer[eye]); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorRenderTarget[eye], 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); //将双眼影像丢入Htc vive里 const vr::Texture_t tex = { reinterpret_cast<void*>(intptr_t(colorRenderTarget[eye])), vr::API_OpenGL, vr::ColorSpace_Linear }; vr::VRCompositor()->Submit(vr::EVREye(eye), &tex); glDeleteTextures(1, &colorRenderTarget[numEyes]); glDisable(GL_TEXTURE_2D); } } glfwSwapBuffers(window); glfwPollEvents(); 下面是matToTexture函式(从网路抓来修改的): GLuint matToTexture(cv::Mat &mat, GLenum minFilter, GLenum magFilter, GLenum wrapFilter) { // Generate a number for our textureID's unique handle GLuint textureID; glGenTextures(1, &textureID); // Bind to our texture handle glBindTexture(GL_TEXTURE_2D, textureID); // Catch silly-mistake texture interpolation method for magnification if (magFilter == GL_LINEAR_MIPMAP_LINEAR || magFilter == GL_LINEAR_MIPMAP_NEAREST || magFilter == GL_NEAREST_MIPMAP_LINEAR || magFilter == GL_NEAREST_MIPMAP_NEAREST) { cout << "You can't use MIPMAPs for magnification - setting filter to GL_LINEAR" << endl; magFilter = GL_LINEAR; } // Set texture interpolation methods for minification and magnification glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); // Set texture clamping method glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapFilter); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set incoming texture format to: // GL_BGR for CV_CAP_OPENNI_BGR_IMAGE, // GL_LUMINANCE for CV_CAP_OPENNI_DISPARITY_MAP, // Work out other mappings as required ( there's a list in comments in main() ) GLenum inputColourFormat = GL_BGR; if (mat.channels() == 1) { inputColourFormat = GL_LUMINANCE; } // Create the texture glTexImage2D(GL_TEXTURE_2D, // Type of texture 0, // Pyramid level (for mip-mapping) - 0 is the top level GL_RGB, // Internal colour format to convert to mat.cols, // Image width i.e. 640 for Kinect in standard mode mat.rows, // Image height i.e. 480 for Kinect in standard mode 0, // Border width in pixels (can either be 1 or 0) inputColourFormat, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.) GL_UNSIGNED_BYTE, // Image data type mat.ptr()); // The actual image data itself // If we're using mipmaps then generate them. Note: This requires OpenGL 3.0 or higher if (minFilter == GL_LINEAR_MIPMAP_LINEAR || minFilter == GL_LINEAR_MIPMAP_NEAREST || minFilter == GL_NEAREST_MIPMAP_LINEAR || minFilter == GL_NEAREST_MIPMAP_NEAREST) { glGenerateMipmap(GL_TEXTURE_2D); } return textureID; } 补充说明(Supplement): matToTexture函式应该还好, 能帮我检查主要的while回圈吗? -- --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.96.33.181
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1485152801.A.7F0.html
1F:推 ggggggh: 为何有pyramid? 01/23 16:15
2F:→ popen: 那里有pyramid? 01/25 22:48
3F:→ popen: 那个不用管,那是注解啊,那直接用copy来的 01/25 22:49
4F:推 doom8199: vr 一般要跑在 90fps+ 才会顺吧, 30太小了 01/26 20:15
5F:→ doom8199: 再来你的 code 有几个问题, 第一个是两个 FBO 的 state 01/26 20:15
6F:→ doom8199: 都设完了, 但没人用它? 叫 GPU做事的指令应该是被埋在 01/26 20:16
7F:→ doom8199: 'Submit' 里头, 可是也没看到你把 FBO 传进去 01/26 20:17
8F:→ doom8199: 第二个是每个 swapbuffer 前都做了两次 mat to texture 01/26 20:18
9F:→ doom8199: 等於每个 frame 都做了两次 memory copy 至 GPU 端 01/26 20:19
10F:→ doom8199: 这种做法很没效率; 一般应该是 GL要开 external texture 01/26 20:20
11F:推 smartclever: windows上有eglimage可以用吗? 01/27 12:50
12F:→ popen: doom,请问能否提供范例,要怎麽修改才好 01/29 22:58







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:iOS站内搜寻

TOP