diff --git a/cpp/DarknetDetection/CMakeLists.txt b/cpp/DarknetDetection/CMakeLists.txt index e14badab..4b6147bd 100644 --- a/cpp/DarknetDetection/CMakeLists.txt +++ b/cpp/DarknetDetection/CMakeLists.txt @@ -31,7 +31,7 @@ set(CMAKE_CXX_STANDARD 11) include(../ComponentSetup.cmake) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core opencv_highgui) +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core opencv_highgui) find_package(mpfComponentInterface REQUIRED) @@ -42,7 +42,7 @@ find_package(Qt4 REQUIRED) get_plugin_build_location(DarknetDetection pluginLocation) if (DEFINED ENV{MPF_DISABLE_CUDA_BUILD}) - set(DARKNET_BUILD_CUDA OFF) +set(DARKNET_BUILD_CUDA OFF) message( "The CUDA version of Darknet will not be built because the MPF_DISABLE_CUDA_BUILD environment variable was set.") else() @@ -86,4 +86,4 @@ endif() add_executable(sample_darknet_detector sample_darknet_detector.cpp) target_link_libraries(sample_darknet_detector mpfDarknetDetection) -add_subdirectory(test) \ No newline at end of file +add_subdirectory(test) diff --git a/cpp/DarknetDetection/Dockerfile b/cpp/DarknetDetection/Dockerfile index b6735c32..a20a1c8a 100644 --- a/cpp/DarknetDetection/Dockerfile +++ b/cpp/DarknetDetection/Dockerfile @@ -36,13 +36,9 @@ RUN mkdir /weights && curl --location https://pjreddie.com/media/files/yolov3.we # Build Component FROM ${BUILD_REGISTRY}openmpf_cpp_component_build:${BUILD_TAG} as build_component -RUN yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64 \ - && VERSION=9-0-9.0.176-1 \ - && yum install -y --nogpgcheck cuda-minimal-build-$VERSION cuda-cublas-dev-$VERSION cuda-curand-dev-$VERSION \ +RUN yum install --nogpgcheck -y cuda-curand-dev-10-2 \ && yum clean all \ - && rm -rf /var/cache/yum/* \ - && ln -s cuda-9.0 /usr/local/cuda \ - && echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/cuda.conf + && rm -rf /var/cache/yum/*; COPY . . @@ -53,18 +49,7 @@ RUN if [ "${RUN_TESTS,,}" == true ]; then cd $BUILD_DIR/test && ./DarknetDetecti #################################################### -FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} - -RUN yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64 \ - && yum install -y --nogpgcheck cuda-cudart-9-0-9.0.176-1 \ - && yum clean all \ - && rm -rf /var/cache/yum/* \ - && ln -s cuda-9.0 /usr/local/cuda \ - && echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/cuda.conf - -# Environment variables required by nvidia runtime. -ENV NVIDIA_VISIBLE_DEVICES all -ENV NVIDIA_DRIVER_CAPABILITIES compute,utility +FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} as darknet_component COPY --from=download_weights /weights $PLUGINS_DIR/DarknetDetection/models @@ -83,3 +68,21 @@ LABEL org.label-schema.license="Apache 2.0" \ org.label-schema.vcs-url="https://github.com/openmpf/openmpf-components" \ org.label-schema.vendor="MITRE" + +#################################################### +FROM darknet_component as sample_executable + +COPY --from=build_component $BUILD_DIR/sample_darknet_detector /opt/mpf/ + +COPY --from=build_component $BUILD_DIR/test/data /opt/mpf/test-data + +RUN ln -s /opt/mpf/plugins /opt/mpf/plugin + +ENV LD_LIBRARY_PATH $PLUGINS_DIR/DarknetDetection/lib + +ENTRYPOINT ["/opt/mpf/sample_darknet_detector"] + + +#################################################### +# Set final image when no --target specified. +FROM darknet_component diff --git a/cpp/DarknetDetection/darknet_lib/CMakeLists.txt b/cpp/DarknetDetection/darknet_lib/CMakeLists.txt index 3f445dc1..28ad6a71 100644 --- a/cpp/DarknetDetection/darknet_lib/CMakeLists.txt +++ b/cpp/DarknetDetection/darknet_lib/CMakeLists.txt @@ -78,8 +78,6 @@ set(DARKNET_LIB_SRC_FILES src/yolo_layer.c src/iseg_layer.c) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core opencv_highgui) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Darknet fails to compile when all optimizations are disabled, which is the default for debug builds. @@ -91,9 +89,8 @@ else() endif() add_library(darknet_lib ${DARKNET_LIB_SRC_FILES}) -target_compile_definitions(darknet_lib PUBLIC -DOPENCV) target_include_directories(darknet_lib PUBLIC include) -target_link_libraries(darknet_lib m pthread ${OpenCV_LIBS}) +target_link_libraries(darknet_lib m pthread) if (DARKNET_BUILD_CUDA) @@ -125,9 +122,9 @@ if (DARKNET_BUILD_CUDA) CUDA_ADD_LIBRARY(darknet_lib_cuda ${DARKNET_LIB_SRC_FILES} ${DARKNET_CUDA_SRC_FILES}) CUDA_ADD_CUBLAS_TO_TARGET(darknet_lib_cuda) - target_compile_definitions(darknet_lib_cuda PUBLIC -DOPENCV -DGPU) + target_compile_definitions(darknet_lib_cuda PUBLIC -DGPU) target_include_directories(darknet_lib_cuda PUBLIC include ${CUDA_INCLUDE_DIRS}) - target_link_libraries(darknet_lib_cuda m pthread ${OpenCV_LIBS} ${CUDA_curand_LIBRARY}) + target_link_libraries(darknet_lib_cuda m pthread ${CUDA_curand_LIBRARY}) endif() diff --git a/cpp/DarknetDetection/darknet_wrapper/CMakeLists.txt b/cpp/DarknetDetection/darknet_wrapper/CMakeLists.txt index dcc15888..c86260aa 100644 --- a/cpp/DarknetDetection/darknet_wrapper/CMakeLists.txt +++ b/cpp/DarknetDetection/darknet_wrapper/CMakeLists.txt @@ -30,7 +30,7 @@ project(darknet-wrapper) set(CMAKE_CXX_STANDARD 11) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core opencv_highgui) +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core opencv_highgui) find_package(mpfComponentInterface REQUIRED) find_package(mpfDetectionComponentApi REQUIRED) diff --git a/cpp/DarknetDetection/sample_darknet_detector.cpp b/cpp/DarknetDetection/sample_darknet_detector.cpp index a1f78343..655462f6 100644 --- a/cpp/DarknetDetection/sample_darknet_detector.cpp +++ b/cpp/DarknetDetection/sample_darknet_detector.cpp @@ -28,6 +28,8 @@ #include #include #include +#include + #include "DarknetDetection.h" @@ -37,9 +39,26 @@ using namespace MPF::COMPONENT; void print_tracks(const std::vector &tracks); int main(int argc, char* argv[]) { + if (argc == 2) { + std::string arg1 = argv[1]; + if (arg1 == "gpu-info") { + int cuda_device_count = cv::cuda::getCudaEnabledDeviceCount(); + std::cout << "Cuda device count: " << cuda_device_count << std::endl; + if (cuda_device_count > 0) { + for (int i = 0; i < cuda_device_count; i++) { + std::cout << "==== Device #" << i << " ====" << std::endl; + cv::cuda::printCudaDeviceInfo(i); + std::cout << "=================================" << std::endl; + } + } + return EXIT_SUCCESS; + } + } + if (argc < 3) { std::cout << "Usage: " << argv[0] << " [gpu_index]" << std::endl; std::cout << "Usage: " << argv[0] << " [gpu_index] [queue_capacity]" << std::endl; + std::cout << "Usage: " << argv[0] << " gpu-info" << std::endl; return 1; } diff --git a/cpp/DarknetDetection/test/test_darknet_detection.cpp b/cpp/DarknetDetection/test/test_darknet_detection.cpp index 6917dbc5..7488357c 100644 --- a/cpp/DarknetDetection/test/test_darknet_detection.cpp +++ b/cpp/DarknetDetection/test/test_darknet_detection.cpp @@ -26,8 +26,8 @@ #include -#include -#include + +#include #include #include diff --git a/cpp/DlibFaceDetection/CMakeLists.txt b/cpp/DlibFaceDetection/CMakeLists.txt index 39ec2e86..52b68401 100644 --- a/cpp/DlibFaceDetection/CMakeLists.txt +++ b/cpp/DlibFaceDetection/CMakeLists.txt @@ -31,13 +31,14 @@ project(dlib-face-detection) set(CMAKE_CXX_STANDARD 11) set(USE_AVX_INSTRUCTIONS ON) -set(DLIB_DIR /apps/source/dlib-sources/dlib-18.18/dlib) +set(DLIB_USE_CUDA OFF) +set(DLIB_DIR /apps/source/dlib-sources/dlib-19.20/dlib) include(${DLIB_DIR}/cmake) set_property(TARGET dlib PROPERTY POSITION_INDEPENDENT_CODE ON) include(../ComponentSetup.cmake) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_highgui) +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_highgui) find_package(mpfComponentInterface REQUIRED) find_package(mpfDetectionComponentApi REQUIRED) find_package(mpfComponentUtils REQUIRED) @@ -56,4 +57,4 @@ configure_mpf_component(DlibFaceDetection TARGETS mpfDlibFaceDetection) add_subdirectory(test) add_executable(sample_dlib_face_detector sample_dlib_face_detector.cpp) -target_link_libraries(sample_dlib_face_detector mpfDlibFaceDetection) \ No newline at end of file +target_link_libraries(sample_dlib_face_detector mpfDlibFaceDetection) diff --git a/cpp/DlibFaceDetection/DlibFaceDetection.cpp b/cpp/DlibFaceDetection/DlibFaceDetection.cpp index 4531d334..fb0d654f 100644 --- a/cpp/DlibFaceDetection/DlibFaceDetection.cpp +++ b/cpp/DlibFaceDetection/DlibFaceDetection.cpp @@ -667,7 +667,7 @@ vector DlibFaceDetection::GetDetectionsFromImageData(const MPF if (verbosity > 0) { // Draw a rectangle onto the input image for each detection if (imshow_on) { - namedWindow("original image", CV_WINDOW_AUTOSIZE); + namedWindow("original image", cv::WINDOW_AUTOSIZE); imshow("original image", image); waitKey(5); } @@ -679,7 +679,7 @@ vector DlibFaceDetection::GetDetectionsFromImageData(const MPF cv::rectangle(image, object, CV_RGB(0, 0, 0), 2); } if (imshow_on) { - namedWindow("new image", CV_WINDOW_AUTOSIZE); + namedWindow("new image", cv::WINDOW_AUTOSIZE); imshow("new image", image); //0 waits indefinitely for input, which could cause problems when run as a component waitKey(5); diff --git a/cpp/DlibFaceDetection/Dockerfile b/cpp/DlibFaceDetection/Dockerfile index 55d206be..a1030a57 100644 --- a/cpp/DlibFaceDetection/Dockerfile +++ b/cpp/DlibFaceDetection/Dockerfile @@ -35,7 +35,7 @@ RUN yum install --assumeyes bzip2 \ && rm --recursive /var/cache/yum/* RUN mkdir --parents /apps/source/dlib-sources; \ - curl --location 'http://dlib.net/files/dlib-18.18.tar.bz2' \ + curl --location 'http://dlib.net/files/dlib-19.20.tar.bz2' \ | tar --extract --bzip2 --directory /apps/source/dlib-sources diff --git a/cpp/KeywordTagging/CMakeLists.txt b/cpp/KeywordTagging/CMakeLists.txt index f55ebdaa..a5152bed 100644 --- a/cpp/KeywordTagging/CMakeLists.txt +++ b/cpp/KeywordTagging/CMakeLists.txt @@ -35,7 +35,8 @@ message("Package in ${PACKAGE_DIR}") find_package(mpfComponentInterface REQUIRED) find_package(mpfDetectionComponentApi REQUIRED) find_package(mpfComponentUtils REQUIRED) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 COMPONENTS opencv_core) +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core) + find_package(Qt4 REQUIRED) find_package(Boost 1.53.0 COMPONENTS regex locale filesystem) diff --git a/cpp/OalprLicensePlateTextDetection/CMakeLists.txt b/cpp/OalprLicensePlateTextDetection/CMakeLists.txt index 451e6fec..91579310 100644 --- a/cpp/OalprLicensePlateTextDetection/CMakeLists.txt +++ b/cpp/OalprLicensePlateTextDetection/CMakeLists.txt @@ -32,7 +32,7 @@ set(CMAKE_CXX_STANDARD 11) include(../ComponentSetup.cmake) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7) +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core) find_package(mpfComponentInterface REQUIRED) find_package(mpfDetectionComponentApi REQUIRED) find_package(mpfComponentUtils REQUIRED) diff --git a/cpp/OalprLicensePlateTextDetection/Dockerfile b/cpp/OalprLicensePlateTextDetection/Dockerfile index 84b12360..a1adfb59 100644 --- a/cpp/OalprLicensePlateTextDetection/Dockerfile +++ b/cpp/OalprLicensePlateTextDetection/Dockerfile @@ -54,12 +54,17 @@ RUN mkdir /tmp/tesseract; \ RUN mkdir /tmp/oalpr; \ cd /tmp/oalpr; \ - curl --location 'https://github.com/openalpr/openalpr/archive/6ead2fb8f72ac1929a2e04912c5795af0bf37761.tar.gz' \ + curl --location 'https://github.com/openalpr/openalpr/archive/386895386781f04ef056e93dd70d9ec36f72d350.tar.gz' \ | tar --extract --gzip; \ - cd openalpr-6ead2fb8f72ac1929a2e04912c5795af0bf37761/src; \ + cd openalpr-386895386781f04ef056e93dd70d9ec36f72d350/src; \ + # The following sed command will need to be modified when upgrading OALPR. + # Line 101 of the OALPR CMakeLists.txt contains: FIND_PACKAGE( OpenCV REQUIRED ) + # That pulls in a bunch of OpenCV libraries that OALPR doesn't need. + sed -i '101s/.*/ FIND_PACKAGE( OpenCV REQUIRED COMPONENTS opencv_core opencv_imgcodecs opencv_highgui opencv_objdetect opencv_video)/' \ + CMakeLists.txt; \ mkdir build; \ cd build; \ - cmake3 -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_DAEMON=OFF \ + cmake3 -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_DAEMON=OFF -DWITH_GPU_DETECTOR=false \ -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -DLeptonica_LIB=/usr/local/lib/libleptonica.so ..; \ make install -j "$(nproc)"; \ rm --recursive /tmp/oalpr diff --git a/cpp/OcvDnnDetection/CMakeLists.txt b/cpp/OcvDnnDetection/CMakeLists.txt index 54a71c2e..1958a385 100644 --- a/cpp/OcvDnnDetection/CMakeLists.txt +++ b/cpp/OcvDnnDetection/CMakeLists.txt @@ -32,7 +32,7 @@ set(CMAKE_CXX_STANDARD 11) include(../ComponentSetup.cmake) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_dnn) find_package(mpfComponentInterface REQUIRED) diff --git a/cpp/OcvDnnDetection/Dockerfile b/cpp/OcvDnnDetection/Dockerfile index 495c6763..6af511ab 100644 --- a/cpp/OcvDnnDetection/Dockerfile +++ b/cpp/OcvDnnDetection/Dockerfile @@ -36,8 +36,7 @@ ARG RUN_TESTS=false RUN if [ "${RUN_TESTS,,}" == true ]; then cd $BUILD_DIR/test && ./OcvDnnDetectionTest; fi - -FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} as install_component +FROM ${BUILD_REGISTRY}openmpf_cpp_executor:${BUILD_TAG} as ocv_dnn_component ENV COMPONENT_LOG_NAME ocv-dnn-detection.log @@ -53,3 +52,20 @@ LABEL org.label-schema.license="Apache 2.0" \ org.label-schema.url="https://openmpf.github.io" \ org.label-schema.vcs-url="https://github.com/openmpf/openmpf-components" \ org.label-schema.vendor="MITRE" + + +FROM ocv_dnn_component as sample_executable + +COPY --from=build_component $BUILD_DIR/sample_ocv_dnn_classifier /opt/mpf/ + +COPY --from=build_component $BUILD_DIR/test/data /opt/mpf/test-data + +RUN ln -s /opt/mpf/plugins /opt/mpf/plugin + +ENV LD_LIBRARY_PATH $PLUGINS_DIR/OcvDnnDetection/lib + +ENTRYPOINT ["/opt/mpf/sample_ocv_dnn_classifier"] + + +# Set final image when no --target specified. +FROM ocv_dnn_component diff --git a/cpp/OcvDnnDetection/OcvDnnDetection.cpp b/cpp/OcvDnnDetection/OcvDnnDetection.cpp index 31740f36..7d3cd19d 100644 --- a/cpp/OcvDnnDetection/OcvDnnDetection.cpp +++ b/cpp/OcvDnnDetection/OcvDnnDetection.cpp @@ -33,6 +33,8 @@ #include #include #include +#include + #include #include @@ -525,9 +527,48 @@ MPF_COMPONENT_CREATOR(OcvDnnDetection); MPF_COMPONENT_DELETER(); + +bool set_cuda_device_if_requested(const Properties &props, const log4cxx::LoggerPtr &logger) { + int cuda_device_id = DetectionComponentUtils::GetProperty(props, "CUDA_DEVICE_ID", -1); + if (cuda_device_id < 0) { + return false; + } + + int cuda_device_count = cv::cuda::getCudaEnabledDeviceCount(); + if (cuda_device_count > 0 && cuda_device_id < cuda_device_count) { + LOG4CXX_INFO(logger, "Running job on CUDA device: " << cuda_device_id); + cv::cuda::setDevice(cuda_device_id); + return true; + } + + std::string error_message; + if (cuda_device_count < 0) { + error_message = "Could not run job on GPU because the CUDA driver is not installed or is the wrong version."; + } + else if (cuda_device_count == 0) { + error_message = "Could not run job on GPU because OpenCV was compiled without CUDA support."; + } + else { + error_message = "Could not run job on GPU because CUDA_DEVICE_ID was set to " + std::to_string(cuda_device_id) + + " but only " + std::to_string(cuda_device_count) + + " CUDA devices were detected, making the maximum device id " + + std::to_string(cuda_device_count - 1) + "."; + } + + bool fallback_to_cpu = DetectionComponentUtils::GetProperty( + props, "FALLBACK_TO_CPU_WHEN_GPU_PROBLEM", false); + if (fallback_to_cpu) { + LOG4CXX_WARN(logger, error_message << " Running job on CPU instead."); + return false; + } + throw MPFDetectionException(MPFDetectionError::MPF_GPU_ERROR, error_message); +} + + + OcvDnnDetection::OcvDnnJobConfig::OcvDnnJobConfig(const Properties &props, const MPF::COMPONENT::ModelsIniParser &model_parser, - const log4cxx::LoggerPtr &logger) { + const log4cxx::LoggerPtr &logger) { using namespace DetectionComponentUtils; @@ -544,11 +585,14 @@ OcvDnnDetection::OcvDnnJobConfig::OcvDnnJobConfig(const Properties &props, class_names = readClassNames(settings.synset_file); + bool cuda_enabled = set_cuda_device_if_requested(props, logger); + // Import the model // For models that do not support or require a config file, ModelsIniParser // will assign the empty string as default to settings.model_config_file. // OpenCV DNN's readNet ignores the config file when it is passed an empty // string path, so we need not check whether the file exists. + // If using GPU version, cv::cuda::setDevice(cuda_device_id); MUST be called before cv::dnn::readNet. net = cv::dnn::readNet(settings.model_binary_file, settings.model_config_file); if (net.empty()) { throw MPFDetectionException( @@ -557,6 +601,11 @@ OcvDnnDetection::OcvDnnJobConfig::OcvDnnJobConfig(const Properties &props, + ") and model_binary (" + settings.model_binary_file + ")."); } + if (cuda_enabled) { + net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); + net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); + } + LOG4CXX_DEBUG(logger, "Created neural network"); resize_size = cv::Size(GetProperty(props, "RESIZE_WIDTH", 224), GetProperty(props, "RESIZE_HEIGHT", 224)); diff --git a/cpp/OcvDnnDetection/plugin-files/descriptor/descriptor.json b/cpp/OcvDnnDetection/plugin-files/descriptor/descriptor.json index c86fe944..1ccb8629 100644 --- a/cpp/OcvDnnDetection/plugin-files/descriptor/descriptor.json +++ b/cpp/OcvDnnDetection/plugin-files/descriptor/descriptor.json @@ -125,6 +125,18 @@ "description": "When FEED_FORWARD_TYPE is provided and not set to NONE, and FEED_FORWARD_WHITELIST_FILE is provided, this value determines what to do with feed-forward detections with class names not contained in the FEED_FORWARD_WHITELIST_FILE. Acceptable values are PASS_THROUGH and DROP.", "type": "STRING", "defaultValue": "PASS_THROUGH" + }, + { + "name": "CUDA_DEVICE_ID", + "description": "ID of CUDA device (typically 0) to be used. When less than 0 CUDA will be disabled.", + "type": "INT", + "propertiesKey": "detection.cuda.device.id" + }, + { + "name": "FALLBACK_TO_CPU_WHEN_GPU_PROBLEM", + "description": "Indicates whether or not the CPU only version should run if there is an issue with the GPU. Only used when CUDA_DEVICE_ID >= 0.", + "type": "BOOLEAN", + "propertiesKey": "detection.use.cpu.when.gpu.problem" } ] } diff --git a/cpp/OcvDnnDetection/sample_ocv_dnn_classifier.cpp b/cpp/OcvDnnDetection/sample_ocv_dnn_classifier.cpp index 8aa19e1b..1257de24 100644 --- a/cpp/OcvDnnDetection/sample_ocv_dnn_classifier.cpp +++ b/cpp/OcvDnnDetection/sample_ocv_dnn_classifier.cpp @@ -28,14 +28,33 @@ #include #include #include +#include + #include "OcvDnnDetection.h" using namespace MPF::COMPONENT; int main(int argc, char* argv[]) { + if (argc == 2) { + std::string arg1 = argv[1]; + if (arg1 == "gpu-info") { + int cuda_device_count = cv::cuda::getCudaEnabledDeviceCount(); + std::cout << "Cuda device count: " << cuda_device_count << std::endl; + if (cuda_device_count > 0) { + for (int i = 0; i < cuda_device_count; i++) { + std::cout << "==== Device #" << i << " ====" << std::endl; + cv::cuda::printCudaDeviceInfo(i); + std::cout << "=================================" << std::endl; + } + } + return EXIT_SUCCESS; + } + } + try { - if ((argc < 2) || (argc > 5)) { - std::cout << "Usage: " << argv[0] << " [num-classifications] [confidence-threshold] [ROTATE | CROP | FLIP]" << std::endl; + if ((argc < 2) || (argc > 6)) { + std::cout << "Usage: " << argv[0] << " [cuda_device_id or -1] [num-classifications] [confidence-threshold] [ROTATE | CROP | FLIP]" << std::endl; + std::cout << "Usage: " << argv[0] << " gpu-info" << std::endl; return EXIT_SUCCESS; } @@ -78,21 +97,27 @@ int main(int argc, char* argv[]) { << " URI: " << uri << std::endl; if (argc > 2) { + std::string cuda_device_id(argv[2]); + std::cout << " CUDA device ID: " << cuda_device_id << std::endl; + algorithm_properties["CUDA_DEVICE_ID"] = cuda_device_id; + } + + if (argc > 3) { // read the number of classifications returned - std::string num_classes(argv[2]); + std::string num_classes(argv[3]); algorithm_properties["NUMBER_OF_CLASSIFICATIONS"] = num_classes; std::cout << " Number of classifications: " << num_classes << std::endl; } - if (argc > 3) { + if (argc > 4) { // read the confidence threshold - std::string threshold(argv[3]); + std::string threshold(argv[4]); algorithm_properties["CONFIDENCE_THRESHOLD"] = threshold; std::cout << " Confidence threshold: " << threshold << std::endl; } - if (argc > 4) { - std::string transformation(argv[4]); + if (argc > 5) { + std::string transformation(argv[5]); if (transformation == "ROTATE") { // The input image will be rotated 270 degrees @@ -123,16 +148,16 @@ int main(int argc, char* argv[]) { std::vector detections = ocv_dnn_component.GetDetections(job); for (int i = 0; i < detections.size(); i++) { std::cout << "Detection " << i << ":" - << std::endl + << std::endl << " Primary classification: " << detections[i].detection_properties["CLASSIFICATION"] - << std::endl + << std::endl << " Primary confidence: " << detections[i].confidence - << std::endl + << std::endl << " Classification list: " << detections[i].detection_properties["CLASSIFICATION LIST"] - << std::endl + << std::endl << " Confidence list: " << detections[i].detection_properties["CLASSIFICATION CONFIDENCE LIST"] - << std::endl; - } + << std::endl; + } ocv_dnn_component.Close(); return EXIT_SUCCESS; } diff --git a/cpp/OcvFaceDetection/CMakeLists.txt b/cpp/OcvFaceDetection/CMakeLists.txt index 8ab3ecfa..6359d0ee 100644 --- a/cpp/OcvFaceDetection/CMakeLists.txt +++ b/cpp/OcvFaceDetection/CMakeLists.txt @@ -32,7 +32,7 @@ set(CMAKE_CXX_STANDARD 11) include(../ComponentSetup.cmake) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_highgui opencv_objdetect opencv_features2d opencv_ml opencv_flann opencv_video) find_package(mpfComponentInterface REQUIRED) diff --git a/cpp/OcvFaceDetection/OcvFaceDetection.cpp b/cpp/OcvFaceDetection/OcvFaceDetection.cpp index 138731c6..2ff4b22c 100644 --- a/cpp/OcvFaceDetection/OcvFaceDetection.cpp +++ b/cpp/OcvFaceDetection/OcvFaceDetection.cpp @@ -220,7 +220,7 @@ void OcvFaceDetection::Display(const string title, const Mat &img) { Rect OcvFaceDetection::GetMatch(const Mat &frame_rgb_display, const Mat &frame_gray, const Mat &templ) { //no clue what method is best - default of the opencv demo - int match_method = CV_TM_CCOEFF_NORMED; + int match_method = cv::TM_CCOEFF_NORMED; Mat img_display = frame_rgb_display.clone(); @@ -245,7 +245,7 @@ Rect OcvFaceDetection::GetMatch(const Mat &frame_rgb_display, const Mat &frame_g minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat()); /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better - if (match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED) { matchLoc = minLoc; } + if (match_method == cv::TM_SQDIFF || match_method == cv::TM_SQDIFF_NORMED) { matchLoc = minLoc; } else { matchLoc = maxLoc; } Rect match_rect(matchLoc.x, matchLoc.y, templ.cols, templ.rows); @@ -318,7 +318,7 @@ Mat OcvFaceDetection::GetMask(const Mat &frame, const Rect &face_rect, bool copy //would allow for using a rotated rect!! - possible future improvement rotated_rect.angle = 0.0f; //draw the ellipse on the black frame to create the mask - ellipse(image_mask, rotated_rect, Scalar(255), CV_FILLED); + ellipse(image_mask, rotated_rect, Scalar(255), cv::FILLED); if (copy_face_rect) { //Copy face to masked image @@ -583,10 +583,10 @@ vector OcvFaceDetection::GetDetectionsFromVideoCapture( //only keep if within the correct detected face rect if (correct_detected_rect_pair.first.contains(new_points[i])) { track->current_points.push_back(new_points[i]); - circle(frame_draw_pre_verified, new_points[i], 2, Scalar(255, 255, 255), CV_FILLED); + circle(frame_draw_pre_verified, new_points[i], 2, Scalar(255, 255, 255), cv::FILLED); } else { - circle(frame_draw_pre_verified, new_points[i], 2, Scalar(0, 0, 255), CV_FILLED); + circle(frame_draw_pre_verified, new_points[i], 2, Scalar(0, 0, 255), cv::FILLED); } } } @@ -602,7 +602,7 @@ vector OcvFaceDetection::GetDetectionsFromVideoCapture( for (unsigned i = 0; i < new_points.size(); i++) { track->current_points.push_back(new_points[i]); //draw the points as red - circle(frame_draw_pre_verified, new_points[i], 2, Scalar(0, 0, 255), CV_FILLED); + circle(frame_draw_pre_verified, new_points[i], 2, Scalar(0, 0, 255), cv::FILLED); } //draw a circle around the points @@ -890,7 +890,7 @@ vector OcvFaceDetection::GetDetectionsFromVideoCapture( if(imshow_on) { for(unsigned k=0; k OcvFaceDetection::GetDetectionsFromImageData( if (verbosity > 0) { // Draw a rectangle onto the input image for each detection if (imshow_on) { - cv::namedWindow("original image", CV_WINDOW_AUTOSIZE); + cv::namedWindow("original image", cv::WINDOW_AUTOSIZE); imshow("original image", image_data); cv::waitKey(5); } @@ -1087,7 +1087,7 @@ vector OcvFaceDetection::GetDetectionsFromImageData( rectangle(image_data, object, CV_RGB(0, 0, 0), 2); } if (imshow_on) { - cv::namedWindow("new image", CV_WINDOW_AUTOSIZE); + cv::namedWindow("new image", cv::WINDOW_AUTOSIZE); imshow("new image", image_data); //0 waits indefinitely for input, which could cause problems when run as a component //cv::waitKey(0); diff --git a/cpp/OcvFaceDetection/test/test_ocv_face_detection.cpp b/cpp/OcvFaceDetection/test/test_ocv_face_detection.cpp index 6ea6fd95..fa74683a 100644 --- a/cpp/OcvFaceDetection/test/test_ocv_face_detection.cpp +++ b/cpp/OcvFaceDetection/test/test_ocv_face_detection.cpp @@ -120,7 +120,7 @@ TEST(OcvFaceDetection, VerifyQuality) { test_image_path = current_working_dir + "/" + test_image_path; } - cv::Mat image = cv::imread(test_image_path, CV_LOAD_IMAGE_IGNORE_ORIENTATION + CV_LOAD_IMAGE_COLOR); + cv::Mat image = cv::imread(test_image_path, cv::IMREAD_IGNORE_ORIENTATION + cv::IMREAD_COLOR); ASSERT_TRUE(!image.empty()); cv::Mat image_gray = Utils::ConvertToGray(image); diff --git a/cpp/SceneChangeDetection/CMakeLists.txt b/cpp/SceneChangeDetection/CMakeLists.txt index a8f7b0db..f8ead744 100644 --- a/cpp/SceneChangeDetection/CMakeLists.txt +++ b/cpp/SceneChangeDetection/CMakeLists.txt @@ -32,7 +32,7 @@ set(CMAKE_CXX_STANDARD 11) include(../ComponentSetup.cmake) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_video opencv_highgui) find_package(mpfComponentInterface REQUIRED) diff --git a/cpp/SceneChangeDetection/SceneChangeDetection.cpp b/cpp/SceneChangeDetection/SceneChangeDetection.cpp index 097819c8..64cd8527 100644 --- a/cpp/SceneChangeDetection/SceneChangeDetection.cpp +++ b/cpp/SceneChangeDetection/SceneChangeDetection.cpp @@ -231,7 +231,7 @@ bool SceneChangeDetection::DetectChangeHistogram(const cv::Mat &frame, cv::Mat & hist, 2, histSize, ranges, true, // The histogram is uniform. false ); - double val = compareHist(hist, lastHist, CV_COMP_CORREL); + double val = compareHist(hist, lastHist, cv::HISTCMP_CORREL); hist.copyTo(lastHist); return val < hist_thresh; } diff --git a/cpp/TesseractOCRTextDetection/CMakeLists.txt b/cpp/TesseractOCRTextDetection/CMakeLists.txt index 625a7004..8137d4f2 100755 --- a/cpp/TesseractOCRTextDetection/CMakeLists.txt +++ b/cpp/TesseractOCRTextDetection/CMakeLists.txt @@ -33,7 +33,7 @@ set(PACKAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/plugin/${PROJECT_NAME}) message("Package in ${PACKAGE_DIR}") unset(OpenCV_CONFIG_PATH CACHE) -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_highgui opencv_objdetect opencv_features2d opencv_ml opencv_flann opencv_video) diff --git a/cpp/TesseractOCRTextDetection/Dockerfile b/cpp/TesseractOCRTextDetection/Dockerfile index 36533675..12d74a4f 100644 --- a/cpp/TesseractOCRTextDetection/Dockerfile +++ b/cpp/TesseractOCRTextDetection/Dockerfile @@ -32,7 +32,7 @@ FROM ${BUILD_REGISTRY}openmpf_cpp_component_build:${BUILD_TAG} as build_componen RUN yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm \ && yum --enablerepo=remi install -y ImageMagick ImageMagick-c++ \ ImageMagick-c++-devel ImageMagick-devel ImageMagick-libs \ - libgif libjpeg libpng libtiff zlib ghostscript \ + libjpeg libpng libtiff zlib ghostscript \ && yum clean all \ && rm -rf /var/cache/yum/* diff --git a/cpp/TesseractOCRTextDetection/TesseractOCRTextDetection.cpp b/cpp/TesseractOCRTextDetection/TesseractOCRTextDetection.cpp index 8b8fb14b..09448a40 100755 --- a/cpp/TesseractOCRTextDetection/TesseractOCRTextDetection.cpp +++ b/cpp/TesseractOCRTextDetection/TesseractOCRTextDetection.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include diff --git a/cpp/TrtisDetection/CMakeLists.txt b/cpp/TrtisDetection/CMakeLists.txt index 1d64f8c7..a4208457 100644 --- a/cpp/TrtisDetection/CMakeLists.txt +++ b/cpp/TrtisDetection/CMakeLists.txt @@ -39,7 +39,7 @@ include(../ComponentSetup.cmake) set(PACKAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/plugin/${PROJECT_NAME}) message("Package in ${PACKAGE_DIR}") -find_package(OpenCV 3.4.7 EXACT REQUIRED PATHS /opt/opencv-3.4.7 +find_package(OpenCV 4.5.0 EXACT REQUIRED PATHS /opt/opencv-4.5.0 COMPONENTS opencv_core) find_package(mpfComponentInterface REQUIRED) find_package(mpfDetectionComponentApi REQUIRED) diff --git a/cpp/TrtisDetection/Dockerfile b/cpp/TrtisDetection/Dockerfile index ab3cf3ba..daac095a 100644 --- a/cpp/TrtisDetection/Dockerfile +++ b/cpp/TrtisDetection/Dockerfile @@ -33,7 +33,7 @@ FROM ${MODELS_REGISTRY}openmpf_trtis_detection_models:5.1 as models FROM ${BUILD_REGISTRY}openmpf_cpp_component_build:${BUILD_TAG} as build_component -RUN yum -y install git openssl-devel curl-devel \ +RUN yum -y --nogpgcheck install git openssl-devel curl-devel cuda-cufft-10-2 cuda-npp-10-2 \ && yum clean all \ && rm -rf /var/cache/yum/* @@ -139,7 +139,7 @@ FROM nvcr.io/nvidia/tensorrtserver:19.04-py3 as openmpf_trtis_test_server COPY --from=build_component /usr/lib64/libssl3.so /usr/lib64/libnspr4.so /usr/lib64/libnss3.so \ /usr/lib64/libgtest*.so.0.0.0 /home/mpf/mpf-sdk-install/lib/ /usr/local/lib/ -COPY --from=build_component /opt/opencv-3.4.7/lib64 /apps/install/opencv3.4.7/lib64/ +COPY --from=build_component /opt/opencv-4.5.0/lib64 /apps/install/opencv4.5.0/lib64/ COPY --from=build_component /home/mpf/component_build /Testing_MPF_FILES/ COPY --from=build_component /home/mpf/component_src/test/run_docker_tests.sh /Testing_MPF_FILES/test @@ -147,7 +147,7 @@ ARG RUN_TESTS=false RUN if [ "${RUN_TESTS,,}" == true ]; \ then cd /Testing_MPF_FILES/test/ \ - && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Testing_MPF_FILES/plugin/TrtisDetection/lib/:/apps/install/opencv3.4.7/lib64/ \ + && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Testing_MPF_FILES/plugin/TrtisDetection/lib/:/apps/install/opencv4.5.0/lib64/ \ && ./run_docker_tests.sh \ ; fi diff --git a/cpp/TrtisDetection/TrtisDetection.h b/cpp/TrtisDetection/TrtisDetection.h index 0d88ac5b..9e397935 100644 --- a/cpp/TrtisDetection/TrtisDetection.h +++ b/cpp/TrtisDetection/TrtisDetection.h @@ -28,6 +28,7 @@ #ifndef OPENMPF_COMPONENTS_TRTISDETECTION_H #define OPENMPF_COMPONENTS_TRTISDETECTION_H +#include #include #include diff --git a/python/AzureFormDetection/Dockerfile b/python/AzureFormDetection/Dockerfile index 8db69077..8674267b 100644 --- a/python/AzureFormDetection/Dockerfile +++ b/python/AzureFormDetection/Dockerfile @@ -29,7 +29,7 @@ ARG BUILD_TAG=latest FROM ${BUILD_REGISTRY}openmpf_python_component_build:${BUILD_TAG} as build_component # Manually install packages before COPY so they don't need to be re-installed every time the source code changes. -RUN pip3 install --no-cache-dir 'opencv-python>=3.4.7' +RUN pip3 install --no-cache-dir 'opencv-python>=4.4.0' COPY . . diff --git a/python/AzureFormDetection/setup.py b/python/AzureFormDetection/setup.py index e64f640e..093276db 100644 --- a/python/AzureFormDetection/setup.py +++ b/python/AzureFormDetection/setup.py @@ -35,7 +35,7 @@ install_requires=( 'mpf_component_api>=5.1', 'mpf_component_util>=5.1', - 'opencv-python>=3.3', + 'opencv-python>=4.4.0', 'numpy>=1.11' ), entry_points={ diff --git a/python/AzureOcrTextDetection/Dockerfile b/python/AzureOcrTextDetection/Dockerfile index 92fc0ff5..87d51350 100644 --- a/python/AzureOcrTextDetection/Dockerfile +++ b/python/AzureOcrTextDetection/Dockerfile @@ -29,7 +29,7 @@ ARG BUILD_TAG=latest FROM ${BUILD_REGISTRY}openmpf_python_component_build:${BUILD_TAG} as build_component # Manually install packages before COPY so they don't need to be re-installed every time the source code changes. -RUN pip3 install --no-cache-dir 'opencv-python>=3.4.7' +RUN pip3 install --no-cache-dir 'opencv-python>=4.4.0' COPY . . diff --git a/python/AzureOcrTextDetection/setup.py b/python/AzureOcrTextDetection/setup.py index 4249b307..bea82f6f 100644 --- a/python/AzureOcrTextDetection/setup.py +++ b/python/AzureOcrTextDetection/setup.py @@ -34,7 +34,7 @@ install_requires=( 'mpf_component_api>=5.1', 'mpf_component_util>=5.1', - 'opencv-python>=3.3', + 'opencv-python>=4.4.0', 'numpy>=1.11' ), entry_points={ diff --git a/python/EastTextDetection/Dockerfile b/python/EastTextDetection/Dockerfile index 5b822404..75fd0492 100644 --- a/python/EastTextDetection/Dockerfile +++ b/python/EastTextDetection/Dockerfile @@ -29,7 +29,7 @@ ARG BUILD_TAG=latest FROM ${BUILD_REGISTRY}openmpf_python_component_build:${BUILD_TAG} as build_component # Manually install packages before COPY so they don't need to be re-installed every time the source code changes. -RUN pip3 install --no-cache-dir 'opencv-python>=3.4.7' +RUN pip3 install --no-cache-dir 'opencv-python>=4.4.0' COPY . . diff --git a/python/EastTextDetection/setup.py b/python/EastTextDetection/setup.py index 841afd80..b86def94 100644 --- a/python/EastTextDetection/setup.py +++ b/python/EastTextDetection/setup.py @@ -35,7 +35,7 @@ install_requires=( 'mpf_component_api>=5.1', 'mpf_component_util>=5.1', - 'opencv-python>=3.4.7', + 'opencv-python>=4.4.0', ), entry_points={ 'mpf.exported_component': 'component = east_component.east_component:EastComponent'