Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI

on:
push:
branches: [master]
pull_request:

jobs:
linux:
name: ${{ matrix.name }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- name: Release
build_type: Release
options: -DOGUI_BUILD_EXAMPLES=ON
flags: ""
- name: Static library
build_type: Release
options: -DOGUI_BUILD_SHARED=OFF -DOGUI_BUILD_EXAMPLES=OFF
flags: ""
- name: Bundled GLFW
build_type: Release
options: -DOGUI_SYSTEM_GLFW=OFF -DOGUI_BUILD_EXAMPLES=OFF
flags: ""
- name: AddressSanitizer
build_type: Debug
options: -DOGUI_BUILD_EXAMPLES=OFF
flags: -fsanitize=address,undefined -fno-omit-frame-pointer
- name: ThreadSanitizer
build_type: Debug
options: -DOGUI_BUILD_EXAMPLES=OFF
flags: -fsanitize=thread -fno-omit-frame-pointer

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake g++ libopencv-dev libglew-dev libglfw3-dev \
libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
xvfb xauth libgl1-mesa-dri

# The default address randomization of the runners breaks ThreadSanitizer
- name: Allow ThreadSanitizer memory mappings
if: contains(matrix.flags, 'thread')
run: sudo sysctl vm.mmap_rnd_bits=28

- name: Configure
run: >
cmake -S . -B build
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
-DOGUI_BUILD_TESTS=ON
${{ matrix.options }}
"-DCMAKE_C_FLAGS=${{ matrix.flags }}"
"-DCMAKE_CXX_FLAGS=${{ matrix.flags }}"
"-DCMAKE_EXE_LINKER_FLAGS=${{ matrix.flags }}"
"-DCMAKE_SHARED_LINKER_FLAGS=${{ matrix.flags }}"

- name: Build
run: cmake --build build -j $(nproc)

- name: Test
env:
LIBGL_ALWAYS_SOFTWARE: 1
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
run: xvfb-run -a -s "-screen 0 1024x768x24" ctest --test-dir build --output-on-failure

- name: Install and use the CMake package
if: matrix.flags == ''
env:
LIBGL_ALWAYS_SOFTWARE: 1
run: |
cmake --install build
cmake -S tests/consumer -B build-consumer -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install
cmake --build build-consumer
LD_LIBRARY_PATH=${{ github.workspace }}/install/lib xvfb-run -a build-consumer/consumer
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
cmake_minimum_required(VERSION 3.16)

project(OpenCVGUI VERSION 1.0.1 LANGUAGES C CXX)
project(OpenCVGUI VERSION 2.0.0 LANGUAGES C CXX)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

option(OGUI_BUILD_SHARED "Build OpenCVGUI as a shared library?" ON)
option(OGUI_GL3 "Build OpenCVGUI with OpenGL 3 support?" ON)
option(OGUI_BUILD_EXAMPLES "Build OpenCVGUI examples?" ON)
option(OGUI_SYSTEM_GLFW "Use system GLFW if available instead of 3rdparty/glfw?" ON)
option(OGUI_BUILD_TESTS "Build OpenCVGUI tests? They need a display, use xvfb-run in CI" OFF)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
Expand Down Expand Up @@ -67,7 +68,7 @@ set_target_properties(opencvgui PROPERTIES
EXPORT_NAME OpenCVGUI
FOLDER "OpenCVGUI")

target_compile_features(opencvgui PUBLIC cxx_std_11)
target_compile_features(opencvgui PUBLIC cxx_std_14)

if(OGUI_GL3)
target_compile_definitions(opencvgui PRIVATE OGUI_GL3)
Expand Down Expand Up @@ -112,6 +113,18 @@ endif()

add_executable(font2c src/font2c.cpp)

# Tests
if(OGUI_BUILD_TESTS)
enable_testing()
foreach(test test_render test_dialogs)
add_executable(${test} tests/${test}.cpp)
target_link_libraries(${test} PRIVATE opencvgui glfw)
set_target_properties(${test} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_test(NAME ${test} COMMAND ${test})
set_tests_properties(${test} PROPERTIES TIMEOUT 60)
endforeach()
endif()

# INSTALLATION
install(TARGETS opencvgui
EXPORT OpenCVGUITargets
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# OpenCVGUI
[![CI](https://github.com/damiles/OpenCVGUI/actions/workflows/ci.yml/badge.svg)](https://github.com/damiles/OpenCVGUI/actions/workflows/ci.yml)

Do you like OpenCV Highui but it's not enough and don't want waste your time
in a new UI SDK? **This is your solution!**
OpenCVGUI is a new graphical user inteface for OpenCV with different
Expand All @@ -22,6 +24,16 @@ Why OpenCVGUI: more Powerful and exactly so simple than OpenCV Highui.
5. make
6. sudo make install

# Tests
Tests open a window, so they need a display. Use `xvfb-run` on machines
without one.

```bash
cmake -S . -B build -DOGUI_BUILD_TESTS=ON
cmake --build build
ctest --test-dir build --output-on-failure
```


## Features

Expand Down Expand Up @@ -58,7 +70,7 @@ Create a new window
Show image in window
```C++
Mat image= imread("./lena.jpg");
window->imshow("image title key like highui imshow", &image);
window->imshow("image title key like highui imshow", image);
```

Custom 3D plot shaders (optional, defaults are embedded in the library).
Expand Down Expand Up @@ -88,11 +100,11 @@ OGUICVWindow *window;
void cv_process() {
while(app_is_running) {
cap >> frame;
window->imshow("camera", &frame);
window->imshow("camera", frame);
Mat output;
cvtColor( frame, gray, COLOR_RGB2GRAY );
threshold( gray, output, (int)thr, 255, CV_THRESH_BINARY);
window->imshow("threshold", &output);
window->imshow("threshold", output);
}
}

Expand All @@ -118,7 +130,7 @@ int main( int argc, const char* argv[] )
if(cap.isOpened()){
cap >> frame;
// show image
window->imshow("camera", &frame);
window->imshow("camera", frame);
}else{
return 0;
}
Expand All @@ -127,7 +139,7 @@ int main( int argc, const char* argv[] )
cvtColor( frame, gray, COLOR_RGB2GRAY );
Mat output;
threshold( gray, output, 125, 255, CV_THRESH_BINARY);
window->imshow("threshold", &output);
window->imshow("threshold", output);

// Start the Comptuer vision process
OpenCVGUI::app_run(cv_process);
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ OGUICVWindow *window;
void cv_process() {
while(app_is_running) {
cap >> frame;
window->imshow("camera", &frame);
window->imshow("camera", frame);
Mat output;
cvtColor( frame, gray, COLOR_RGB2GRAY );
threshold( gray, output, (int)thr, 255, CV_THRESH_BINARY);
window->imshow("threshold", &output);
window->imshow("threshold", output);
}
}

Expand All @@ -58,7 +58,7 @@ int main( int argc, const char* argv[] )
if(cap.isOpened()){
cap >> frame;
// show image
window->imshow("camera", &frame);
window->imshow("camera", frame);
}else{
return 0;
}
Expand All @@ -67,7 +67,7 @@ int main( int argc, const char* argv[] )
cvtColor( frame, gray, COLOR_RGB2GRAY );
Mat output;
threshold( gray, output, 125, 255, CV_THRESH_BINARY);
window->imshow("threshold", &output);
window->imshow("threshold", output);

// Start the Comptuer vision process
OpenCVGUI::app_run(cv_process);
Expand Down
4 changes: 2 additions & 2 deletions include/OpenCVGUI/OGUI3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OGUI3D : public OGUIArea {
virtual void draw(int x, int y, int width, int height);
virtual void draw3d(int x, int y, int width, int height);
virtual void updateScrollStatus(double xoffset,double yoffset);
void replot(void *data);
void replot(const Mat& data);

/**
* Set a function to draw custom OpenGL content in the 3D area.
Expand All @@ -56,7 +56,7 @@ class OGUI3D : public OGUIArea {
*/
void setExternalDraw3D(std::function<void(int x, int y, int width, int height, const glm::mat4& mvp)> func);

OGUI3D(OGUIWindow* window, std::string title, void* data);
OGUI3D(OGUIWindow* window, const std::string& title, const Mat& data);

// 3d functions
GLuint vao, vbo, ibo, shaderProgram, MatrixID, position_attribute;
Expand Down
1 change: 1 addition & 0 deletions include/OpenCVGUI/OGUIArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class OGUIArea {
public:

OGUIArea(OGUIWindow* window);
virtual ~OGUIArea() {}

virtual void draw(int x, int y, int width, int height);
virtual void draw3d(int x, int y, int width, int height);
Expand Down
35 changes: 31 additions & 4 deletions include/OpenCVGUI/OGUICVWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "OGUI3D.h"
#include "OGUIPlotArea.h"
#include <mutex>
#include <memory>

namespace OpenCVGUI {
/**
Expand All @@ -37,9 +38,11 @@ class OGUICVWindow : public OGUIWindow{
/**
* Add new image to window with title
* @param {string} area_title image are title
* @param {Mat} image opencv mat
* @param {Mat} image opencv mat, it is copied
*/
void imshow(string area_title, void* img);
void imshow(const string& area_title, const Mat& img);
[[deprecated("use imshow(title, const cv::Mat&)")]]
void imshow(const string& area_title, const Mat* img);

/**
* Add callback for mouse interaction to specific image area
Expand All @@ -57,16 +60,40 @@ class OGUICVWindow : public OGUIWindow{
OGUIArea* findAreaByTitle(string title);

void addFormWidget(OGUIWidget* widget);
void plot3D(string area_title, void* data);
void plot2D(string area_title, void* data, std::vector<string> labels, float xstep=1, int plot_type=0);

/**
* Add or update a 3D plot of a CV_32F Mat, values are the height
* @param {string} area_title plot area title
* @param {Mat} data opencv mat, it is copied
*/
void plot3D(const string& area_title, const Mat& data);
[[deprecated("use plot3D(title, const cv::Mat&)")]]
void plot3D(const string& area_title, const Mat* data);

/**
* Add or update a 2D plot, each Mat row is a serie
* @param {string} area_title plot area title
* @param {Mat} data opencv mat, it is copied
* @param {vector<string>} labels one label per serie
* @param {float} xstep x distance between values
* @param {int} plot_type one of PlotTypes
*/
void plot2D(const string& area_title, const Mat& data, const std::vector<string>& labels, float xstep=1, int plot_type=0);
[[deprecated("use plot2D(title, const cv::Mat&, labels, ...)")]]
void plot2D(const string& area_title, const Mat* data, const std::vector<string>& labels, float xstep=1, int plot_type=0);

// Areas and layouts are owned by the window, these pointers are only for access
std::vector<OGUIArea*> areas_showing;
std::vector<OGUILayout*> layout;
OGUIFormArea *formArea;



private:
// Areas created by the window, released when the window is destroyed
std::vector<std::unique_ptr<OGUIArea>> _owned_areas;
template<typename T> T* own(T* area);

// Protects areas_showing, imshow and plots can be called from any thread
std::mutex _areas_mutex;
OGUIArea* findArea(string title);
Expand Down
12 changes: 8 additions & 4 deletions include/OpenCVGUI/OGUIFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@
using namespace std;
using namespace cv;

struct NVGcontext;

namespace OpenCVGUI {
class OGUIWindow;

class OGUIFile {
public:
OGUIFile(void* window, const char* file_name, const char* path, int isdir, const char* ext, double size);
OGUIFile(OGUIWindow* window, const char* file_name, const char* path, int isdir, const char* ext, double size);
string _file_name;
string _path;
string _ext;
int _is_dir; //1 is dir 2 is drive
double _size;
void* _window;
OGUIWindow* _window;

bool draw(void *vvg, int x, int y, int mouse_x, int mouse_y);
bool draw(NVGcontext* vg, int x, int y, int mouse_x, int mouse_y);

bool isImage();
unsigned char* getPreview();

private:
int _mouse_state;
unsigned char* _preview_data;
Mat _preview; // 150x150 RGBA preview
};
}

Expand Down
7 changes: 4 additions & 3 deletions include/OpenCVGUI/OGUIFileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <vector>
#include <string>
#include <memory>
#include <mutex>
#include <condition_variable>

Expand All @@ -34,11 +35,11 @@ namespace OpenCVGUI {
private:
OGUIWindow* _window;
bool _is_file_browser_visible = false;
OGUIFile* _file_browser_result;
std::vector<OGUIFile*> _file_list;
OGUIFile* _file_browser_result; // Points to a file in _file_list or _system
std::vector<std::unique_ptr<OGUIFile>> _file_list;
string _actual_folder;
std::vector<string> _filter;
std::vector <OGUIFile*> _system;
std::vector<std::unique_ptr<OGUIFile>> _system;

char resolved_path[4096];

Expand Down
5 changes: 4 additions & 1 deletion include/OpenCVGUI/OGUIImageArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class OGUIImageArea : public OGUIArea {
virtual void draw(int x, int y, int width, int height);
virtual void updateScrollStatus(double xoffset,double yoffset);
OGUIImageArea(OGUIWindow* window, string title="");
void setImage(Mat *img);
// Set the image to show, it is copied
void setImage(const Mat& img);
[[deprecated("use setImage(const cv::Mat&)")]]
void setImage(const Mat* img);
void setMouseClickCallBack(std::function<void(int, int)> func);
void calcHistogram();
private:
Expand Down
4 changes: 2 additions & 2 deletions include/OpenCVGUI/OGUIPlotArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class OGUIPlotArea : public OGUIArea {

virtual void draw(int x, int y, int width, int height);

OGUIPlotArea(OGUIWindow* window, std::string title, void* data, std::vector<std::string> labels, float xstep=1.f, int plot_type=0);
void replot(void *data, std::vector<std::string> labels, float xstep=1.f);
OGUIPlotArea(OGUIWindow* window, const std::string& title, const Mat& data, const std::vector<std::string>& labels, float xstep=1.f, int plot_type=0);
void replot(const Mat& data, const std::vector<std::string>& labels, float xstep=1.f);
std::vector<int> color_scheme={
0,160,192,
255,51,102,
Expand Down
Loading
Loading