feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
21
3rdparty/opencv-4.5.4/samples/va_intel/CMakeLists.txt
vendored
Normal file
21
3rdparty/opencv-4.5.4/samples/va_intel/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
ocv_install_example_src(opencl *.cpp *.inc CMakeLists.txt)
|
||||
|
||||
set(OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS
|
||||
opencv_core
|
||||
opencv_imgproc
|
||||
opencv_imgcodecs
|
||||
opencv_videoio
|
||||
opencv_highgui)
|
||||
ocv_check_dependencies(${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(va_intel_samples)
|
||||
ocv_include_modules_recurse(${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS})
|
||||
file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
|
||||
foreach(sample_filename ${all_samples})
|
||||
ocv_define_sample(tgt ${sample_filename} va_intel)
|
||||
ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS} ${VA_LIBRARIES})
|
||||
endforeach()
|
238
3rdparty/opencv-4.5.4/samples/va_intel/display.cpp.inc
vendored
Normal file
238
3rdparty/opencv-4.5.4/samples/va_intel/display.cpp.inc
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <va/va.h>
|
||||
# include <va/va_drm.h>
|
||||
|
||||
#include "opencv2/core.hpp" // cv::format()
|
||||
|
||||
namespace va {
|
||||
|
||||
bool openDisplay();
|
||||
void closeDisplay();
|
||||
|
||||
VADisplay display = NULL;
|
||||
bool initialized = false;
|
||||
|
||||
#define VA_INTEL_PCI_DIR "/sys/bus/pci/devices"
|
||||
#define VA_INTEL_DRI_DIR "/dev/dri/"
|
||||
#define VA_INTEL_PCI_DISPLAY_CONTROLLER_CLASS 0x03
|
||||
|
||||
static unsigned readId(const char* devName, const char* idName);
|
||||
static int findAdapter(unsigned desiredVendorId);
|
||||
|
||||
int drmfd = -1;
|
||||
|
||||
class Directory
|
||||
{
|
||||
typedef int (*fsort)(const struct dirent**, const struct dirent**);
|
||||
public:
|
||||
Directory(const char* path)
|
||||
{
|
||||
dirEntries = 0;
|
||||
numEntries = scandir(path, &dirEntries, filterFunc, (fsort)alphasort);
|
||||
}
|
||||
~Directory()
|
||||
{
|
||||
if (numEntries && dirEntries)
|
||||
{
|
||||
for (int i = 0; i < numEntries; ++i)
|
||||
free(dirEntries[i]);
|
||||
free(dirEntries);
|
||||
}
|
||||
}
|
||||
int count() const
|
||||
{
|
||||
return numEntries;
|
||||
}
|
||||
const struct dirent* operator[](int index) const
|
||||
{
|
||||
return ((dirEntries != 0) && (index >= 0) && (index < numEntries)) ? dirEntries[index] : 0;
|
||||
}
|
||||
protected:
|
||||
static int filterFunc(const struct dirent* dir)
|
||||
{
|
||||
if (!dir) return 0;
|
||||
if (!strcmp(dir->d_name, ".")) return 0;
|
||||
if (!strcmp(dir->d_name, "..")) return 0;
|
||||
return 1;
|
||||
}
|
||||
private:
|
||||
int numEntries;
|
||||
struct dirent** dirEntries;
|
||||
};
|
||||
|
||||
static unsigned readId(const char* devName, const char* idName)
|
||||
{
|
||||
long int id = 0;
|
||||
|
||||
std::string fileName = cv::format("%s/%s/%s", VA_INTEL_PCI_DIR, devName, idName);
|
||||
|
||||
FILE* file = fopen(fileName.c_str(), "r");
|
||||
if (file)
|
||||
{
|
||||
char str[16] = "";
|
||||
if (fgets(str, sizeof(str), file))
|
||||
id = strtol(str, NULL, 16);
|
||||
fclose(file);
|
||||
}
|
||||
return (unsigned)id;
|
||||
}
|
||||
|
||||
static int findAdapter(unsigned desiredVendorId)
|
||||
{
|
||||
int adapterIndex = -1;
|
||||
|
||||
Directory dir(VA_INTEL_PCI_DIR);
|
||||
|
||||
for (int i = 0; i < dir.count(); ++i)
|
||||
{
|
||||
const char* name = dir[i]->d_name;
|
||||
|
||||
unsigned classId = readId(name, "class");
|
||||
if ((classId >> 16) == VA_INTEL_PCI_DISPLAY_CONTROLLER_CLASS)
|
||||
{
|
||||
unsigned vendorId = readId(name, "vendor");
|
||||
if (vendorId == desiredVendorId)
|
||||
{
|
||||
std::string subdirName = cv::format("%s/%s/%s", VA_INTEL_PCI_DIR, name, "drm");
|
||||
Directory subdir(subdirName.c_str());
|
||||
for (int j = 0; j < subdir.count(); ++j)
|
||||
{
|
||||
if (!strncmp(subdir[j]->d_name, "card", 4))
|
||||
{
|
||||
adapterIndex = strtoul(subdir[j]->d_name + 4, NULL, 10);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return adapterIndex;
|
||||
}
|
||||
|
||||
class NodeInfo
|
||||
{
|
||||
enum { NUM_NODES = 2 };
|
||||
public:
|
||||
NodeInfo(int adapterIndex)
|
||||
{
|
||||
const char* names[NUM_NODES] = { "renderD", "card" };
|
||||
int numbers[NUM_NODES];
|
||||
numbers[0] = adapterIndex+128;
|
||||
numbers[1] = adapterIndex;
|
||||
for (int i = 0; i < NUM_NODES; ++i)
|
||||
{
|
||||
paths[i] = cv::format("%s%s%d", VA_INTEL_DRI_DIR, names[i], numbers[i]);
|
||||
}
|
||||
}
|
||||
~NodeInfo()
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
int count() const
|
||||
{
|
||||
return NUM_NODES;
|
||||
}
|
||||
const char* path(int index) const
|
||||
{
|
||||
return ((index >= 0) && (index < NUM_NODES)) ? paths[index].c_str() : 0;
|
||||
}
|
||||
private:
|
||||
std::string paths[NUM_NODES];
|
||||
};
|
||||
|
||||
static bool openDeviceIntel();
|
||||
static bool openDeviceGeneric();
|
||||
|
||||
static bool openDeviceIntel()
|
||||
{
|
||||
const unsigned IntelVendorID = 0x8086;
|
||||
|
||||
int adapterIndex = findAdapter(IntelVendorID);
|
||||
if (adapterIndex >= 0)
|
||||
{
|
||||
NodeInfo nodes(adapterIndex);
|
||||
|
||||
for (int i = 0; i < nodes.count(); ++i)
|
||||
{
|
||||
drmfd = open(nodes.path(i), O_RDWR);
|
||||
if (drmfd >= 0)
|
||||
{
|
||||
display = vaGetDisplayDRM(drmfd);
|
||||
if (display)
|
||||
return true;
|
||||
close(drmfd);
|
||||
drmfd = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool openDeviceGeneric()
|
||||
{
|
||||
static const char* device_paths[] = { "/dev/dri/renderD128", "/dev/dri/card0" };
|
||||
static const int num_devices = sizeof(device_paths) / sizeof(device_paths[0]);
|
||||
|
||||
for (int i = 0; i < num_devices; ++i)
|
||||
{
|
||||
drmfd = open(device_paths[i], O_RDWR);
|
||||
if (drmfd >= 0)
|
||||
{
|
||||
display = vaGetDisplayDRM(drmfd);
|
||||
if (display)
|
||||
return true;
|
||||
close(drmfd);
|
||||
drmfd = -1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool openDisplay()
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
drmfd = -1;
|
||||
display = 0;
|
||||
|
||||
if (openDeviceIntel() || openDeviceGeneric())
|
||||
{
|
||||
int majorVersion = 0, minorVersion = 0;
|
||||
if (vaInitialize(display, &majorVersion, &minorVersion) == VA_STATUS_SUCCESS)
|
||||
{
|
||||
initialized = true;
|
||||
return true;
|
||||
}
|
||||
close(drmfd);
|
||||
display = 0;
|
||||
drmfd = -1;
|
||||
}
|
||||
return false; // Can't open VA display
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void closeDisplay()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
if (display)
|
||||
vaTerminate(display);
|
||||
if (drmfd >= 0)
|
||||
close(drmfd);
|
||||
display = 0;
|
||||
drmfd = -1;
|
||||
initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace va
|
266
3rdparty/opencv-4.5.4/samples/va_intel/va_intel_interop.cpp
vendored
Normal file
266
3rdparty/opencv-4.5.4/samples/va_intel/va_intel_interop.cpp
vendored
Normal file
@ -0,0 +1,266 @@
|
||||
/* origin: libva-1.3.1/test/decode/mpeg2vldemo.cpp */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <va/va.h>
|
||||
|
||||
#include "display.cpp.inc"
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core/va_intel.hpp"
|
||||
|
||||
#define CHECK_VASTATUS(_status,_func) \
|
||||
if (_status != VA_STATUS_SUCCESS) \
|
||||
{ \
|
||||
char str[256]; \
|
||||
snprintf(str, sizeof(str)-1, "%s:%s (%d) failed(status=0x%08x),exit\n", __func__, _func, __LINE__, _status); \
|
||||
throw std::runtime_error(str); \
|
||||
}
|
||||
|
||||
class CmdlineParser
|
||||
{
|
||||
public:
|
||||
enum { fnInput=0, fnOutput1, fnOutput2, _fnNumFiles }; // file name indices
|
||||
CmdlineParser(int argc, char** argv):
|
||||
m_argc(argc), m_argv(argv)
|
||||
{}
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: va_intel_interop [-f] infile outfile1 outfile2\n\n"
|
||||
"Interop ON/OFF version\n\n"
|
||||
"where: -f option indicates interop is off (fallback mode); interop is on by default\n"
|
||||
" infile is to be existing, contains input image data (bmp, jpg, png, tiff, etc)\n"
|
||||
" outfile1 is to be created, contains original surface data (NV12)\n"
|
||||
" outfile2 is to be created, contains processed surface data (NV12)\n");
|
||||
}
|
||||
// true => go, false => usage/exit; extra args/unknown options are ignored for simplicity
|
||||
bool run()
|
||||
{
|
||||
int n = 0;
|
||||
for (int i = 0; i < _fnNumFiles; ++i)
|
||||
m_files[i] = 0;
|
||||
m_interop = true;
|
||||
for (int i = 1; i < m_argc; ++i)
|
||||
{
|
||||
const char *arg = m_argv[i];
|
||||
if (arg[0] == '-') // option
|
||||
{
|
||||
if (!strcmp(arg, "-f"))
|
||||
m_interop = false;
|
||||
}
|
||||
else // parameter
|
||||
{
|
||||
if (n < _fnNumFiles)
|
||||
m_files[n++] = arg;
|
||||
}
|
||||
}
|
||||
return bool(n >= _fnNumFiles);
|
||||
}
|
||||
bool isInterop() const
|
||||
{
|
||||
return m_interop;
|
||||
}
|
||||
const char* getFile(int n) const
|
||||
{
|
||||
return ((n >= 0) && (n < _fnNumFiles)) ? m_files[n] : 0;
|
||||
}
|
||||
private:
|
||||
int m_argc;
|
||||
char** m_argv;
|
||||
const char* m_files[_fnNumFiles];
|
||||
bool m_interop;
|
||||
};
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
enum UNITS
|
||||
{
|
||||
USEC = 0,
|
||||
MSEC,
|
||||
SEC
|
||||
};
|
||||
|
||||
Timer() : m_t0(0), m_diff(0)
|
||||
{
|
||||
m_tick_frequency = (float)cv::getTickFrequency();
|
||||
|
||||
m_unit_mul[USEC] = 1000000;
|
||||
m_unit_mul[MSEC] = 1000;
|
||||
m_unit_mul[SEC] = 1;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_t0 = m_diff = 0;
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
m_t0 = cv::getTickCount();
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
m_diff = cv::getTickCount() - m_t0;
|
||||
}
|
||||
|
||||
float time(UNITS u = MSEC)
|
||||
{
|
||||
float sec = m_diff / m_tick_frequency;
|
||||
|
||||
return sec * m_unit_mul[u];
|
||||
}
|
||||
|
||||
public:
|
||||
float m_tick_frequency;
|
||||
int64 m_t0;
|
||||
int64 m_diff;
|
||||
int m_unit_mul[3];
|
||||
};
|
||||
|
||||
static void checkIfAvailableYUV420()
|
||||
{
|
||||
VAEntrypoint entrypoints[5];
|
||||
int num_entrypoints,vld_entrypoint;
|
||||
VAConfigAttrib attrib;
|
||||
VAStatus status;
|
||||
|
||||
status = vaQueryConfigEntrypoints(va::display, VAProfileMPEG2Main, entrypoints, &num_entrypoints);
|
||||
CHECK_VASTATUS(status, "vaQueryConfigEntrypoints");
|
||||
|
||||
for (vld_entrypoint = 0; vld_entrypoint < num_entrypoints; ++vld_entrypoint)
|
||||
{
|
||||
if (entrypoints[vld_entrypoint] == VAEntrypointVLD)
|
||||
break;
|
||||
}
|
||||
if (vld_entrypoint == num_entrypoints)
|
||||
throw std::runtime_error("Failed to find VLD entry point");
|
||||
|
||||
attrib.type = VAConfigAttribRTFormat;
|
||||
vaGetConfigAttributes(va::display, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1);
|
||||
if ((attrib.value & VA_RT_FORMAT_YUV420) == 0)
|
||||
throw std::runtime_error("Desired YUV420 RT format not found");
|
||||
}
|
||||
|
||||
static cv::UMat readImage(const char* fileName)
|
||||
{
|
||||
cv::Mat m = cv::imread(fileName);
|
||||
if (m.empty())
|
||||
throw std::runtime_error("Failed to load image: " + std::string(fileName));
|
||||
return m.getUMat(cv::ACCESS_RW);
|
||||
}
|
||||
|
||||
static void writeImage(const cv::UMat& u, const char* fileName, bool doInterop)
|
||||
{
|
||||
std::string fn = std::string(fileName) + std::string(doInterop ? ".on" : ".off") + std::string(".jpg");
|
||||
cv::imwrite(fn, u);
|
||||
}
|
||||
|
||||
static float run(const char* infile, const char* outfile1, const char* outfile2, bool doInterop)
|
||||
{
|
||||
VASurfaceID surface;
|
||||
VAStatus status;
|
||||
Timer t;
|
||||
|
||||
// initialize CL context for CL/VA interop
|
||||
cv::va_intel::ocl::initializeContextFromVA(va::display, doInterop);
|
||||
|
||||
// load input image
|
||||
cv::UMat u1 = readImage(infile);
|
||||
cv::Size size2 = u1.size();
|
||||
status = vaCreateSurfaces(va::display, VA_RT_FORMAT_YUV420, size2.width, size2.height, &surface, 1, NULL, 0);
|
||||
CHECK_VASTATUS(status, "vaCreateSurfaces");
|
||||
|
||||
// transfer image into VA surface, make sure all CL initialization is done (kernels etc)
|
||||
cv::va_intel::convertToVASurface(va::display, u1, surface, size2);
|
||||
cv::va_intel::convertFromVASurface(va::display, surface, size2, u1);
|
||||
cv::UMat u2;
|
||||
cv::blur(u1, u2, cv::Size(7, 7), cv::Point(-3, -3));
|
||||
|
||||
// measure performance on some image processing
|
||||
writeImage(u1, outfile1, doInterop);
|
||||
t.start();
|
||||
cv::va_intel::convertFromVASurface(va::display, surface, size2, u1);
|
||||
cv::blur(u1, u2, cv::Size(7, 7), cv::Point(-3, -3));
|
||||
cv::va_intel::convertToVASurface(va::display, u2, surface, size2);
|
||||
t.stop();
|
||||
writeImage(u2, outfile2, doInterop);
|
||||
|
||||
vaDestroySurfaces(va::display, &surface,1);
|
||||
|
||||
return t.time(Timer::MSEC);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdlineParser cmd(argc, argv);
|
||||
if (!cmd.run())
|
||||
{
|
||||
cmd.usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!va::openDisplay())
|
||||
throw std::runtime_error("Failed to open VA display for CL-VA interoperability");
|
||||
std::cout << "VA display opened successfully" << std::endl;
|
||||
|
||||
checkIfAvailableYUV420();
|
||||
|
||||
const char* infile = cmd.getFile(CmdlineParser::fnInput);
|
||||
const char* outfile1 = cmd.getFile(CmdlineParser::fnOutput1);
|
||||
const char* outfile2 = cmd.getFile(CmdlineParser::fnOutput2);
|
||||
bool doInterop = cmd.isInterop();
|
||||
|
||||
float time = run(infile, outfile1, outfile2, doInterop);
|
||||
|
||||
std::cout << "Interop " << (doInterop ? "ON " : "OFF") << ": processing time, msec: " << time << std::endl;
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
std::cerr << "ERROR: " << ex.what() << std::endl;
|
||||
}
|
||||
|
||||
va::closeDisplay();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user