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/m.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