can render 2 cv::mats

This commit is contained in:
Kueffner, Maximilian
2025-03-14 19:32:40 +01:00
parent 5ecc38a9ca
commit 0b541348b0
15 changed files with 290 additions and 12 deletions
+2
View File
@@ -0,0 +1,2 @@
add_subdirectory(imaging)
add_subdirectory(rendering)
+23
View File
@@ -0,0 +1,23 @@
include(${CMAKE_SOURCE_DIR}/cmake/libCZI.cmake)
find_package(OpenCV REQUIRED)
message(STATUS "Found opencv: " ${OpenCV_INCLUDE_DIRS})
message(STATUS "OpenCV_LIBs from: " ${OpenCV_LIBS})
set(IMAGELIBSRC
Image.cpp)
set(IMAGELIBLIBNAME pixelariumimagelib)
add_library(${IMAGELIBLIBNAME}
STATIC ${IMAGELIBSRC})
target_link_libraries(${IMAGELIBLIBNAME}
PUBLIC ${OpenCV_LIBS}
PRIVATE libCZIStatic)
target_include_directories(${IMAGELIBLIBNAME}
PUBLIC ${OpenCV_INCLUDE_DIRS}
PRIVATE ${LIBCZI_INCLUDE_DIR})
+15
View File
@@ -0,0 +1,15 @@
#include "Image.hpp"
#include <filesystem>
#include <opencv2/imgcodecs.hpp>
#include <stdexcept>
pixelarium::imaging::Image::Image(const std::string& uri)
{
if (!std::filesystem::exists(uri))
{
throw std::runtime_error("File not found");
}
this->_img = cv::imread(uri);
}
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include <filesystem>
#include <memory>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <string>
namespace pixelarium::imaging
{
class Image
{
public:
explicit Image(const std::string& uri);
// get back the defaults
Image() = default;
Image(const Image& other) = default;
Image(Image&& other) noexcept = default;
Image& operator=(const Image& other) = default;
Image& operator=(Image&& other) noexcept = default;
~Image() = default;
const cv::Mat& GetImage() const { return this->_img; }
private:
cv::Mat _img;
};
} // namespace pixelarium::imaging
+15
View File
@@ -0,0 +1,15 @@
set(RENDERSRC)
set(RENDERLIBNAME pixelariumrenderlib)
set(RENDERLIBSRC
CvMatRender.cpp)
add_library(${RENDERLIBNAME} STATIC
${RENDERLIBSRC})
target_link_libraries(${RENDERLIBNAME}
PRIVATE pixelariumimagelib)
target_include_directories(${RENDERLIBNAME}
PRIVATE ${CMAKE_SOURCE_DIR}/lib)
+49
View File
@@ -0,0 +1,49 @@
#include "CvMatRender.hpp"
#include <cstdint>
using namespace pixelarium::imaging;
pixelarium::render::CvMatRender::CvMatRender(const Image& img)
{
this->_img = img.GetImage();
this->_texture = 0;
cv::cvtColor(this->_img, this->_img, cv::COLOR_BGR2RGBA);
}
/*static*/ void pixelarium::render::matToTexture(const cv::Mat& image, GLuint* texture)
{
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// auto image = img.GetImage();
switch (image.type())
{
case CV_16U:
case CV_16UC3:
case 26:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.cols, image.rows, 0,
GL_RGBA, GL_UNSIGNED_SHORT, image.data);
break;
case 5:
case 29:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.cols, image.rows, 0,
GL_RGBA, GL_FLOAT, image.data);
break;
default:
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.cols, image.rows, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image.data);
break;
}
}
GLuint pixelarium::render::CvMatRender::Render()
{
matToTexture(this->_img, &this->_texture);
return this->_texture;
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#ifdef _WIN32
#include <windows.h>
#include <GL/GL.h>
#else
#define GL_SILENCE_DEPRECATION
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#endif
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
#endif
#include "imaging/Image.hpp"
namespace pixelarium::render
{
static void matToTexture(const cv::Mat& image,
GLuint* texture);
class CvMatRender
{
public:
explicit CvMatRender(const pixelarium::imaging::Image& img);
// void* Render();
GLuint Render();
private:
cv::Mat _img;
GLuint _texture;
};
} // namespace pixelarium::render
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <string>
namespace pixelarium::utils::log
{
class ILog
{
public:
virtual void Info(const std::string& msg,
const std::string& source = "") = 0;
virtual void Debug(const std::string& msg,
const std::string& source = "") = 0;
virtual void Warn(const std::string& msg,
const std::string& source = "") = 0;
virtual void Error(const std::string& msg,
const std::string& source = "") = 0;
virtual ~ILog() {}
};
} // namespace pixelarium::utils
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include "ILog.hpp"
namespace pixelarium::utils::log
{
class SpdLogger : public ILog
{
public:
SpdLogger(const std::string& file_sink);
void Info(const std::string& msg,
const std::string& source = "") override;
void Debug(const std::string& msg,
const std::string& source = "") override;
void Warn(const std::string& msg,
const std::string& source = "") override;
void Error(const std::string& msg,
const std::string& source = "") override;
};
} // namespace pixelarium::utils::log