Skip to content

Commit ae6949e

Browse files
committed
Add checks for videowriter(which cannot work in opencv3.2)
1 parent 0f1ba81 commit ae6949e

14 files changed

+38
-32
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ PenaltyExcessCharacter: 1000000
9191
PenaltyReturnTypeOnItsOwnLine: 60
9292
PointerAlignment: Left
9393
RawStringFormats:
94-
- Delimiter: pb
94+
- Delimiters: [pb]
9595
Language: TextProto
9696
BasedOnStyle: google
9797
ReflowComments: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ __pycache__
2222
/lib
2323
/tensorlayer
2424
/vis
25+
build
2526
cmake_install.cmake
2627
CMakeCache.txt
2728
CMakeFiles

auto-format.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
find ./include -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
2-
find ./src -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
3-
find ./examples -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
1+
set -e
2+
3+
export CLANG_FORMAT=clang-format-9
4+
5+
find ./include -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec $CLANG_FORMAT -style=file -i {} \;
6+
find ./src -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec $CLANG_FORMAT -style=file -i {} \;
7+
find ./examples -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec $CLANG_FORMAT -style=file -i {} \;

examples/operator_api_video.example.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ int main(int argc, char** argv)
3333
capture.get(cv::CAP_PROP_FPS),
3434
cv::Size(FLAGS_input_width, FLAGS_input_height));
3535

36+
// Basic Information.
37+
poseplus_log() << "Input video name: " << FLAGS_input_video << std::endl;
38+
poseplus_log() << "Output video name: " << FLAGS_output_video << std::endl;
39+
poseplus_log() << "Input Frame: Size@" << cv::Size(capture.get(cv::CAP_PROP_FRAME_WIDTH), capture.get(cv::CAP_PROP_FRAME_HEIGHT)) << std::endl;
40+
poseplus_log() << "Output Frame: Size@" << cv::Size(writer.get(cv::CAP_PROP_FRAME_WIDTH), writer.get(cv::CAP_PROP_FRAME_HEIGHT)) << std::endl;
41+
poseplus_log() << "Count@" << capture.get(cv::CAP_PROP_FRAME_COUNT) << std::endl;
42+
3643
// * Create TensorRT engine.
3744
namespace pp = poseplus;
3845
if (FLAGS_logging)

examples/stream_api_video.example.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ int main(int argc, char** argv)
3636
// Basic information about videos.
3737
poseplus_log() << "Input video name: " << FLAGS_input_video << std::endl;
3838
poseplus_log() << "Output video name: " << FLAGS_output_video << std::endl;
39-
poseplus_log() << "Input Frame: Size@"
40-
<< cv::Size(capture.get(cv::CAP_PROP_FRAME_WIDTH), capture.get(cv::CAP_PROP_FRAME_HEIGHT))
41-
<< " Count@" << capture.get(cv::CAP_PROP_FRAME_COUNT) << std::endl;
39+
poseplus_log() << "Input Frame: Size@" << cv::Size(capture.get(cv::CAP_PROP_FRAME_WIDTH), capture.get(cv::CAP_PROP_FRAME_HEIGHT)) << std::endl;
40+
poseplus_log() << "Output Frame: Size@" << cv::Size(writer.get(cv::CAP_PROP_FRAME_WIDTH), writer.get(cv::CAP_PROP_FRAME_HEIGHT)) << std::endl;
41+
poseplus_log() << "Count@" << capture.get(cv::CAP_PROP_FRAME_COUNT) << std::endl;
4242

