Skip to content

Commit b878cbf

Browse files
More security checks on cvMatToOutput & updated hand test
1 parent b4a7a6c commit b878cbf

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# Script for internal use. We might completely change it continuously and we will not answer questions about it.
1+
# Usage example:
2+
# clear && clear && make all -j`nproc` && bash ./examples/tests/hand_accuracy_test.sh
3+
4+
# Disclaimer:
5+
# Script for internal use. We might make continuous changess on it and we will not answer questions about it.
26

37
# Clear terminal screen
48
clear && clear
59

610

711

8-
HAND_TESTING_FOLDER="/media/posefs3b/Users/gines/openpose_training/dataset/hand_testing/5_keypointJson/"
12+
HAND_TESTING_FOLDER="/media/posefs3b/Users/gines/openpose_train/dataset/hand_testing/"
913
IMAGES_FOLDER=${HAND_TESTING_FOLDER}"0_images/"
1014
IMAGES_BB_FOLDER=${HAND_TESTING_FOLDER}"3_images_bounding_box"
11-
IMAGES_BB_FOLDER=${HAND_TESTING_FOLDER}"4_hand_detections"
15+
HAND_GROUND_TRUTH_FOLDER=${HAND_TESTING_FOLDER}"4_hand_detections"
1216
KEYPOINT_JSON_FOLDER=${HAND_TESTING_FOLDER}"5_keypointJson/"
1317

1418
SCALES=6
@@ -24,9 +28,9 @@ rm -rf $HAND_RESULTS_FOLDER_BB
2428
./build/examples/tests/handFromJsonTest.bin \
2529
--hand_scale_number ${SCALES} --hand_scale_range 0.4 \
2630
--image_dir ${IMAGES_BB_FOLDER} \
27-
--hand_ground_truth ${IMAGES_BB_FOLDER} \
28-
--write_keypoint_json $HAND_RESULTS_FOLDER_BB \
29-
--no_display
31+
--hand_ground_truth ${HAND_GROUND_TRUTH_FOLDER}
32+
# --write_keypoint_json $HAND_RESULTS_FOLDER_BB \
33+
# --no_display
3034

3135

3236

@@ -36,8 +40,7 @@ echo "Output on ${HAND_RESULTS_FOLDER_NO_BB}"
3640
rm -rf $HAND_RESULTS_FOLDER_NO_BB
3741
# 1 scale
3842
./build/examples/openpose/openpose.bin \
39-
--hand logging_level 3 \
40-
--hand_scale_number ${SCALES} --hand_scale_range 0.4 \
41-
--image_dir ${IMAGES_FOLDER} \
42-
--write_keypoint_json $HAND_RESULTS_FOLDER_NO_BB \
43-
--no_display
43+
--hand --hand_scale_number ${SCALES} --hand_scale_range 0.4 \
44+
--image_dir ${IMAGES_FOLDER} #\
45+
# --write_keypoint_json $HAND_RESULTS_FOLDER_NO_BB \
46+
# --no_display

examples/tests/wrapperHandFromJsonTest.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace op
4141
// Workers
4242
TWorker wDatumProducer;
4343
TWorker spWIdGenerator;
44+
TWorker spWScaleAndSizeExtractor;
4445
TWorker spWCvMatToOpInput;
4546
TWorker spWCvMatToOpOutput;
4647
std::vector<std::vector<TWorker>> spWPoses;
@@ -172,6 +173,13 @@ namespace op
172173
const auto datumProducer = std::make_shared<DatumProducer<TDatums>>(producerSharedPtr);
173174
wDatumProducer = std::make_shared<WDatumProducer<TDatumsPtr, TDatums>>(datumProducer);
174175

176+
// Get input scales and sizes
177+
const auto scaleAndSizeExtractor = std::make_shared<ScaleAndSizeExtractor>(
178+
wrapperStructPose.netInputSize, finalOutputSize, wrapperStructPose.scalesNumber,
179+
wrapperStructPose.scaleGap
180+
);
181+
spWScaleAndSizeExtractor = std::make_shared<WScaleAndSizeExtractor<TDatumsPtr>>(scaleAndSizeExtractor);
182+
175183
// Input cvMat to OpenPose format
176184
const auto cvMatToOpInput = std::make_shared<CvMatToOpInput>();
177185
spWCvMatToOpInput = std::make_shared<WCvMatToOpInput<TDatumsPtr>>(cvMatToOpInput);
@@ -281,6 +289,7 @@ namespace op
281289
mThreadManager.reset();
282290
// Reset
283291
wDatumProducer = nullptr;
292+
spWScaleAndSizeExtractor = nullptr;
284293
spWCvMatToOpInput = nullptr;
285294
spWCvMatToOpOutput = nullptr;
286295
spWPoses.clear();
@@ -301,7 +310,8 @@ namespace op
301310
{
302311
// Security checks
303312
if (spWCvMatToOpInput == nullptr)
304-
error("Configure the WrapperHandFromJsonTest class before calling `start()`.", __LINE__, __FUNCTION__, __FILE__);
313+
error("Configure the WrapperHandFromJsonTest class before calling `start()`.",
314+
__LINE__, __FUNCTION__, __FILE__);
305315
if (wDatumProducer == nullptr)
306316
{
307317
const auto message = "You need to use the OpenPose default producer.";
@@ -323,9 +333,11 @@ namespace op
323333
// OpenPose producer
324334
// Thread 0 or 1, queues 0 -> 1
325335
if (spWCvMatToOpOutput == nullptr)
326-
mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWCvMatToOpInput}, queueIn++, queueOut++);
336+
mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWScaleAndSizeExtractor,
337+
spWCvMatToOpInput}, queueIn++, queueOut++);
327338
else
328-
mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWCvMatToOpInput, spWCvMatToOpOutput}, queueIn++, queueOut++);
339+
mThreadManager.add(threadId++, {wDatumProducer, spWIdGenerator, spWScaleAndSizeExtractor,
340+
spWCvMatToOpInput, spWCvMatToOpOutput}, queueIn++, queueOut++);
329341
// Pose estimation & rendering
330342
// Thread 1 or 2...X, queues 1 -> 2, X = 2 + #GPUs
331343
if (!spWPoses.empty())

src/openpose/core/cvMatToOpOutput.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace op
1212
error("Wrong input element (empty cvInputData).", __LINE__, __FUNCTION__, __FILE__);
1313
if (cvInputData.channels() != 3)
1414
error("Input images must be 3-channel BGR.", __LINE__, __FUNCTION__, __FILE__);
15+
if (cvInputData.cols <= 0 || cvInputData.rows <= 0)
16+
error("Input images has 0 area.", __LINE__, __FUNCTION__, __FILE__);
17+
if (outputResolution.x <= 0 || outputResolution.y <= 0)
18+
error("Output resolution has 0 area.", __LINE__, __FUNCTION__, __FILE__);
1519
// outputData - Reescale keeping aspect ratio and transform to float the output image
1620
const cv::Mat frameWithOutputSize = resizeFixedAspectRatio(cvInputData, scaleInputToOutput,
1721
outputResolution);

0 commit comments

Comments
 (0)