feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
34
3rdparty/opencv-4.5.4/samples/opengl/CMakeLists.txt
vendored
Normal file
34
3rdparty/opencv-4.5.4/samples/opengl/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
if(APPLE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
find_package(X11 QUIET)
|
||||
endif()
|
||||
|
||||
SET(OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS
|
||||
opencv_core
|
||||
opencv_imgproc
|
||||
opencv_imgcodecs
|
||||
opencv_videoio
|
||||
opencv_highgui)
|
||||
ocv_check_dependencies(${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
project(opengl_samples)
|
||||
ocv_include_modules_recurse(${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS})
|
||||
file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
|
||||
if(NOT X11_FOUND)
|
||||
ocv_list_filterout(all_samples "opengl_interop")
|
||||
endif()
|
||||
foreach(sample_filename ${all_samples})
|
||||
ocv_define_sample(tgt ${sample_filename} opengl)
|
||||
ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS})
|
||||
if(sample_filename STREQUAL "opengl_interop.cpp")
|
||||
ocv_target_link_libraries(${tgt} PRIVATE ${X11_LIBRARIES})
|
||||
ocv_target_include_directories(${tgt} ${X11_INCLUDE_DIR})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
ocv_install_example_src(opengl *.cpp *.hpp CMakeLists.txt)
|
114
3rdparty/opencv-4.5.4/samples/opengl/opengl.cpp
vendored
Normal file
114
3rdparty/opencv-4.5.4/samples/opengl/opengl.cpp
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#define NOMINMAX 1
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/opengl.hpp"
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
|
||||
const int win_width = 800;
|
||||
const int win_height = 640;
|
||||
|
||||
struct DrawData
|
||||
{
|
||||
ogl::Arrays arr;
|
||||
ogl::Texture2D tex;
|
||||
ogl::Buffer indices;
|
||||
};
|
||||
|
||||
void draw(void* userdata);
|
||||
|
||||
void draw(void* userdata)
|
||||
{
|
||||
DrawData* data = static_cast<DrawData*>(userdata);
|
||||
|
||||
glRotated(0.6, 0, 1, 0);
|
||||
|
||||
ogl::render(data->arr, data->indices, ogl::TRIANGLES);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string filename;
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "Usage: " << argv[0] << " image" << endl;
|
||||
filename = "../data/lena.jpg";
|
||||
}
|
||||
else
|
||||
filename = argv[1];
|
||||
|
||||
Mat img = imread(filename);
|
||||
if (img.empty())
|
||||
{
|
||||
cerr << "Can't open image " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
namedWindow("OpenGL", WINDOW_OPENGL);
|
||||
resizeWindow("OpenGL", win_width, win_height);
|
||||
|
||||
Mat_<Vec2f> vertex(1, 4);
|
||||
vertex << Vec2f(-1, 1), Vec2f(-1, -1), Vec2f(1, -1), Vec2f(1, 1);
|
||||
|
||||
Mat_<Vec2f> texCoords(1, 4);
|
||||
texCoords << Vec2f(0, 0), Vec2f(0, 1), Vec2f(1, 1), Vec2f(1, 0);
|
||||
|
||||
Mat_<int> indices(1, 6);
|
||||
indices << 0, 1, 2, 2, 3, 0;
|
||||
|
||||
DrawData data;
|
||||
|
||||
data.arr.setVertexArray(vertex);
|
||||
data.arr.setTexCoordArray(texCoords);
|
||||
data.indices.copyFrom(indices);
|
||||
data.tex.copyFrom(img);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, (double)win_width / win_height, 0.1, 100.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
data.tex.bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
setOpenGlDrawCallback("OpenGL", draw, &data);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
updateWindow("OpenGL");
|
||||
char key = (char)waitKey(40);
|
||||
if (key == 27)
|
||||
break;
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback("OpenGL", 0, 0);
|
||||
destroyAllWindows();
|
||||
|
||||
return 0;
|
||||
}
|
533
3rdparty/opencv-4.5.4/samples/opengl/opengl_interop.cpp
vendored
Normal file
533
3rdparty/opencv-4.5.4/samples/opengl/opengl_interop.cpp
vendored
Normal file
@ -0,0 +1,533 @@
|
||||
/*
|
||||
// Sample demonstrating interoperability of OpenCV UMat with OpenGL texture.
|
||||
// At first, the data obtained from video file or camera and placed onto
|
||||
// OpenGL texture, following mapping of this OpenGL texture to OpenCV UMat
|
||||
// and call cv::Blur function. The result is mapped back to OpenGL texture
|
||||
// and rendered through OpenGL API.
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#elif defined(__linux__)
|
||||
# include <X11/X.h>
|
||||
# include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/opengl.hpp"
|
||||
#include "opencv2/core/ocl.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
|
||||
#include "winapp.hpp"
|
||||
|
||||
#if defined(_WIN32)
|
||||
# pragma comment(lib, "opengl32.lib")
|
||||
# pragma comment(lib, "glu32.lib")
|
||||
#endif
|
||||
|
||||
|
||||
class GLWinApp : public WinApp
|
||||
{
|
||||
public:
|
||||
enum MODE
|
||||
{
|
||||
MODE_CPU = 0,
|
||||
MODE_GPU
|
||||
};
|
||||
|
||||
GLWinApp(int width, int height, std::string& window_name, cv::VideoCapture& cap) :
|
||||
WinApp(width, height, window_name)
|
||||
{
|
||||
m_shutdown = false;
|
||||
m_use_buffer = false;
|
||||
m_demo_processing = true;
|
||||
m_mode = MODE_CPU;
|
||||
m_modeStr[0] = cv::String("Processing on CPU");
|
||||
m_modeStr[1] = cv::String("Processing on GPU");
|
||||
m_cap = cap;
|
||||
}
|
||||
|
||||
~GLWinApp() {}
|
||||
|
||||
virtual void cleanup() CV_OVERRIDE
|
||||
{
|
||||
m_shutdown = true;
|
||||
#if defined(__linux__)
|
||||
glXMakeCurrent(m_display, None, NULL);
|
||||
glXDestroyContext(m_display, m_glctx);
|
||||
#endif
|
||||
WinApp::cleanup();
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) CV_OVERRIDE
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_CHAR:
|
||||
if (wParam == '1')
|
||||
{
|
||||
set_mode(MODE_CPU);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (wParam == '2')
|
||||
{
|
||||
set_mode(MODE_GPU);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if (wParam == '9')
|
||||
{
|
||||
toggle_buffer();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if (wParam == VK_SPACE)
|
||||
{
|
||||
m_demo_processing = !m_demo_processing;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if (wParam == VK_ESCAPE)
|
||||
{
|
||||
cleanup();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
cleanup();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case WM_DESTROY:
|
||||
::PostQuitMessage(0);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
return ::DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
int handle_event(XEvent& e) CV_OVERRIDE
|
||||
{
|
||||
switch(e.type)
|
||||
{
|
||||
case ClientMessage:
|
||||
if ((Atom)e.xclient.data.l[0] == m_WM_DELETE_WINDOW)
|
||||
{
|
||||
m_end_loop = true;
|
||||
cleanup();
|
||||
}
|
||||
else
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case Expose:
|
||||
render();
|
||||
break;
|
||||
case KeyPress:
|
||||
switch(keycode_to_keysym(e.xkey.keycode))
|
||||
{
|
||||
case XK_space:
|
||||
m_demo_processing = !m_demo_processing;
|
||||
break;
|
||||
case XK_1:
|
||||
set_mode(MODE_CPU);
|
||||
break;
|
||||
case XK_2:
|
||||
set_mode(MODE_GPU);
|
||||
break;
|
||||
case XK_9:
|
||||
toggle_buffer();
|
||||
break;
|
||||
case XK_Escape:
|
||||
m_end_loop = true;
|
||||
cleanup();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int init() CV_OVERRIDE
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
m_hDC = GetDC(m_hWnd);
|
||||
|
||||
if (setup_pixel_format() != 0)
|
||||
{
|
||||
std::cerr << "Can't setup pixel format" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
m_hRC = wglCreateContext(m_hDC);
|
||||
wglMakeCurrent(m_hDC, m_hRC);
|
||||
#elif defined(__linux__)
|
||||
m_glctx = glXCreateContext(m_display, m_visual_info, NULL, GL_TRUE);
|
||||
glXMakeCurrent(m_display, m_window, m_glctx);
|
||||
#endif
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
|
||||
if (cv::ocl::haveOpenCL())
|
||||
{
|
||||
(void) cv::ogl::ocl::initializeContextFromGL();
|
||||
}
|
||||
|
||||
m_oclDevName = cv::ocl::useOpenCL() ?
|
||||
cv::ocl::Context::getDefault().device(0).name() :
|
||||
(char*) "No OpenCL device";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} // init()
|
||||
|
||||
int get_frame(cv::ogl::Texture2D& texture, cv::ogl::Buffer& buffer, bool do_buffer)
|
||||
{
|
||||
if (!m_cap.read(m_frame_bgr))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
cv::cvtColor(m_frame_bgr, m_frame_rgba, cv::COLOR_RGB2RGBA);
|
||||
|
||||
if (do_buffer)
|
||||
buffer.copyFrom(m_frame_rgba, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||
else
|
||||
texture.copyFrom(m_frame_rgba, true);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void print_info(MODE mode, double time, cv::String& oclDevName)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
HDC hDC = m_hDC;
|
||||
|
||||
HFONT hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
|
||||
|
||||
HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont);
|
||||
|
||||
if (hOldFont)
|
||||
{
|
||||
TEXTMETRIC tm;
|
||||
::GetTextMetrics(hDC, &tm);
|
||||
|
||||
char buf[256+1];
|
||||
int y = 0;
|
||||
|
||||
buf[0] = 0;
|
||||
sprintf_s(buf, sizeof(buf)-1, "Mode: %s OpenGL %s", m_modeStr[mode].c_str(), use_buffer() ? "buffer" : "texture");
|
||||
::TextOut(hDC, 0, y, buf, (int)strlen(buf));
|
||||
|
||||
y += tm.tmHeight;
|
||||
buf[0] = 0;
|
||||
sprintf_s(buf, sizeof(buf)-1, "Time, msec: %2.1f", time);
|
||||
::TextOut(hDC, 0, y, buf, (int)strlen(buf));
|
||||
|
||||
y += tm.tmHeight;
|
||||
buf[0] = 0;
|
||||
sprintf_s(buf, sizeof(buf)-1, "OpenCL device: %s", oclDevName.c_str());
|
||||
::TextOut(hDC, 0, y, buf, (int)strlen(buf));
|
||||
|
||||
::SelectObject(hDC, hOldFont);
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
|
||||
char buf[256+1];
|
||||
snprintf(buf, sizeof(buf)-1, "Time, msec: %2.1f, Mode: %s OpenGL %s, Device: %s", time, m_modeStr[mode].c_str(), use_buffer() ? "buffer" : "texture", oclDevName.c_str());
|
||||
XStoreName(m_display, m_window, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void idle() CV_OVERRIDE
|
||||
{
|
||||
render();
|
||||
}
|
||||
|
||||
int render() CV_OVERRIDE
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_shutdown)
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
int r;
|
||||
cv::ogl::Texture2D texture;
|
||||
cv::ogl::Buffer buffer;
|
||||
|
||||
texture.setAutoRelease(true);
|
||||
buffer.setAutoRelease(true);
|
||||
|
||||
MODE mode = get_mode();
|
||||
bool do_buffer = use_buffer();
|
||||
|
||||
r = get_frame(texture, buffer, do_buffer);
|
||||
if (r != 0)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case MODE_CPU: // process frame on CPU
|
||||
processFrameCPU(texture, buffer, do_buffer);
|
||||
break;
|
||||
|
||||
case MODE_GPU: // process frame on GPU
|
||||
processFrameGPU(texture, buffer, do_buffer);
|
||||
break;
|
||||
} // switch
|
||||
|
||||
if (do_buffer) // buffer -> texture
|
||||
{
|
||||
cv::Mat m(m_height, m_width, CV_8UC4);
|
||||
buffer.copyTo(m);
|
||||
texture.copyFrom(m, true);
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
XWindowAttributes window_attributes;
|
||||
XGetWindowAttributes(m_display, m_window, &window_attributes);
|
||||
glViewport(0, 0, window_attributes.width, window_attributes.height);
|
||||
#endif
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
texture.bind();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.1f);
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 0.1f);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 0.1f);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.1f);
|
||||
glEnd();
|
||||
|
||||
#if defined(_WIN32)
|
||||
SwapBuffers(m_hDC);
|
||||
#elif defined(__linux__)
|
||||
glXSwapBuffers(m_display, m_window);
|
||||
#endif
|
||||
|
||||
print_info(mode, m_timer.getTimeMilli(), m_oclDevName);
|
||||
}
|
||||
|
||||
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
return 10;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void processFrameCPU(cv::ogl::Texture2D& texture, cv::ogl::Buffer& buffer, bool do_buffer)
|
||||
{
|
||||
cv::Mat m(m_height, m_width, CV_8UC4);
|
||||
|
||||
m_timer.reset();
|
||||
m_timer.start();
|
||||
|
||||
if (do_buffer)
|
||||
buffer.copyTo(m);
|
||||
else
|
||||
texture.copyTo(m);
|
||||
|
||||
if (m_demo_processing)
|
||||
{
|
||||
// blur texture image with OpenCV on CPU
|
||||
cv::blur(m, m, cv::Size(15, 15));
|
||||
}
|
||||
|
||||
if (do_buffer)
|
||||
buffer.copyFrom(m, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||
else
|
||||
texture.copyFrom(m, true);
|
||||
|
||||
m_timer.stop();
|
||||
}
|
||||
|
||||
void processFrameGPU(cv::ogl::Texture2D& texture, cv::ogl::Buffer& buffer, bool do_buffer)
|
||||
{
|
||||
cv::UMat u;
|
||||
|
||||
m_timer.reset();
|
||||
m_timer.start();
|
||||
|
||||
if (do_buffer)
|
||||
u = cv::ogl::mapGLBuffer(buffer);
|
||||
else
|
||||
cv::ogl::convertFromGLTexture2D(texture, u);
|
||||
|
||||
if (m_demo_processing)
|
||||
{
|
||||
// blur texture image with OpenCV on GPU with OpenCL
|
||||
cv::blur(u, u, cv::Size(15, 15));
|
||||
}
|
||||
|
||||
if (do_buffer)
|
||||
cv::ogl::unmapGLBuffer(u);
|
||||
else
|
||||
cv::ogl::convertToGLTexture2D(u, texture);
|
||||
|
||||
m_timer.stop();
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
int setup_pixel_format()
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 24;
|
||||
pfd.cRedBits = 8;
|
||||
pfd.cRedShift = 0;
|
||||
pfd.cGreenBits = 8;
|
||||
pfd.cGreenShift = 0;
|
||||
pfd.cBlueBits = 8;
|
||||
pfd.cBlueShift = 0;
|
||||
pfd.cAlphaBits = 8;
|
||||
pfd.cAlphaShift = 0;
|
||||
pfd.cAccumBits = 0;
|
||||
pfd.cAccumRedBits = 0;
|
||||
pfd.cAccumGreenBits = 0;
|
||||
pfd.cAccumBlueBits = 0;
|
||||
pfd.cAccumAlphaBits = 0;
|
||||
pfd.cDepthBits = 24;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.cAuxBuffers = 0;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
pfd.bReserved = 0;
|
||||
pfd.dwLayerMask = 0;
|
||||
pfd.dwVisibleMask = 0;
|
||||
pfd.dwDamageMask = 0;
|
||||
|
||||
int pfmt = ChoosePixelFormat(m_hDC, &pfd);
|
||||
if (pfmt == 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (SetPixelFormat(m_hDC, pfmt, &pfd) == 0)
|
||||
return -2;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
KeySym keycode_to_keysym(unsigned keycode)
|
||||
{ // note that XKeycodeToKeysym() is considered deprecated
|
||||
int keysyms_per_keycode_return = 0;
|
||||
KeySym *keysyms = XGetKeyboardMapping(m_display, keycode, 1, &keysyms_per_keycode_return);
|
||||
KeySym keysym = keysyms[0];
|
||||
XFree(keysyms);
|
||||
return keysym;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool use_buffer() { return m_use_buffer; }
|
||||
void toggle_buffer() { m_use_buffer = !m_use_buffer; }
|
||||
MODE get_mode() { return m_mode; }
|
||||
void set_mode(MODE mode) { m_mode = mode; }
|
||||
|
||||
private:
|
||||
bool m_shutdown;
|
||||
bool m_use_buffer;
|
||||
bool m_demo_processing;
|
||||
MODE m_mode;
|
||||
cv::String m_modeStr[2];
|
||||
#if defined(_WIN32)
|
||||
HDC m_hDC;
|
||||
HGLRC m_hRC;
|
||||
#elif defined(__linux__)
|
||||
GLXContext m_glctx;
|
||||
#endif
|
||||
cv::VideoCapture m_cap;
|
||||
cv::Mat m_frame_bgr;
|
||||
cv::Mat m_frame_rgba;
|
||||
cv::String m_oclDevName;
|
||||
};
|
||||
|
||||
static const char* keys =
|
||||
{
|
||||
"{c camera | 0 | camera id }"
|
||||
"{f file | | movie file name }"
|
||||
};
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
cv::CommandLineParser parser(argc, argv, keys);
|
||||
int camera_id = parser.get<int>("camera");
|
||||
string file = parser.get<string>("file");
|
||||
|
||||
parser.about(
|
||||
"\nA sample program demonstrating interoperability of OpenGL and OpenCL with OpenCV.\n\n"
|
||||
"Hot keys: \n"
|
||||
" SPACE - turn processing on/off\n"
|
||||
" 1 - process GL data through OpenCV on CPU\n"
|
||||
" 2 - process GL data through OpenCV on GPU (via OpenCL)\n"
|
||||
" 9 - toggle use of GL texture/GL buffer\n"
|
||||
" ESC - exit\n\n");
|
||||
|
||||
parser.printMessage();
|
||||
|
||||
cv::VideoCapture cap;
|
||||
|
||||
if (file.empty())
|
||||
cap.open(camera_id);
|
||||
else
|
||||
cap.open(file.c_str());
|
||||
|
||||
if (!cap.isOpened())
|
||||
{
|
||||
printf("can not open camera or video file\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int width = (int)cap.get(CAP_PROP_FRAME_WIDTH);
|
||||
int height = (int)cap.get(CAP_PROP_FRAME_HEIGHT);
|
||||
|
||||
#if defined(_WIN32)
|
||||
string wndname = "WGL Window";
|
||||
#elif defined(__linux__)
|
||||
string wndname = "GLX Window";
|
||||
#endif
|
||||
|
||||
GLWinApp app(width, height, wndname, cap);
|
||||
|
||||
try
|
||||
{
|
||||
app.create();
|
||||
return app.run();
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
cerr << "Exception: " << e.what() << endl;
|
||||
return 10;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cerr << "FATAL ERROR: Unknown exception" << endl;
|
||||
return 11;
|
||||
}
|
||||
}
|
222
3rdparty/opencv-4.5.4/samples/opengl/winapp.hpp
vendored
Normal file
222
3rdparty/opencv-4.5.4/samples/opengl/winapp.hpp
vendored
Normal file
@ -0,0 +1,222 @@
|
||||
#if defined(_WIN32)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#elif defined(__linux__)
|
||||
# include <X11/X.h>
|
||||
# include <X11/Xlib.h>
|
||||
# include <X11/Xutil.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#if defined(_WIN32)
|
||||
# include <GL/glu.h>
|
||||
#elif defined(__linux__)
|
||||
# include <GL/glx.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define WINCLASS "WinAppWnd"
|
||||
#endif
|
||||
|
||||
#define SAFE_RELEASE(p) if (p) { p->Release(); p = NULL; }
|
||||
|
||||
class WinApp
|
||||
{
|
||||
public:
|
||||
WinApp(int width, int height, std::string& window_name)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_window_name = window_name;
|
||||
#if defined(_WIN32)
|
||||
m_hInstance = ::GetModuleHandle(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~WinApp()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
::UnregisterClass(WINCLASS, m_hInstance);
|
||||
#endif
|
||||
}
|
||||
|
||||
int create()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
WNDCLASSEX wcex;
|
||||
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = &WinApp::StaticWndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = m_hInstance;
|
||||
wcex.hIcon = LoadIcon(0, IDI_APPLICATION);
|
||||
wcex.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wcex.hbrBackground = 0;
|
||||
wcex.lpszMenuName = 0L;
|
||||
wcex.lpszClassName = WINCLASS;
|
||||
wcex.hIconSm = 0;
|
||||
|
||||
ATOM wc = ::RegisterClassEx(&wcex);
|
||||
|
||||
RECT rc = { 0, 0, m_width, m_height };
|
||||
::AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
|
||||
|
||||
m_hWnd = ::CreateWindow(
|
||||
(LPCTSTR)wc, m_window_name.c_str(),
|
||||
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
rc.right - rc.left, rc.bottom - rc.top,
|
||||
NULL, NULL, m_hInstance, (void*)this);
|
||||
|
||||
if (!m_hWnd)
|
||||
return -1;
|
||||
|
||||
::ShowWindow(m_hWnd, SW_SHOW);
|
||||
::UpdateWindow(m_hWnd);
|
||||
::SetFocus(m_hWnd);
|
||||
#elif defined(__linux__)
|
||||
m_display = XOpenDisplay(NULL);
|
||||
|
||||
if (m_display == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_WM_DELETE_WINDOW = XInternAtom(m_display, "WM_DELETE_WINDOW", False);
|
||||
|
||||
static GLint visual_attributes[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
|
||||
m_visual_info = glXChooseVisual(m_display, 0, visual_attributes);
|
||||
|
||||
if (m_visual_info == NULL)
|
||||
{
|
||||
XCloseDisplay(m_display);
|
||||
return -2;
|
||||
}
|
||||
|
||||
Window root = DefaultRootWindow(m_display);
|
||||
|
||||
m_event_mask = ExposureMask | KeyPressMask;
|
||||
|
||||
XSetWindowAttributes window_attributes;
|
||||
window_attributes.colormap = XCreateColormap(m_display, root, m_visual_info->visual, AllocNone);
|
||||
window_attributes.event_mask = m_event_mask;
|
||||
|
||||
m_window = XCreateWindow(
|
||||
m_display, root, 0, 0, m_width, m_height, 0, m_visual_info->depth,
|
||||
InputOutput, m_visual_info->visual, CWColormap | CWEventMask, &window_attributes);
|
||||
|
||||
XMapWindow(m_display, m_window);
|
||||
XSetWMProtocols(m_display, m_window, &m_WM_DELETE_WINDOW, 1);
|
||||
XStoreName(m_display, m_window, m_window_name.c_str());
|
||||
#endif
|
||||
|
||||
return init();
|
||||
}
|
||||
|
||||
virtual void cleanup()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
::DestroyWindow(m_hWnd);
|
||||
#elif defined(__linux__)
|
||||
XDestroyWindow(m_display, m_window);
|
||||
XCloseDisplay(m_display);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) = 0;
|
||||
#endif
|
||||
|
||||
int run()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
MSG msg;
|
||||
|
||||
::ZeroMemory(&msg, sizeof(msg));
|
||||
|
||||
while (msg.message != WM_QUIT)
|
||||
{
|
||||
if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||
{
|
||||
::TranslateMessage(&msg);
|
||||
::DispatchMessage(&msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
idle();
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<int>(msg.wParam);
|
||||
#elif defined(__linux__)
|
||||
m_end_loop = false;
|
||||
|
||||
do {
|
||||
XEvent e;
|
||||
|
||||
if (!XCheckWindowEvent(m_display, m_window, m_event_mask, &e) || !handle_event(e))
|
||||
{
|
||||
idle();
|
||||
}
|
||||
} while (!m_end_loop);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
#if defined(_WIN32)
|
||||
static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
WinApp* pWnd;
|
||||
|
||||
if (message == WM_NCCREATE)
|
||||
{
|
||||
LPCREATESTRUCT pCreateStruct = ((LPCREATESTRUCT)lParam);
|
||||
pWnd = (WinApp*)(pCreateStruct->lpCreateParams);
|
||||
::SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)pWnd);
|
||||
}
|
||||
|
||||
pWnd = GetObjectFromWindow(hWnd);
|
||||
|
||||
if (pWnd)
|
||||
return pWnd->WndProc(hWnd, message, wParam, lParam);
|
||||
else
|
||||
return ::DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
inline static WinApp* GetObjectFromWindow(HWND hWnd)
|
||||
{
|
||||
return (WinApp*)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
virtual int handle_event(XEvent& e) = 0;
|
||||
#endif
|
||||
|
||||
virtual int init() = 0;
|
||||
virtual int render() = 0;
|
||||
|
||||
virtual void idle() = 0;
|
||||
|
||||
#if defined(_WIN32)
|
||||
HINSTANCE m_hInstance;
|
||||
HWND m_hWnd;
|
||||
#elif defined(__linux__)
|
||||
Display* m_display;
|
||||
XVisualInfo* m_visual_info;
|
||||
Window m_window;
|
||||
long m_event_mask;
|
||||
Atom m_WM_DELETE_WINDOW;
|
||||
bool m_end_loop;
|
||||
#endif
|
||||
int m_width;
|
||||
int m_height;
|
||||
std::string m_window_name;
|
||||
cv::TickMeter m_timer;
|
||||
};
|
Reference in New Issue
Block a user