-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
425 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/imview/include/imview/widget/buffered_cv_image_widget.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* @file image_widget.hpp | ||
* @date 10/10/24 | ||
* @brief | ||
* | ||
* @copyright Copyright (c) 2024 Ruixiang Du (rdu) | ||
*/ | ||
|
||
#ifndef QUICKVIZ_CV_IMAGE_WIDGET_HPP | ||
#define QUICKVIZ_IMAGE_WIDGET_HPP | ||
|
||
#include <functional> | ||
|
||
#include "imview/panel.hpp" | ||
#include "imview/buffer/buffer_registry.hpp" | ||
|
||
#include "glad/glad.h" | ||
|
||
#include <opencv2/opencv.hpp> | ||
|
||
namespace quickviz { | ||
class BufferedCvImageWidget : public Panel { | ||
public: | ||
BufferedCvImageWidget(const std::string& widget_name, | ||
const std::string& buffer_name); | ||
~BufferedCvImageWidget(); | ||
|
||
// public methods | ||
void SetKeepAspectRatio(bool keep); | ||
void Draw() override; | ||
|
||
private: | ||
GLuint image_texture_; | ||
std::shared_ptr<BufferInterface<cv::Mat>> buffer_; | ||
bool keep_aspect_ratio_ = false; | ||
}; | ||
} // namespace quickviz | ||
|
||
#endif // QUICKVIZ_CV_IMAGE_WIDGET_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* @file image_widget.hpp | ||
* @date 10/10/24 | ||
* @brief | ||
* | ||
* @copyright Copyright (c) 2024 Ruixiang Du (rdu) | ||
*/ | ||
|
||
#ifndef QUICKVIZ_CV_IMAGE_WIDGET_HPP | ||
#define QUICKVIZ_CV_IMAGE_WIDGET_HPP | ||
|
||
#include "glad/glad.h" | ||
|
||
#include <mutex> | ||
#include <functional> | ||
|
||
#include <opencv2/opencv.hpp> | ||
|
||
#include "imview/panel.hpp" | ||
|
||
namespace quickviz { | ||
class CvImageWidget : public Panel { | ||
public: | ||
CvImageWidget(const std::string& widget_name); | ||
~CvImageWidget(); | ||
|
||
// public methods | ||
void SetKeepAspectRatio(bool keep); | ||
void UpdateImage(const cv::Mat& image); | ||
void Draw() override; | ||
|
||
private: | ||
std::mutex image_mutex_; | ||
cv::Mat image_mat_; | ||
GLuint image_texture_; | ||
bool keep_aspect_ratio_ = false; | ||
}; | ||
} // namespace quickviz | ||
|
||
#endif // QUICKVIZ_CV_IMAGE_WIDGET_HPP |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* @file buffered_cv_image_widget.cpp | ||
* @date 10/25/24 | ||
* @brief | ||
* | ||
* @copyright Copyright (c) 2024 Ruixiang Du (rdu) | ||
*/ | ||
|
||
#include "imview/widget/buffered_cv_image_widget.hpp" | ||
|
||
#include "imview/utils/image_utils.hpp" | ||
|
||
namespace quickviz { | ||
BufferedCvImageWidget::BufferedCvImageWidget(const std::string& widget_name, | ||
const std::string& buffer_name) | ||
: Panel(widget_name) { | ||
this->SetAutoLayout(false); | ||
// this->SetNoResize(true); | ||
// this->SetNoMove(true); | ||
this->SetWindowNoMenuButton(); | ||
this->SetNoBackground(true); | ||
|
||
auto& buffer_registry = BufferRegistry::GetInstance(); | ||
buffer_ = buffer_registry.GetBuffer<cv::Mat>(buffer_name); | ||
|
||
glGenTextures(1, &image_texture_); | ||
} | ||
|
||
BufferedCvImageWidget::~BufferedCvImageWidget() { | ||
glDeleteTextures(1, &image_texture_); | ||
} | ||
|
||
void BufferedCvImageWidget::SetKeepAspectRatio(bool keep) { | ||
keep_aspect_ratio_ = keep; | ||
} | ||
|
||
void BufferedCvImageWidget::Draw() { | ||
Begin(); | ||
{ | ||
ImVec2 contentSize = ImGui::GetContentRegionAvail(); | ||
float width = contentSize.x; | ||
float height = contentSize.y; | ||
|
||
cv::Mat mat; | ||
buffer_->Read(mat); | ||
|
||
if (!mat.empty()) { | ||
if (keep_aspect_ratio_) { | ||
cv::Mat proc = mat; | ||
float aspect_ratio = mat.cols / (float)mat.rows; | ||
float img_width = width; | ||
float img_height = height; | ||
if (width / height > aspect_ratio) { | ||
img_width = height * aspect_ratio; | ||
} else { | ||
img_height = width / aspect_ratio; | ||
} | ||
if (img_width > width) { | ||
// need to scale down | ||
img_width = width; | ||
img_height = width / aspect_ratio; | ||
} else { | ||
// need to scale down | ||
img_height = height; | ||
img_width = height * aspect_ratio; | ||
} | ||
cv::resize(mat, proc, cv::Size(img_width, img_height), 0, 0, | ||
cv::INTER_CUBIC); | ||
// copy display to center of image | ||
cv::Mat display = cv::Mat::zeros(height, width, mat.type()); | ||
cv::Rect roi((width - proc.cols) / 2, (height - proc.rows) / 2, | ||
proc.cols, proc.rows); | ||
proc.copyTo(display(roi)); | ||
CopyTextureFromCvMat(display, image_texture_); | ||
} else { | ||
CopyTextureFromCvMat(mat, image_texture_); | ||
} | ||
} | ||
ImGui::Image((void*)(intptr_t)image_texture_, ImVec2(width, height)); | ||
} | ||
End(); | ||
} | ||
} // namespace quickviz |
Oops, something went wrong.