提交 510f34c4 编写于 作者: G gineshidalgo99

CocoJson not experimental & removed 3599-image limit.

上级 685b795e
......@@ -17,8 +17,8 @@ Each flag is divided into flag name, default value, and description.
- DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
- DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default example video.");
- DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20 images.");
- DEFINE_uint64(frame_first, 0, "Start on desired frame number.");
- DEFINE_uint64(frame_last, -1, "Finish on desired frame number. Select -1 to disable this option.");
- DEFINE_uint64(frame_first, 0, "Start on desired frame number. Indexes are 0-based, i.e. the first frame has index 0.");
- DEFINE_uint64(frame_last, -1, "Finish on desired frame number. Select -1 to disable. Indexes are 0-based, e.g. if set to 10, it will process 11 frames (0-10).");
- DEFINE_bool(frame_flip, false, "Flip/mirror each frame (e.g. for real time webcam demonstrations).");
- DEFINE_int32(frame_rotate, 0, "Rotate each frame, 4 possible values: 0, 90, 180, 270.");
- DEFINE_bool(frames_repeat, false, "Repeat frames when finished.");
......
......@@ -52,8 +52,9 @@ DEFINE_int32(camera, 0, "The camera index for cv
DEFINE_string(camera_resolution, "1280x720", "Size of the camera frames to ask for.");
DEFINE_string(video, "", "Use a video file instead of the camera. Use `examples/media/video.avi` for our default example video.");
DEFINE_string(image_dir, "", "Process a directory of images. Use `examples/media/` for our default example folder with 20 images.");
DEFINE_uint64(frame_first, 0, "Start on desired frame number.");
DEFINE_uint64(frame_last, -1, "Finish on desired frame number. Select -1 to disable this option.");
DEFINE_uint64(frame_first, 0, "Start on desired frame number. Indexes are 0-based, i.e. the first frame has index 0.");
DEFINE_uint64(frame_last, -1, "Finish on desired frame number. Select -1 to disable. Indexes are 0-based, e.g. if set to 10, it will process"
" 11 frames (0-10).");
DEFINE_bool(frame_flip, false, "Flip/mirror each frame (e.g. for real time webcam demonstrations).");
DEFINE_int32(frame_rotate, 0, "Rotate each frame, 4 possible values: 0, 90, 180, 270.");
DEFINE_bool(frames_repeat, false, "Repeat frames when finished.");
......
#ifndef OPENPOSE_EXPERIMENTAL_FILESTREAM_HEADERS_HPP
#define OPENPOSE_EXPERIMENTAL_FILESTREAM_HEADERS_HPP
// storage module
#include "wCocoJsonSaver.hpp"
#endif // OPENPOSE_EXPERIMENTAL_FILESTREAM_HEADERS_HPP
// THE CLASSES INSIDE THE experimental NAMESPACE ARE STILL BEING DEVELOPED, WE HIGHLY RECOMMEND NOT TO USE THEM
// The results are not the same as the one obtained with Matlab, so there is a bug somewhere in this class or in CocoJsonSaver.
#ifndef OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
#define OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
#include <memory> // std::shared_ptr
#include <openpose/filestream/cocoJsonSaver.hpp>
#include <openpose/thread/workerConsumer.hpp>
namespace op
{
namespace experimental
{
template<typename TDatums>
class WCocoJsonSaver : public WorkerConsumer<TDatums>
{
public:
explicit WCocoJsonSaver(const std::shared_ptr<CocoJsonSaver>& cocoJsonSaver);
void initializationOnThread();
void workConsumer(const TDatums& tDatums);
private:
std::shared_ptr<CocoJsonSaver> spCocoJsonSaver;
DELETE_COPY(WCocoJsonSaver);
};
}
}
// Implementation
#include <openpose/utilities/errorAndLog.hpp>
#include <openpose/utilities/macros.hpp>
#include <openpose/utilities/pointerContainer.hpp>
#include <openpose/utilities/profiler.hpp>
namespace op
{
namespace experimental
{
template<typename TDatums>
WCocoJsonSaver<TDatums>::WCocoJsonSaver(const std::shared_ptr<CocoJsonSaver>& cocoJsonSaver) :
spCocoJsonSaver{cocoJsonSaver}
{
}
template<typename TDatums>
void WCocoJsonSaver<TDatums>::initializationOnThread()
{
}
template<typename TDatums>
void WCocoJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
{
try
{
if (checkNoNullNorEmpty(tDatums))
{
// Check tDatums->size() == 1
if (tDatums->size() > 1)
error("Function only ready for tDatums->size() == 1", __LINE__, __FUNCTION__, __FILE__);
// Debugging log
dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Profiling speed
const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
// T* to T
const auto& tDatum = (*tDatums)[0];
// Record json in COCO format
const std::string stringToRemove = "COCO_val2014_";
const auto stringToRemoveEnd = tDatum.name.find(stringToRemove) + stringToRemove.size();
const auto imageId = std::stoull(tDatum.name.substr(stringToRemoveEnd, tDatum.name.size() - stringToRemoveEnd));
// if (imageId <= 20671) // 1471 images ~ 1.5 min at 15fps
if (imageId <= 50006) // 3559 images ~ 4 min at 15fps // move this to producer as --frame_last 50006
{
// Record json in COCO format if file within desired range of images
spCocoJsonSaver->record(tDatum.poseKeypoints, imageId);
// Profiling speed
Profiler::timerEnd(profilerKey);
Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X);
}
else
{
// Debugging log
log("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Stop worker
this->stop();
}
// Debugging log
dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
}
}
catch (const std::exception& e)
{
this->stop();
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
COMPILE_TEMPLATE_DATUM(WCocoJsonSaver);
}
}
#endif // OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
#ifndef OPENPOSE_EXPERIMENTAL_HEADERS_HPP
#define OPENPOSE_EXPERIMENTAL_HEADERS_HPP
// filestream module
#include "filestream/headers.hpp"
// hands module
#include "hand/headers.hpp"
......
......@@ -12,6 +12,7 @@
#include "keypointJsonSaver.hpp"
#include "keypointSaver.hpp"
#include "videoSaver.hpp"
#include "wCocoJsonSaver.hpp"
#include "wFaceJsonSaver.hpp"
#include "wFaceSaver.hpp"
#include "wHandJsonSaver.hpp"
......
#ifndef OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
#define OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
#include <memory> // std::shared_ptr
#include <openpose/filestream/cocoJsonSaver.hpp>
#include <openpose/thread/workerConsumer.hpp>
namespace op
{
template<typename TDatums>
class WCocoJsonSaver : public WorkerConsumer<TDatums>
{
public:
explicit WCocoJsonSaver(const std::shared_ptr<CocoJsonSaver>& cocoJsonSaver);
void initializationOnThread();
void workConsumer(const TDatums& tDatums);
private:
std::shared_ptr<CocoJsonSaver> spCocoJsonSaver;
DELETE_COPY(WCocoJsonSaver);
};
}
// Implementation
#include <openpose/utilities/errorAndLog.hpp>
#include <openpose/utilities/macros.hpp>
#include <openpose/utilities/pointerContainer.hpp>
#include <openpose/utilities/profiler.hpp>
namespace op
{
template<typename TDatums>
WCocoJsonSaver<TDatums>::WCocoJsonSaver(const std::shared_ptr<CocoJsonSaver>& cocoJsonSaver) :
spCocoJsonSaver{cocoJsonSaver}
{
}
template<typename TDatums>
void WCocoJsonSaver<TDatums>::initializationOnThread()
{
}
template<typename TDatums>
void WCocoJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
{
try
{
if (checkNoNullNorEmpty(tDatums))
{
// Check tDatums->size() == 1
if (tDatums->size() > 1)
error("Function only ready for tDatums->size() == 1", __LINE__, __FUNCTION__, __FILE__);
// Debugging log
dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
// Profiling speed
const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
// T* to T
const auto& tDatum = tDatums->at(0);
// Record json in COCO format
const std::string stringToRemove = "COCO_val2014_";
const auto stringToRemoveEnd = tDatum.name.find(stringToRemove) + stringToRemove.size();
const auto imageId = std::stoull(tDatum.name.substr(stringToRemoveEnd, tDatum.name.size() - stringToRemoveEnd));
// Record json in COCO format if file within desired range of images
spCocoJsonSaver->record(tDatum.poseKeypoints, imageId);
// Profiling speed
Profiler::timerEnd(profilerKey);
Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X);
// Debugging log
dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
}
}
catch (const std::exception& e)
{
this->stop();
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
COMPILE_TEMPLATE_DATUM(WCocoJsonSaver);
}
#endif // OPENPOSE_FILESTREAM_W_COCO_JSON_SAVER_HPP
......@@ -710,7 +710,7 @@ namespace op
{
const auto humanFormat = true; // If true, bigger size (and potentially slower to process), but easier for a human to read it
const auto cocoJsonSaver = std::make_shared<CocoJsonSaver>(wrapperStructOutput.writeCocoJson, humanFormat);
mOutputWs.emplace_back(std::make_shared<experimental::WCocoJsonSaver<TDatumsPtr>>(cocoJsonSaver));
mOutputWs.emplace_back(std::make_shared<WCocoJsonSaver<TDatumsPtr>>(cocoJsonSaver));
}
// Write frames as desired image format on hard disk
if (!writeImagesCleaned.empty())
......
#include <openpose/experimental/filestream/headers.hpp>
namespace op
{
DEFINE_TEMPLATE_DATUM(experimental::WCocoJsonSaver);
}
......@@ -2,6 +2,7 @@
namespace op
{
DEFINE_TEMPLATE_DATUM(WCocoJsonSaver);
DEFINE_TEMPLATE_DATUM(WFaceJsonSaver);
DEFINE_TEMPLATE_DATUM(WFaceSaver);
DEFINE_TEMPLATE_DATUM(WHandJsonSaver);
......
......@@ -57,7 +57,7 @@ namespace op
if (!directoryPath.empty())
{
std::replace(directoryPath.begin(), directoryPath.end(), '\\', '/'); // replace all '\\' to '/';
if (*(directoryPath.cend() - 1) != '/')
if (directoryPath.back() != '/')
directoryPath = directoryPath + "/";
}
return directoryPath;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册