Initial Commit
This commit is contained in:
commit
1ded5ea730
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Ignore all build directories
|
||||||
|
build/
|
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "thirdparty/glew-cmake"]
|
||||||
|
path = thirdparty/glew-cmake
|
||||||
|
url = https://github.com/Perlmint/glew-cmake
|
||||||
|
[submodule "thirdparty/glfw"]
|
||||||
|
path = thirdparty/glfw
|
||||||
|
url = https://github.com/glfw/glfw
|
136
CMakeLists.txt
Normal file
136
CMakeLists.txt
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.24)
|
||||||
|
|
||||||
|
set(PROJECT_NAME Sentinal)
|
||||||
|
project(${PROJECT_NAME} LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(project_version_major 0)
|
||||||
|
set(project_version_minor 0)
|
||||||
|
set(project_version_patch 1)
|
||||||
|
set(project_version_tweak 0)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Make sure this is here for nvim and fleet users
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# Manage Dependencies #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
ExternalProject_Add(
|
||||||
|
imgui
|
||||||
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
||||||
|
GIT_TAG master
|
||||||
|
UPDATE_COMMAND ""
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
BUILD_IN_SOURCE 1
|
||||||
|
)
|
||||||
|
|
||||||
|
ExternalProject_Get_Property(imgui source_dir)
|
||||||
|
file(GLOB imgui_sources
|
||||||
|
"${source_dir}/*.cpp"
|
||||||
|
"${source_dir}/*.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(imgui STATIC ${imgui_sources})
|
||||||
|
target_include_directories(imgui PUBLIC ${source_dir})
|
||||||
|
|
||||||
|
ExternalProject_Add(
|
||||||
|
ffmpeg
|
||||||
|
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
|
||||||
|
GIT_TAG master
|
||||||
|
UPDATE_COMMAND ""
|
||||||
|
CONFIGURE_COMMAND ./configure --prefix=<INSTALL_DIR> --enable-shared --disable-static
|
||||||
|
BUILD_COMMAND make
|
||||||
|
INSTALL_COMMAND make install
|
||||||
|
BUILD_IN_SOURCE 1
|
||||||
|
)
|
||||||
|
|
||||||
|
ExternalProject_Get_Property(ffmpeg install_dir)
|
||||||
|
|
||||||
|
set(FFMPEG_INCLUDE_DIR ${install_dir}/include)
|
||||||
|
set(FFMPEG_LIB_DIR ${install_dir}/lib)
|
||||||
|
set(FFMPEG_BIN_DIR ${install_dir}/bin)
|
||||||
|
|
||||||
|
add_library(avcodec SHARED IMPORTED)
|
||||||
|
set_target_properties(avcodec PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libavcodec.so
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(avformat SHARED IMPORTED)
|
||||||
|
set_target_properties(avformat PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libavformat.so
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(avutil SHARED IMPORTED)
|
||||||
|
set_target_properties(avutil PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libavutil.so
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(swscale SHARED IMPORTED)
|
||||||
|
set_target_properties(swscale PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libswscale.so
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(FFmpeg::avcodec ALIAS avcodec)
|
||||||
|
add_library(FFmpeg::avformat ALIAS avformat)
|
||||||
|
add_library(FFmpeg::avutil ALIAS avutil)
|
||||||
|
add_library(FFmpeg::swscale ALIAS swscale)
|
||||||
|
|
||||||
|
# Add GLFW and GLEW as subdirectories if they have their own CMake files
|
||||||
|
add_subdirectory(thirdparty/glfw)
|
||||||
|
add_subdirectory(thirdparty/glew-cmake)
|
||||||
|
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
# Dependencies Done #
|
||||||
|
# # # # # # # # # # # #
|
||||||
|
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
list(APPEND EXTRA_LIBS "-framework OpenGL")
|
||||||
|
elseif(WIN32)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
else()
|
||||||
|
list(APPEND EXTRA_LIBS "-lGL -lGLU -lX11")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ImGui glfw backends (GLFW + OpenGL3)
|
||||||
|
add_library(imgui_impl STATIC
|
||||||
|
thirdparty/imgui/backends/imgui_impl_glfw.cpp
|
||||||
|
thirdparty/imgui/backends/imgui_impl_opengl3.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(imgui_impl PRIVATE
|
||||||
|
thirdparty/imgui
|
||||||
|
thirdparty/imgui/backends
|
||||||
|
thirdparty/glfw/include
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
thirdparty/imgui
|
||||||
|
thirdparty/imgui/backends
|
||||||
|
thirdparty/glfw/include
|
||||||
|
thirdparty/glew-cmake/include
|
||||||
|
)
|
||||||
|
|
||||||
|
set(glew-cmake_BUILD_SHARED OFF)
|
||||||
|
set(glew-cmake_BUILD_STATIC ON)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} src/main.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE imgui FFmpeg::avcodec FFmpeg::avformat FFmpeg::avutil FFmpeg::swscale glfw glew)
|
||||||
|
|
||||||
|
add_dependencies(${PROJECT_NAME} ffmpeg)
|
||||||
|
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||||
|
)
|
8
README.md
Normal file
8
README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Sentinal
|
||||||
|
Security Camera Software
|
||||||
|
|
||||||
|
## Building
|
||||||
|
Sentinal uses MinGW as it's main compiler. To clone the repo, use
|
||||||
|
```bash
|
||||||
|
git clone http://10.0.0.19:3001/sentinal/sentinal.git
|
||||||
|
```
|
196
src/main.cpp
Normal file
196
src/main.cpp
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
// #include <GLFW/glfw3.h>
|
||||||
|
// #include <imgui.h>
|
||||||
|
// #include <imgui_impl_glfw.h>
|
||||||
|
// #include <imgui_impl_opengl3.h>
|
||||||
|
// #include <stdio.h>
|
||||||
|
|
||||||
|
// int main(void) {
|
||||||
|
// GLFWwindow* window;
|
||||||
|
// if (!glfwInit()) {
|
||||||
|
// printf("Couldn't initialize GLFW!\n");
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// window = glfwCreateWindow(640, 480, "Sentinal", NULL, NULL);
|
||||||
|
// if (!window) {
|
||||||
|
// printf("Couldn't create window\n");
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// // Initialize OpenGL loader (you might need to include and initialize GLEW or glad here)
|
||||||
|
|
||||||
|
// // Initialize ImGui
|
||||||
|
// IMGUI_CHECKVERSION();
|
||||||
|
// ImGui::CreateContext();
|
||||||
|
// ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
|
// ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
// // Initialize ImGui backends
|
||||||
|
// ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
|
// ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
|
|
||||||
|
// while (!glfwWindowShouldClose(window)) {
|
||||||
|
// glfwPollEvents();
|
||||||
|
|
||||||
|
// // Start ImGui frame
|
||||||
|
// ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
// ImGui_ImplGlfw_NewFrame();
|
||||||
|
// ImGui::NewFrame();
|
||||||
|
|
||||||
|
// // Your ImGui code here
|
||||||
|
// ImGui::Begin("Hello, ImGui!");
|
||||||
|
// ImGui::Text("This is a simple window.");
|
||||||
|
// ImGui::End();
|
||||||
|
|
||||||
|
// // Render
|
||||||
|
// ImGui::Render();
|
||||||
|
// int display_w, display_h;
|
||||||
|
// glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
|
// glViewport(0, 0, display_w, display_h);
|
||||||
|
// glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
// glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
// ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
|
// glfwSwapBuffers(window);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Cleanup
|
||||||
|
// ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
// ImGui_ImplGlfw_Shutdown();
|
||||||
|
// ImGui::DestroyContext();
|
||||||
|
|
||||||
|
// glfwDestroyWindow(window);
|
||||||
|
// glfwTerminate();
|
||||||
|
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <libavformat/avformat.h>
|
||||||
|
#include <libavcodec/avcodec.h>
|
||||||
|
#include <libavutil/avutil.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <imgui_impl_glfw.h>
|
||||||
|
#include <imgui_impl_opengl3.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Function to create a texture from an OpenCV frame
|
||||||
|
GLuint createTextureFromFrame(const cv::Mat& frame) {
|
||||||
|
GLuint textureID;
|
||||||
|
glGenTextures(1, &textureID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||||
|
|
||||||
|
// Set texture parameters
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
// Upload the frame to the texture
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, frame.cols, frame.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, frame.data);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
return textureID;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// Initialize GLFW
|
||||||
|
if (!glfwInit()) {
|
||||||
|
printf("Couldn't initialize GLFW!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a windowed mode window and its OpenGL context
|
||||||
|
GLFWwindow* window = glfwCreateWindow(640, 480, "Sentinal", NULL, NULL);
|
||||||
|
if (!window) {
|
||||||
|
printf("Couldn't create window\n");
|
||||||
|
glfwTerminate();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the window's context current
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// Initialize GLEW
|
||||||
|
if (glewInit() != GLEW_OK) {
|
||||||
|
printf("Couldn't initialize GLEW!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize ImGui
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
// Initialize ImGui backends
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
|
ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
|
|
||||||
|
// OpenCV video capture
|
||||||
|
cv::VideoCapture cap(0); // Change the argument to a video file path if needed
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
printf("Couldn't open video capture\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint videoTexture = 0;
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
|
// Capture frame
|
||||||
|
cv::Mat frame;
|
||||||
|
cap >> frame; // Get the next frame from the video
|
||||||
|
|
||||||
|
if (!frame.empty()) {
|
||||||
|
// Create or update texture
|
||||||
|
if (videoTexture == 0) {
|
||||||
|
videoTexture = createTextureFromFrame(frame);
|
||||||
|
} else {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, videoTexture);
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame.cols, frame.rows, GL_BGR, GL_UNSIGNED_BYTE, frame.data);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start ImGui frame
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// ImGui window with video
|
||||||
|
ImGui::Begin("Video Stream");
|
||||||
|
if (videoTexture != 0) {
|
||||||
|
ImGui::Image((void*)(intptr_t)videoTexture, ImVec2((float)frame.cols, (float)frame.rows));
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
// Render ImGui
|
||||||
|
ImGui::Render();
|
||||||
|
int display_w, display_h;
|
||||||
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
|
glViewport(0, 0, display_w, display_h);
|
||||||
|
glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
|
// Swap buffers
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
glDeleteTextures(1, &videoTexture);
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
glfwTerminate();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
1
thirdparty/glew-cmake
vendored
Submodule
1
thirdparty/glew-cmake
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a5494db414d62e7bcb19f9f8fd7ee660338ea08e
|
1
thirdparty/glfw
vendored
Submodule
1
thirdparty/glfw
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit b35641f4a3c62aa86a0b3c983d163bc0fe36026d
|
Loading…
x
Reference in New Issue
Block a user