4343
// Checks.
4444
if (!capture.isOpened()) {

include/openpose_plus/operator/dnn/tensorrt.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/// \file tensorrt.hpp
44
/// \brief The DNN engine implementation of TensorRT.
5-
/// \author Jiawei Liu(github.com/ganler)
65

76
#include "../../utility/model.hpp"
87
#include <NvInferRuntime.h>

include/openpose_plus/operator/parser/paf.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/// \file paf.hpp
44
/// \brief Post-processing using Part Affinity Field (PAF).
5-
/// \author Jiawei Liu(github.com/ganler)
65

76
#include "../../utility/data.hpp"
87

include/openpose_plus/stream/stream.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/// \file stream.hpp
44
/// \brief Stream processing for pose estimation.
5-
/// \author Jiawei Liu(github.com/ganler)
65

76
#include <future>
87
#include <opencv2/opencv.hpp>
@@ -363,8 +362,8 @@ void basic_stream_manager::parse_from_internals(ParserList&& parser_list)
363362
futures[round_robin - parser_list.size()].wait();
364363

365364
futures.push_back(m_thread_pool.enqueue(
366-
[&parser_list, &internals, rb = round_robin]() -> pose_set {
367-
auto poses = parser_list.at(rb % parser_list.size()).get().process(std::move(internals[rb]));
365+
[&parser_list, &internals, round_robin]() -> pose_set {
366+
auto poses = parser_list.at(round_robin % parser_list.size()).get().process(std::move(internals[round_robin]));
368367
return poses;
369368
}));
370369
}
@@ -398,7 +397,7 @@ basic_stream_manager::write_to(NameGetter&& name_getter)
398397

399398
auto pose_set = m_pose_sets_queue.dump_all();
400399
for (auto&& poses : pose_set) {
401-
auto&& raw_image = m_input_queue_replica.dump().value();
400+
auto raw_image = m_input_queue_replica.dump().value();
402401
std::cout << poses.size() << std::endl;
403402
for (auto&& pose : poses)
404403
draw_human(raw_image, pose);

include/openpose_plus/utility/data.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/// \file data.hpp
44
/// \brief Data types in OpenPose-Plus.
5-
/// \author Jiawei Liu(github.com/ganler)
65

76
#include "human.hpp"
87

include/openpose_plus/utility/logging.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/// \file logging.hpp
44
/// \brief About logging configuration.
5-
/// \author Jiawei Liu(github.com/ganler)
65

76
#include <atomic>
87
#include <iostream>

include/openpose_plus/utility/model.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/// \file model.hpp
44
/// \brief The configurations of model files.
5-
/// \author Jiawei Liu(github.com/ganler)
65

76
#include <string>
87
#include <vector>

src/logging.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ void warning(const Args&... args)
2929
}
3030

3131
template <typename... Args>
32-
void error(const Args&... args)
32+
void error(const Args&... args) // ! Must log!
3333
{
34-
if (is_logging_enabled() == false)
35-
return;
3634
get_error_logger() << "[OpenPose-Plus::ERROR ] ";
3735
((get_error_logger() << args), ...);
3836
std::exit(-1);

src/stream.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void basic_stream_manager::resize_from_inputs(cv::Size size)
9797

9898
void basic_stream_manager::write_to(cv::VideoWriter& writer)
9999
{
100+
if (writer.get(cv::CAP_PROP_FRAME_WIDTH) <= 0 || writer.get(cv::CAP_PROP_FRAME_HEIGHT) <= 0)
101+
error("Got invalid video writer shape: ", cv::Size(writer.get(cv::CAP_PROP_FRAME_WIDTH), writer.get(cv::CAP_PROP_FRAME_HEIGHT)), '\n');
100102
try {
101103
while (true) {
102104
{

src/tensorrt.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,17 @@ namespace dnn {
177177

178178
nvinfer1::IOptimizationProfile* profile = builder->createOptimizationProfile();
179179
profile->setDimensions(
180-
network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMIN, nvinfer1::Dims4(1, 3, size.height, size.width));
180+
network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMIN, nvinfer1::Dims4(1, 3, size.height, size.width));
181181
profile->setDimensions(
182-
network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kOPT, nvinfer1::Dims4(max_batch_size, 3, size.height, size.width));
182+
network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kOPT, nvinfer1::Dims4(max_batch_size, 3, size.height, size.width));
183183
profile->setDimensions(
184-
network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMAX, nvinfer1::Dims4(max_batch_size, 3, size.height, size.width));
185-
// profile->setDimensions(
186-
// network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMIN, nvinfer1::Dims4(1, size.height, size.width, 3));
187-
// profile->setDimensions(
188-
// network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kOPT, nvinfer1::Dims4(1, size.height, size.width, 3));
189-
// profile->setDimensions(
190-
// network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMAX, nvinfer1::Dims4(max_batch_size, size.height, size.width, 3));
184+
network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMAX, nvinfer1::Dims4(max_batch_size, 3, size.height, size.width));
185+
// profile->setDimensions(
186+
// network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMIN, nvinfer1::Dims4(1, size.height, size.width, 3));
187+
// profile->setDimensions(
188+
// network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kOPT, nvinfer1::Dims4(1, size.height, size.width, 3));
189+
// profile->setDimensions(
190+
// network->getInput(0)->getName(), nvinfer1::OptProfileSelector::kMAX, nvinfer1::Dims4(max_batch_size, size.height, size.width, 3));
191191
config->addOptimizationProfile(profile);
192192

193193
auto engine = builder->buildEngineWithConfig(*network, *config);
@@ -229,7 +229,7 @@ namespace dnn {
229229
const std::string name(m_engine->getBindingName(i));
230230

231231
if (m_engine->bindingIsInput(i))
232-
size_vector = {3, m_inp_size.height, m_inp_size.width};
232+
size_vector = { 3, m_inp_size.height, m_inp_size.width };
233233
else {
234234
const int offset = dims.nbDims - 3;
235235
for (int j = 0; j < 3; ++j)
@@ -266,7 +266,7 @@ namespace dnn {
266266
const std::string name(m_engine->getBindingName(i));
267267

268268
if (m_engine->bindingIsInput(i))
269-
size_vector = {3, m_inp_size.height, m_inp_size.width};
269+
size_vector = { 3, m_inp_size.height, m_inp_size.width };
270270
else {
271271
const int offset = dims.nbDims - 3;
272272
for (int j = 0; j < 3; ++j)
@@ -310,8 +310,8 @@ namespace dnn {
310310
auto context = m_engine->createExecutionContext();
311311
std::vector<void*> buffer_ptrs_(m_cuda_buffers.size());
312312
std::transform(
313-
m_cuda_buffers.begin(), m_cuda_buffers.end(),
314-
buffer_ptrs_.begin(), [](const auto& b) { return b.data(); });
313+
m_cuda_buffers.begin(), m_cuda_buffers.end(),
314+
buffer_ptrs_.begin(), [](const auto& b) { return b.data(); });
315315
context->execute(batch_size, buffer_ptrs_.data());
316316
context->destroy();
317317
}

0 commit comments

Comments
 (0)