From b878cbf4f0db5c55cbb7ef15045ad102c10fbde2 Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Wed, 3 Jan 2018 11:26:46 -0500 Subject: [PATCH] More security checks on cvMatToOutput & updated hand test --- examples/tests/hand_accuracy_test.sh | 25 ++++++++++++---------- examples/tests/wrapperHandFromJsonTest.hpp | 18 +++++++++++++--- src/openpose/core/cvMatToOpOutput.cpp | 4 ++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/examples/tests/hand_accuracy_test.sh b/examples/tests/hand_accuracy_test.sh index a1c1a040..872ab1aa 100755 --- a/examples/tests/hand_accuracy_test.sh +++ b/examples/tests/hand_accuracy_test.sh @@ -1,14 +1,18 @@ -# Script for internal use. We might completely change it continuously and we will not answer questions about it. +# Usage example: +# clear && clear && make all -j`nproc` && bash ./examples/tests/hand_accuracy_test.sh + +# Disclaimer: +# Script for internal use. We might make continuous changess on it and we will not answer questions about it. # Clear terminal screen clear && clear -HAND_TESTING_FOLDER="/media/posefs3b/Users/gines/openpose_training/dataset/hand_testing/5_keypointJson/" +HAND_TESTING_FOLDER="/media/posefs3b/Users/gines/openpose_train/dataset/hand_testing/" IMAGES_FOLDER=${HAND_TESTING_FOLDER}"0_images/" IMAGES_BB_FOLDER=${HAND_TESTING_FOLDER}"3_images_bounding_box" -IMAGES_BB_FOLDER=${HAND_TESTING_FOLDER}"4_hand_detections" +HAND_GROUND_TRUTH_FOLDER=${HAND_TESTING_FOLDER}"4_hand_detections" KEYPOINT_JSON_FOLDER=${HAND_TESTING_FOLDER}"5_keypointJson/" SCALES=6 @@ -24,9 +28,9 @@ rm -rf $HAND_RESULTS_FOLDER_BB ./build/examples/tests/handFromJsonTest.bin \ --hand_scale_number ${SCALES} --hand_scale_range 0.4 \ --image_dir ${IMAGES_BB_FOLDER} \ - --hand_ground_truth ${IMAGES_BB_FOLDER} \ - --write_keypoint_json $HAND_RESULTS_FOLDER_BB \ - --no_display + --hand_ground_truth ${HAND_GROUND_TRUTH_FOLDER} + # --write_keypoint_json $HAND_RESULTS_FOLDER_BB \ + # --no_display @@ -36,8 +40,7 @@ echo "Output on ${HAND_RESULTS_FOLDER_NO_BB}" rm -rf $HAND_RESULTS_FOLDER_NO_BB # 1 scale ./build/examples/openpose/openpose.bin \ - --hand logging_level 3 \ - --hand_scale_number ${SCALES} --hand_scale_range 0.4 \ - --image_dir ${IMAGES_FOLDER} \ - --write_keypoint_json $HAND_RESULTS_FOLDER_NO_BB \ - --no_display + --hand --hand_scale_number ${SCALES} --hand_scale_range 0.4 \ + --image_dir ${IMAGES_FOLDER} #\ + # --write_keypoint_json $HAND_RESULTS_FOLDER_NO_BB \ + # --no_display diff --git a/examples/tests/wrapperHandFromJsonTest.hpp b/examples/tests/wrapperHandFromJsonTest.hpp index 73f5cd48..06d29336 100644 --- a/examples/tests/wrapperHandFromJsonTest.hpp +++ b/examples/tests/wrapperHandFromJsonTest.hpp @@ -41,6 +41,7 @@ namespace op // Workers TWorker wDatumProducer; TWorker spWIdGenerator; + TWorker spWScaleAndSizeExtractor; TWorker spWCvMatToOpInput; TWorker spWCvMatToOpOutput; std::vector> spWPoses; @@ -172,6 +173,13 @@ namespace op const auto datumProducer = std::make_shared>(producerSharedPtr); wDatumProducer = std::make_shared>(datumProducer); + // Get input scales and sizes + const auto scaleAndSizeExtractor = std::make_shared( + wrapperStructPose.netInputSize, finalOutputSize, wrapperStructPose.scalesNumber, + wrapperStructPose.scaleGap + ); + spWScaleAndSizeExtractor = std::make_shared>(scaleAndSizeExtractor); + // Input cvMat to OpenPose format const auto cvMatToOpInput = std::make_shared(); spWCvMatToOpInput = std::make_shared>(cvMatToOpInput); @@ -281,6 +289,7 @@ namespace op mThreadManager.reset(); // Reset wDatumProducer = nullptr; + spWScaleAndSizeExtractor = nullptr; spWCvMatToOpInput = nullptr; spWCvMatToOpOutput = nullptr; spWPoses.clear(); @@ -301,7 +310,8 @@ namespace op { // Security checks if (spWCvMatToOpInput == nullptr) - error("Configure the WrapperHandFromJsonTest class before calling `start()`.", __LINE__, __FUNCTION__, __FILE__); + error("Configure the WrapperHandFromJsonTest class before calling `start()`.", + __LINE__, __FUNCTION__, __FILE__); if (wDatumProducer == nullptr) { const auto message = "You need to use the OpenPose default producer."; @@ -323,9 +333,11 @@ namespace op // OpenPose producer // Thread 0 or 1, queues 0 -> 1 if (spWCvMatToOpOutput == nullptr) - mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWCvMatToOpInput}, queueIn++, queueOut++); + mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWScaleAndSizeExtractor, + spWCvMatToOpInput}, queueIn++, queueOut++); else - mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWCvMatToOpInput, spWCvMatToOpOutput}, queueIn++, queueOut++); + mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWScaleAndSizeExtractor, + spWCvMatToOpInput, spWCvMatToOpOutput}, queueIn++, queueOut++); // Pose estimation & rendering // Thread 1 or 2...X, queues 1 -> 2, X = 2 + #GPUs if (!spWPoses.empty()) diff --git a/src/openpose/core/cvMatToOpOutput.cpp b/src/openpose/core/cvMatToOpOutput.cpp index 872c99e5..41cb376e 100644 --- a/src/openpose/core/cvMatToOpOutput.cpp +++ b/src/openpose/core/cvMatToOpOutput.cpp @@ -12,6 +12,10 @@ namespace op error("Wrong input element (empty cvInputData).", __LINE__, __FUNCTION__, __FILE__); if (cvInputData.channels() != 3) error("Input images must be 3-channel BGR.", __LINE__, __FUNCTION__, __FILE__); + if (cvInputData.cols <= 0 || cvInputData.rows <= 0) + error("Input images has 0 area.", __LINE__, __FUNCTION__, __FILE__); + if (outputResolution.x <= 0 || outputResolution.y <= 0) + error("Output resolution has 0 area.", __LINE__, __FUNCTION__, __FILE__); // outputData - Reescale keeping aspect ratio and transform to float the output image const cv::Mat frameWithOutputSize = resizeFixedAspectRatio(cvInputData, scaleInputToOutput, outputResolution);