我有一个渲染应用程序。这是基础源代码
std::vector<Eigen::Vector3f> frame_buffer;
我已经在opencv中渲染了
pipeline.refresh();
pipeline.draw();
cv::Mat image(700, 700, CV_32FC3, pipeline.raster.frameBuffer().data());
image.convertTo(image, CV_8UC3, 1.0f);
cv::cvtColor(image, image, cv::COLOR_RGB2BGRA);
cv::imshow("image", image);
是正确的
但我想在 ImGUI 中显示。我使用这些代码在 ImGUI 中转换和显示。
// UI.h
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <opencv2/opencv.hpp>
// show function
while (!glfwWindowShouldClose(windows)){
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// window
ImGui::Begin("LRenderer");
pipeline.refresh();
pipeline.draw();
cv::Mat image(700, 700, CV_32FC3, pipeline.raster.frameBuffer().data());
image.convertTo(image, CV_8UC3, 1.0f);
cv::cvtColor(image, image, cv::COLOR_RGB2BGRA);
Mat2Texture(image, image_texture);
ImGui::Image((void*)(intptr_t)image_texture,
ImVec2(image.cols, image.rows));
ImGui::End();
// render
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(windows, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
const ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
glfwSwapBuffers(windows);
}
// convert function
void LRenderer::UI::Mat2Texture(const cv::Mat& image, GLuint& imageTexture) {
if (image.empty()) {
std::cout << "image is empty! " << std::endl;
return;
} else {
// generate texture using GL commands
glGenTextures(1, &image_texture);
glBindTexture(GL_TEXTURE_2D, imageTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, image.cols, image.rows, 0, GL_RGBA,
GL_UNSIGNED_BYTE, image.data);
}
}
glfw版本是3.3,glew版本是4.6。一切都是最新的。我曾尝试使用 glad 哪个版本是 3.3 和 4.6,但它没有用。
我该怎么办?哪个库版本是正确的?以及如何在 ImGUI 中将
cv::mat
转换为 ImTextureID
?我以前曾寻求解决方案。
哪个库版本是正确的?以及如何在 ImGUI 中将
cv::mat
转换为 ImTextureID
?