diff --git a/.vscode/launch.json b/.vscode/launch.json index 21045eb01..a40637baf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,8 +8,8 @@ "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/_debugbuild/aprapipesut", - "args": ["--run_test=virtualcamerasink_tests/perf"], + "program": "${workspaceFolder}/_build/aprapipesut", + "args": ["--run_test=logger_tests"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/README.md b/README.md index 744934e73..2792f9c86 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ git clone --recursive https://github.com/Apra-Labs/ApraPipes.git ## Prerequisites * Run ```sudo apt-get update && sudo apt-get install build-essential``` to get latest build tools -* CMake minimum version 3.14 - Follow [this article](https://anglehit.com/how-to-install-the-latest-version-of-cmake-via-command-line/) to update cmake +* CMake minimum version 3.17 - Follow [this article](https://anglehit.com/how-to-install-the-latest-version-of-cmake-via-command-line/) to update cmake * ffmpeg ``` sudo apt install yasm -y diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 14b1cf0ad..5726376df 100755 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -26,7 +26,7 @@ IF(ENABLE_ARM64) ENDIF(ENABLE_ARM64) project(APRAPIPES) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) hunter_add_package(Boost COMPONENTS system thread filesystem serialization log chrono) find_package(Boost CONFIG REQUIRED system thread filesystem serialization log chrono) @@ -60,13 +60,13 @@ find_library(LIB_AVFORMAT libavformat.a PATHS ${FFMPEG_ROOT}/libavformat NO_DEFA find_library(LIB_AVCODEC libavcodec.a PATHS ${FFMPEG_ROOT}/libavcodec NO_DEFAULT_PATH) find_library(LIB_AVUTIL libavutil.a PATHS ${FFMPEG_ROOT}/libavutil NO_DEFAULT_PATH) find_library(LIB_FFSWR libswresample.a PATHS ${FFMPEG_ROOT}/libswresample NO_DEFAULT_PATH) -find_library(LIB_ZXING libZXing.a PATHS ../thirdparty/zxing-cpp/_install/lib NO_DEFAULT_PATH) +find_library(LIB_ZXING libZXing.a PATHS ../thirdparty/zxing-cpp/_build/zxing-cpp.release/core NO_DEFAULT_PATH) IF(ENABLE_CUDA) IF(ENABLE_ARM64) SET(NVCODEC_LIB) - SET ( JETSON_MULTIMEDIA_LIB_INCLUDE "/usr/src/jetson_multimedia_api/include" ) + SET ( JETSON_MULTIMEDIA_LIB_INCLUDE "/usr/src/jetson_multimedia_api/include" ) list(APPEND CMAKE_PREFIX_PATH /usr/lib/aarch64-linux-gnu/tegra) list(APPEND CMAKE_PREFIX_PATH /usr/lib/aarch64-linux-gnu/tegra-egl) @@ -76,8 +76,8 @@ IF(ENABLE_CUDA) find_library(EGLLIB EGL) find_library(GLESv2LIB GLESv2) find_library(X11LIB X11) - find_library(NVBUFUTILSLIB nvbuf_utils) - find_library(EGLSTREAM_CAMCONSUMER_LIB nveglstream_camconsumer) + find_library(NVBUFUTILSLIB nvbufsurface) + #find_library(EGLSTREAM_CAMCONSUMER_LIB nveglstream_camconsumer) find_library(NVARGUS_SOCKETCLINET_LIB nvargus_socketclient) find_package(Curses REQUIRED) @@ -89,7 +89,7 @@ IF(ENABLE_CUDA) ${EGLLIB} ${GLESv2LIB} ${X11LIB} - ${EGLSTREAM_CAMCONSUMER_LIB} + #${EGLSTREAM_CAMCONSUMER_LIB} ${NVARGUS_SOCKETCLINET_LIB} ) ELSE() @@ -103,7 +103,8 @@ IF(ENABLE_CUDA) libnppig_static.a libnppicc_static.a libnppidei_static.a - libnppial_static.a + libnppial_static.a + libnppif_static.a libculibos.a ) @@ -113,11 +114,11 @@ ENDIF(ENABLE_CUDA) include_directories(AFTER SYSTEM include ${BOOST_ROOT}/include ${OPENCV_ROOT}/include/opencv4 - /usr/local/cuda-10.2/include + /usr/local/cuda/include ../thirdparty/Video_Codec_SDK_10.0.26/Interface ../thirdparty/ffmpeg/include ${CURSES_INCLUDE_DIR} - ../thirdparty/zxing-cpp/_install/include/ZXing + ../thirdparty/zxing-cpp/core/src ) # ApraPipes library @@ -264,11 +265,11 @@ SET(CUDA_IP_FILES src/CCNPPI.cpp src/EffectsKernel.cu src/EffectsNPPI.cpp - src/GaussianBlur.cpp + #src/GaussianBlur.cpp src/OverlayKernel.cu src/OverlayNPPI.cpp - src/ResizeNPPI.cpp - src/RotateNPPI.cpp +# src/ResizeNPPI.cpp +# src/RotateNPPI.cpp ) IF(ENABLE_ARM64) @@ -287,10 +288,10 @@ IF(ENABLE_ARM64) src/NvArgusCamera.cpp src/NvV4L2Camera.cpp src/NvV4L2CameraHelper.cpp - src/EglRenderer.cpp - src/NvEglRenderer.cpp +# src/EglRenderer.cpp +# src/NvEglRenderer.cpp src/DMAUtils.cpp - src/NvTransform.cpp +# src/NvTransform.cpp src/ApraEGLDisplay.cpp src/DMAFDToHostCopy.cpp ) @@ -374,26 +375,26 @@ IF (ENABLE_ARM64) test/h264encoderv4l2helper_tests.cpp test/h264encoderv4l2_tests.cpp test/nvarguscamerahelper_tests.cpp - test/nvarguscamera_tests.cpp - test/nvv4l2camera_test.cpp +# test/nvarguscamera_tests.cpp +# test/nvv4l2camera_test.cpp test/nvv4l2camerahelper_test.cpp - test/nvtransform_tests.cpp - test/eglrenderer_test.cpp +# test/nvtransform_tests.cpp +# test/eglrenderer_test.cpp ) ENDIF(ENABLE_ARM64) IF (ENABLE_CUDA) SET(CUDA_UT_FILES test/cudamemcopy_tests.cpp - test/resizenppi_tests.cpp - test/rotatenppi_tests.cpp +# test/resizenppi_tests.cpp +# test/rotatenppi_tests.cpp ) IF(ENABLE_ARM64) - SET(CUDA_UT_FILES ${CUDA_UT_FILES} - test/cuda_arm_tests.cpp - test/apraegldisplay_tests.cpp - test/frame_factory_test_dma.cpp + SET(CUDA_UT_FILES ${CUDA_UT_FILES} +# test/cuda_arm_tests.cpp +# test/apraegldisplay_tests.cpp +# test/frame_factory_test_dma.cpp ) ELSE() SET(CUDA_UT_FILES ${CUDA_UT_FILES} diff --git a/base/include/DMAAllocator.h b/base/include/DMAAllocator.h index 0675cdf07..d750d26f2 100755 --- a/base/include/DMAAllocator.h +++ b/base/include/DMAAllocator.h @@ -1,7 +1,7 @@ #pragma once #include "Allocators.h" #include "DMAFDWrapper.h" -#include "nvbuf_utils.h" +#include "nvbufsurface.h" #include "FrameMetadataFactory.h" #include "ApraEGLDisplay.h" #include "Logger.h" @@ -12,31 +12,31 @@ class DMAAllocator : public HostAllocator private: std::vector mDMAFDWrapperArr; int mFreeDMACount; - NvBufferColorFormat mColorFormat; + NvBufSurfaceColorFormat mColorFormat; EGLDisplay mEglDisplay; int mHeight; int mWidth; int mCount; - static NvBufferColorFormat getColorFormat(ImageMetadata::ImageType imageType) + static NvBufSurfaceColorFormat getColorFormat(ImageMetadata::ImageType imageType) { - NvBufferColorFormat colorFormat; + NvBufSurfaceColorFormat colorFormat; switch (imageType) { case ImageMetadata::UYVY: - colorFormat = NvBufferColorFormat_UYVY; + colorFormat = NVBUF_COLOR_FORMAT_UYVY; break; case ImageMetadata::RGBA: - colorFormat = NvBufferColorFormat_ABGR32; + colorFormat = NVBUF_COLOR_FORMAT_RGBA; break; case ImageMetadata::BGRA: - colorFormat = NvBufferColorFormat_ARGB32; + colorFormat = NVBUF_COLOR_FORMAT_BGRA; break; case ImageMetadata::YUV420: - colorFormat = NvBufferColorFormat_YUV420; + colorFormat = NVBUF_COLOR_FORMAT_YUV420; break; case ImageMetadata::NV12: - colorFormat = NvBufferColorFormat_NV12; + colorFormat = NVBUF_COLOR_FORMAT_NV12; break; default: throw AIPException(AIP_FATAL, "Expected Actual<" + std::to_string(imageType) + ">"); @@ -97,14 +97,14 @@ class DMAAllocator : public HostAllocator auto eglDisplay = ApraEGLDisplay::getEGLDisplay(); auto colorFormat = getColorFormat(imageType); - auto dmaFDWrapper = DMAFDWrapper::create(0, width, height, colorFormat, NvBufferLayout_Pitch, eglDisplay); + auto dmaFDWrapper = DMAFDWrapper::create(0, width, height, colorFormat, NVBUF_LAYOUT_PITCH, eglDisplay); if (!dmaFDWrapper) { LOG_ERROR << "Failed to allocate dmaFDWrapper"; throw AIPException(AIP_FATAL, "Memory Allocation Failed."); } - - NvBufferParams fdParams; +#ifdef JP512_TBD + NvBufSurfaceParams fdParams; if (NvBufferGetParams(dmaFDWrapper->getFd(), &fdParams)) { throw AIPException(AIP_FATAL, "NvBufferGetParams Failed."); @@ -155,7 +155,7 @@ class DMAAllocator : public HostAllocator throw AIPException(AIP_FATAL, "Expected Raw Image or RAW_IMAGE_PLANAR. Actual<" + std::to_string(frameType) + ">"); break; } - +#endif delete dmaFDWrapper; } @@ -163,7 +163,7 @@ class DMAAllocator : public HostAllocator { if (mFreeDMACount == 0) { - auto dmaFDWrapper = DMAFDWrapper::create(mCount++, mWidth, mHeight, mColorFormat, NvBufferLayout_Pitch, mEglDisplay); + auto dmaFDWrapper = DMAFDWrapper::create(mCount++, mWidth, mHeight, mColorFormat, NVBUF_LAYOUT_PITCH, mEglDisplay); if (!dmaFDWrapper) { LOG_ERROR << "Failed to allocate dmaFDWrapper"; diff --git a/base/include/DMAFDWrapper.h b/base/include/DMAFDWrapper.h index 50d28efb2..9dd8ffcd5 100644 --- a/base/include/DMAFDWrapper.h +++ b/base/include/DMAFDWrapper.h @@ -1,5 +1,5 @@ #pragma once -#include "nvbuf_utils.h" +#include "nvbufsurface.h" #include "EGL/egl.h" #include "cudaEGL.h" @@ -8,8 +8,8 @@ class DMAFDWrapper public: /* Always use this static method to create DMAFDWrapper */ static DMAFDWrapper *create(int index, int width, int height, - NvBufferColorFormat colorFormat, - NvBufferLayout layout, EGLDisplay eglDisplay); + NvBufSurfaceColorFormat colorFormat, + NvBufSurfaceLayout layout, EGLDisplay eglDisplay); virtual ~DMAFDWrapper(); @@ -50,4 +50,4 @@ class DMAFDWrapper const int index; const void* clientData; -}; \ No newline at end of file +}; diff --git a/base/include/DMAUtils.h b/base/include/DMAUtils.h index 1f834f1f7..8c2b46595 100644 --- a/base/include/DMAUtils.h +++ b/base/include/DMAUtils.h @@ -1,6 +1,6 @@ #pragma once -#include "nvbuf_utils.h" +//#include "nvbuf_utils.h" #include "EGL/egl.h" #include "cudaEGL.h" diff --git a/base/include/Logger.h b/base/include/Logger.h index 09aafc82e..94feffd2e 100755 --- a/base/include/Logger.h +++ b/base/include/Logger.h @@ -50,7 +50,7 @@ class Logger { static void initLogger(LoggerProps props); static Logger* getLogger(); static void setLogLevel(boost::log::trivial::severity_level severity); - static void setListener(void(*cb)(std::string&)); + static void setListener(void(*cb)(const std::string&)); virtual ~Logger(); @@ -59,7 +59,7 @@ class Logger { void setFileLog(bool enableLog); bool push(boost::log::trivial::severity_level level, std::ostringstream& stream); - void _setListener(void(*cb)(std::string&)); + void _setListener(void(*cb)(const std::string&)); std::ostringstream& pre(std::ostringstream& stream, boost::log::trivial::severity_level lvl); std::ostringstream& aipexceptionPre(std::ostringstream& stream, boost::log::trivial::severity_level lvl,int type); @@ -72,12 +72,11 @@ class Logger { threadsafe_que mQue; boost::thread myThread; bool run(); - bool process(std::string& message); + bool process(const std::string& message); bool mRunning; - bool logDisabled; LoggerProps mProps; - void(*mListener)(std::string&); + void(*mListener)(const std::string&); static boost::shared_ptr instance; boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg; diff --git a/base/include/NvV4L2CameraHelper.h b/base/include/NvV4L2CameraHelper.h index 2d66aa8a8..950ef4e0c 100644 --- a/base/include/NvV4L2CameraHelper.h +++ b/base/include/NvV4L2CameraHelper.h @@ -4,7 +4,9 @@ #include #include "ExtFrame.h" #include "NvUtils.h" -#include "nvbuf_utils.h" +#ifdef JP512_TBD + #include "nvbuf_utils.h" +#endif #include #include diff --git a/base/include/QRReader.h b/base/include/QRReader.h index 481bfabdc..43e79fee7 100644 --- a/base/include/QRReader.h +++ b/base/include/QRReader.h @@ -2,11 +2,27 @@ #include "Module.h" #include "ReadBarcode.h" +#include "TextUtfEncoding.h" class QRReaderProps : public ModuleProps { public: - QRReaderProps() : ModuleProps() {} + QRReaderProps(bool _tryHarder = false, bool _saveQRImages = false, string _qrImagesPath = "", int _frameRotationCounter = 10) : ModuleProps() + { + tryHarder = _tryHarder; + saveQRImages = _saveQRImages; + qrImagesPath = _qrImagesPath; + frameRotationCounter = _frameRotationCounter; + } + + size_t getSerializeSize() + { + return ModuleProps::getSerializeSize(); + } + bool tryHarder; + bool saveQRImages; + string qrImagesPath; + int frameRotationCounter; }; class QRReader : public Module diff --git a/base/src/DMAFDWrapper.cpp b/base/src/DMAFDWrapper.cpp index 4d99bbc6e..6219b086c 100644 --- a/base/src/DMAFDWrapper.cpp +++ b/base/src/DMAFDWrapper.cpp @@ -1,21 +1,23 @@ #include "DMAFDWrapper.h" #include "DMAUtils.h" -#include "nvbuf_utils.h" +#ifdef JP512_TBD + #include "nvbuf_utils.h" +#endif #include "Logger.h" #include "AIPExceptions.h" #include "cuda_runtime.h" DMAFDWrapper *DMAFDWrapper::create(int index, int width, int height, - NvBufferColorFormat colorFormat, - NvBufferLayout layout, EGLDisplay eglDisplay) + NvBufSurfaceColorFormat colorFormat, + NvBufSurfaceLayout layout, EGLDisplay eglDisplay) { DMAFDWrapper *buffer = new DMAFDWrapper(index, eglDisplay); if (!buffer) { return nullptr; } - +#ifdef JP512_TBD NvBufferCreateParams inputParams = {0}; inputParams.width = width; @@ -77,7 +79,7 @@ DMAFDWrapper *DMAFDWrapper::create(int index, int width, int height, cudaFree(0); buffer->cudaPtr = DMAUtils::getCudaPtr(buffer->eglImage, &buffer->pResource, buffer->eglFrame, eglDisplay); } - +#endif return buffer; } @@ -99,7 +101,7 @@ DMAFDWrapper::~DMAFDWrapper() cudaFree(0); DMAUtils::freeCudaPtr(eglImage, &pResource, eglDisplay); } - +#ifdef JP512_TBD if (hostPtr) { auto res = NvBufferMemUnMap(m_fd, 0, &hostPtr); @@ -132,15 +134,17 @@ DMAFDWrapper::~DMAFDWrapper() NvBufferDestroy(m_fd); m_fd = -1; } +#endif } void *DMAFDWrapper::getHostPtr() { +#ifdef JP512_TBD if (NvBufferMemSyncForCpu(m_fd, 0, &hostPtr)) { throw AIPException(AIP_FATAL, "NvBufferMemSyncForCpu FAILED."); } - +#endif return hostPtr; } @@ -151,21 +155,23 @@ void *DMAFDWrapper::getHostPtrY() void *DMAFDWrapper::getHostPtrU() { +#ifdef JP512_TBD if (NvBufferMemSyncForCpu(m_fd, 1, &hostPtrU)) { throw AIPException(AIP_FATAL, "NvBufferMemSyncForCpu FAILED."); } - +#endif return hostPtrU; } void *DMAFDWrapper::getHostPtrV() { +#ifdef JP512_TBD if (NvBufferMemSyncForCpu(m_fd, 2, &hostPtrV)) { throw AIPException(AIP_FATAL, "NvBufferMemSyncForCpu FAILED."); } - +#endif return hostPtrV; } diff --git a/base/src/DMAUtils.cpp b/base/src/DMAUtils.cpp index 9f3faa392..8df0d0ea9 100644 --- a/base/src/DMAUtils.cpp +++ b/base/src/DMAUtils.cpp @@ -1,8 +1,13 @@ #include "DMAUtils.h" #include "Logger.h" +#ifdef JP512_TBD + #include "nvbuf_utils.h" +#endif uint8_t* DMAUtils::getCudaPtrForFD(int fd, EGLImageKHR eglImage, CUgraphicsResource *pResource, CUeglFrame eglFrame, EGLDisplay eglDisplay){ +#ifdef JP512_TBD eglImage = NvEGLImageFromFd(eglDisplay, fd); +#endif if (eglImage == NULL) { LOG_ERROR << "DID not find eglImage for File Descriptor"; @@ -51,10 +56,11 @@ void DMAUtils::freeCudaPtr(EGLImageKHR eglImage, CUgraphicsResource *pResource, LOG_ERROR << "cuGraphicsEGLUnRegisterResource failed: " << status; return; } - +#ifdef JP512_TBD auto res = NvDestroyEGLImage(eglDisplay, eglImage); if (res) { LOG_ERROR << "NvDestroyEGLImage Error<>" << res; } +#endif } \ No newline at end of file diff --git a/base/src/Logger.cpp b/base/src/Logger.cpp index ec121d7db..8eb1fc4d0 100755 --- a/base/src/Logger.cpp +++ b/base/src/Logger.cpp @@ -29,9 +29,8 @@ Logger::Logger(LoggerProps props) mProps = props; initBoostLogger(props); - logDisabled = !mProps.enableConsoleLog && !mProps.enableFileLog; - // start thread - if (!logDisabled) + // start thread if we has some form of logging + if (mProps.enableConsoleLog ||mProps.enableFileLog) { Logger& logger = *this; myThread = boost::thread(std::ref(logger)); @@ -80,33 +79,43 @@ void Logger::initBoostLogger(LoggerProps props) Logger::~Logger() { mRunning = false; - - if (!logDisabled) - { - mQue.setWake(); - myThread.~thread(); // not the ideal way - thread exits before processing the queue - myThread.join(); - } + std::cout << "Logger exiting..." <flush(); + } + if (mFileSink.get()) + { + mFileSink->flush(); + } + mQue.clear(); + } + catch(const std::exception& e) { - mConsoleSink->flush(); + std::cout << "Exception while logger exit: " << e.what() <flush(); + std::cout << "Uknown exception while logger exit"<_setListener(cb); } -void Logger::_setListener(void(*cb)(std::string&)) +void Logger::_setListener(void(*cb)(const std::string&)) { mListener = cb; } @@ -144,25 +153,51 @@ void Logger::operator()() bool Logger::run() { mRunning = true; - while (mRunning || mQue.size()) - { - std::string message = mQue.try_pop_external(); - if (!message.empty()) + try{ + while (mRunning || mQue.size()) { - process(message); + std::string message = mQue.try_pop_external(); + if (!message.empty()) + { + process(message); + } } } - + catch(const std::exception& e) + { + std::cout << "!!Logger thread exiting for : " << e.what() < #include diff --git a/base/src/NvV4L2CameraHelper.cpp b/base/src/NvV4L2CameraHelper.cpp index 3911d84d9..6c8320ff0 100644 --- a/base/src/NvV4L2CameraHelper.cpp +++ b/base/src/NvV4L2CameraHelper.cpp @@ -2,7 +2,9 @@ #include "DMAFDWrapper.h" #include "NvEglRenderer.h" #include "NvUtils.h" -#include "nvbuf_utils.h" +#ifdef JP512_TBD + #include "nvbuf_utils.h" +#endif #include "Logger.h" NvV4L2CameraHelper::NvV4L2CameraHelper(SendFrame sendFrame,std::function _makeFrame) diff --git a/base/src/QRReader.cpp b/base/src/QRReader.cpp index c341daa78..6d5fa7aba 100644 --- a/base/src/QRReader.cpp +++ b/base/src/QRReader.cpp @@ -3,16 +3,28 @@ #include "FrameMetadataFactory.h" #include "Frame.h" #include "Logger.h" -#include "ReadBarcode.h" -#include "TextUtfEncoding.h" +#include "RawImageMetadata.h" +#include +namespace fs = boost::filesystem; class QRReader::Detail { public: - Detail() : mWidth(0), mHeight(0) + Detail(QRReaderProps _props) : mWidth(0), mHeight(0) { - mHints.setEanAddOnSymbol(ZXing::EanAddOnSymbol::Read); + mReaderOptions.setEanAddOnSymbol(ZXing::EanAddOnSymbol::Read); + LOG_INFO << "Setting tryHarder as " << _props.tryHarder; + mReaderOptions.setTryHarder(_props.tryHarder); + mSaveQRImages = _props.saveQRImages; + mQRImagesFolderName = _props.qrImagesPath; + mFrameRotationCounter = _props.frameRotationCounter; + if (mFrameRotationCounter <= 0) + { + LOG_WARNING << "You are setting frameRotationCounter less than 1"; + mFrameRotationCounter = 1; + } + mFrameCounter = 0; } ~Detail() {} @@ -50,17 +62,18 @@ class QRReader::Detail int mWidth; int mHeight; - ZXing::DecodeHints mHints; + ZXing::ReaderOptions mReaderOptions; std::string mOutputPinId; ZXing::ImageFormat mImageFormat; - -private: - framemetadata_sp mMetadata; + bool mSaveQRImages; + fs::path mQRImagesFolderName; + int mFrameCounter; + int mFrameRotationCounter; }; QRReader::QRReader(QRReaderProps _props) : Module(TRANSFORM, "QRReader", _props) { - mDetail.reset(new Detail()); + mDetail.reset(new Detail(_props)); auto metadata = framemetadata_sp(new FrameMetadata(FrameMetadata::GENERAL)); mDetail->mOutputPinId = addOutputPin(metadata); } @@ -111,7 +124,15 @@ bool QRReader::init() { return false; } - + boost::system::error_code ec; + if (mDetail->mSaveQRImages && (!fs::create_directories(mDetail->mQRImagesFolderName, ec))) + { + if (ec) + { + LOG_ERROR << "Failed to create directory: " << mDetail->mQRImagesFolderName << ". Error: " << ec.message(); + mDetail->mQRImagesFolderName = ""; + } + } return true; } @@ -124,10 +145,40 @@ bool QRReader::process(frame_container &frames) { auto frame = frames.begin()->second; - const auto &result = ZXing::ReadBarcode({static_cast(frame->data()), mDetail->mWidth, mDetail->mHeight, mDetail->mImageFormat}, mDetail->mHints); - - auto text = ZXing::TextUtfEncoding::ToUtf8(result.text()); - + const auto &result = ZXing::ReadBarcode({static_cast(frame->data()), mDetail->mWidth, mDetail->mHeight, mDetail->mImageFormat}, mDetail->mReaderOptions); + + auto text = result.text(); + if (text.length()) + { + LOG_INFO << "ZXING decoded QR: " << text; + } + + if (mDetail->mSaveQRImages && (mDetail->mQRImagesFolderName != "")) + { + fs::path savePath = mDetail->mQRImagesFolderName / (std::to_string(mDetail->mFrameCounter) + ".raw"); + try + { + std::ofstream outFile(savePath.string(), std::ios::binary); + if (outFile) + { + outFile.write(static_cast(frame->data()), frame->size()); + outFile.close(); + } + else + { + LOG_ERROR << "Failed to save frame to " << savePath.string(); + } + } + catch (const std::exception &e) + { + LOG_ERROR << "Exception caught while saving frame to " << savePath.string() << ": " << e.what() << std::endl; + } + mDetail->mFrameCounter++; + if ((mDetail->mFrameCounter % mDetail->mFrameRotationCounter) == 0) + { + mDetail->mFrameCounter = 0; + } + } auto outFrame = makeFrame(text.length(), mDetail->mOutputPinId); memcpy(outFrame->data(), text.c_str(), outFrame->size()); frames.insert(make_pair(mDetail->mOutputPinId, outFrame)); diff --git a/base/src/V4L2CUYUV420Converter.cpp b/base/src/V4L2CUYUV420Converter.cpp index f6abb05e5..5b87bd9f6 100755 --- a/base/src/V4L2CUYUV420Converter.cpp +++ b/base/src/V4L2CUYUV420Converter.cpp @@ -4,7 +4,9 @@ #include "Frame.h" #include "AIPExceptions.h" -#include "nvbuf_utils.h" +#ifdef JP512_TBD + #include "nvbuf_utils.h" +#endif #include V4L2CUYUV420Converter::V4L2CUYUV420Converter(uint32_t srcWidth, uint32_t srcHeight, struct v4l2_format &format) : mFormat(format) @@ -53,7 +55,10 @@ void V4L2CUYUV420Converter::process(frame_sp& frame, AV4L2Buffer *buffer) for (i = 0; i < numPlanes; i++) { + +#ifdef JP512_TBD if (NvBufferMemSyncForDevice(buffer->planesInfo[i].fd, i, (void **)(&buffer->planesInfo[i].data)) < 0) +#endif { LOG_FATAL << "NvBufferMemSyncForDevice failed<>" << i; } @@ -106,6 +111,7 @@ V4L2CURGBToYUV420Converter::~V4L2CURGBToYUV420Converter() void V4L2CURGBToYUV420Converter::process(frame_sp& frame, AV4L2Buffer *buffer) { +#ifdef JP512_TBD eglImage = NvEGLImageFromFd(eglDisplay, buffer->planesInfo[0].fd); status = cuGraphicsEGLRegisterImage(&pResource, eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE); if (status != CUDA_SUCCESS) @@ -162,4 +168,5 @@ void V4L2CURGBToYUV420Converter::process(frame_sp& frame, AV4L2Buffer *buffer) buffer->v4l2_buf.m.planes[i].bytesused = mBytesUsedUV; } } +#endif } \ No newline at end of file diff --git a/base/test/QRReader_tests.cpp b/base/test/QRReader_tests.cpp index cd3b73234..ed8e7b580 100644 --- a/base/test/QRReader_tests.cpp +++ b/base/test/QRReader_tests.cpp @@ -9,6 +9,11 @@ #include "Logger.h" #include "AIPExceptions.h" #include "QRReader.h" +#include "PipeLine.h" +#include "RotateCV.h" +#include "VirtualCameraSink.h" + +#define VIDEO_DEV "/dev/video99" BOOST_AUTO_TEST_SUITE(QRReader_tests) @@ -39,6 +44,34 @@ BOOST_AUTO_TEST_CASE(rgb) BOOST_TEST(expectedOutput == actualOutput); } +BOOST_AUTO_TEST_CASE(test) +{ + FileReaderModuleProps fileReaderProps("./data/qrData/h.raw"); + fileReaderProps.readLoop = true; + auto fileReader = boost::shared_ptr(new FileReaderModule(fileReaderProps)); + auto metadata = framemetadata_sp(new RawImageMetadata(720, 1280, ImageMetadata::ImageType::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + QRReaderProps qrReaderProps(true,true,"./data",10); + auto QRData = boost::shared_ptr(new QRReader(qrReaderProps)); + fileReader->setNext(QRData); + + auto sink = boost::shared_ptr(new ExternalSinkModule()); + QRData->setNext(sink); + + BOOST_TEST(fileReader->init()); + BOOST_TEST(QRData->init()); + BOOST_TEST(sink->init()); + + fileReader->step(); + QRData->step(); + auto frames = sink->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + std::string expectedOutput = "0005100788"; + auto actualOutput = std::string(const_cast( static_cast(outputFrame->data()) ), outputFrame->size() ); +} + BOOST_AUTO_TEST_CASE(yuv420) { Logger::setLogLevel(boost::log::trivial::severity_level::trace); @@ -66,5 +99,31 @@ BOOST_AUTO_TEST_CASE(yuv420) BOOST_TEST(expectedOutput == actualOutput); } +BOOST_AUTO_TEST_CASE(readLoop) +{ + Logger::setLogLevel(boost::log::trivial::severity_level::trace); + FileReaderModuleProps fileReaderProps("./data/qrData/h.raw"); + fileReaderProps.readLoop = true; + auto fileReader = boost::shared_ptr(new FileReaderModule(fileReaderProps)); + auto metadata = framemetadata_sp(new RawImageMetadata(720, 1280, ImageMetadata::ImageType::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + auto m1 = boost::shared_ptr(new RotateCV(RotateCVProps(90))); + fileReader->setNext(m1); + + QRReaderProps qrReaderProps(true, true, "./data", 10); + auto QRData = boost::shared_ptr(new QRReader(qrReaderProps)); + m1->setNext(QRData); + + + auto p = boost::shared_ptr(new PipeLine("test")); + p->appendModule(fileReader); + p->init(); + p->run_all_threaded(); + boost::this_thread::sleep_for(boost::chrono::seconds(60)); + + p->wait_for_all(true); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/base/test/h264encoderv4l2helper_tests.cpp b/base/test/h264encoderv4l2helper_tests.cpp index e9b446ebb..c412d8ff9 100755 --- a/base/test/h264encoderv4l2helper_tests.cpp +++ b/base/test/h264encoderv4l2helper_tests.cpp @@ -7,8 +7,9 @@ #include "Logger.h" #include "test_utils.h" - -#include "nvbuf_utils.h" +#ifdef JP512_TBD + #include "nvbuf_utils.h" +#endif BOOST_AUTO_TEST_SUITE(h264encoderv4l2helper_tests) diff --git a/base/test/logger_tests.cpp b/base/test/logger_tests.cpp index 10c984619..22f11db87 100755 --- a/base/test/logger_tests.cpp +++ b/base/test/logger_tests.cpp @@ -10,18 +10,19 @@ BOOST_AUTO_TEST_SUITE(logger_tests) BOOST_AUTO_TEST_CASE(basic) { LoggerProps props; - props.enableConsoleLog = false; + props.enableConsoleLog = true; + props.enableFileLog = true; + Logger::initLogger(props); + Logger::setLogLevel(boost::log::trivial::severity_level::info); - for (auto i = 0; i < 100; i++) + for (auto i = 0; i < 1000; i++) { - LOG_ERROR << "HELLO WORLD " << i; + LOG_INFO << "HELLO WORLD " << i; } - - boost::this_thread::sleep_for(boost::chrono::seconds(1)); } -void listener(std::string& msg) +void listener(const std::string& msg) { std::cout << msg << "-------------------------" << std::endl; } @@ -29,23 +30,25 @@ void listener(std::string& msg) BOOST_AUTO_TEST_CASE(listener_test) { LoggerProps props; + props.enableConsoleLog = true; + props.enableFileLog = true; + Logger::initLogger(props); + Logger::setLogLevel(boost::log::trivial::severity_level::info); for (auto i = 0; i < 10; i++) { - LOG_ERROR << "HELLO WORLD " << i; + LOG_INFO << "HELLO WORLD " << i; } Logger::setListener(listener); for (auto i = 10; i < 20; i++) { - LOG_ERROR << "HELLO WORLD " << i; + LOG_INFO << "HELLO WORLD " << i; } Logger::setListener(nullptr); - - boost::this_thread::sleep_for(boost::chrono::seconds(1)); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/base/test/opencvresize_tests.cpp b/base/test/opencvresize_tests.cpp index 8e1d735ec..14fc92f9c 100755 --- a/base/test/opencvresize_tests.cpp +++ b/base/test/opencvresize_tests.cpp @@ -4,11 +4,13 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" -#include -#include -#include "opencv2/cudaimgproc.hpp" -#include "opencv2/core/cuda_stream_accessor.hpp" -#include +#ifdef JP512_TBD + #include + #include + #include "opencv2/cudaimgproc.hpp" + #include "opencv2/core/cuda_stream_accessor.hpp" + #include +#endif BOOST_AUTO_TEST_SUITE(opencvresize_tests, * boost::unit_test::disabled()) @@ -48,6 +50,7 @@ void testopencvcpuresize() void testopencvgpuresize() { +#ifdef JP512_TBD std::string imgPath = "4k.jpg"; auto src1 = cv::imread(imgPath, 0); @@ -69,6 +72,7 @@ void testopencvgpuresize() dst_gpu.download(dst); cv::imwrite("/home/al/Downloads/testopencvgpuresize.jpg", dst); +#endif } BOOST_AUTO_TEST_CASE(cpu) diff --git a/thirdparty/zxing-cpp b/thirdparty/zxing-cpp index a3e1d3115..ce8e3770e 160000 --- a/thirdparty/zxing-cpp +++ b/thirdparty/zxing-cpp @@ -1 +1 @@ -Subproject commit a3e1d3115147cc72970574f30f635a13bbe75782 +Subproject commit ce8e3770ea9aaf5809b11ebfc258d433df86eac2