Skip to content

Commit

Permalink
Optimized augmentation for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
gineshidalgo99 committed Feb 28, 2018
1 parent 6e7d170 commit 6d7e794
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 109 deletions.
4 changes: 2 additions & 2 deletions include/caffe/openpose/dataAugmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace caffe {
// Cropping
cv::Point2i estimateCrop(const MetaData& metaData, const OPTransformationParameter& param_);
void applyCrop(cv::Mat& imageAugmented, const cv::Point2i& cropCenter, const cv::Mat& image,
const unsigned char defaultBorderValue, const OPTransformationParameter& param_);
const unsigned char defaultBorderValue, const cv::Size& cropSize);
void applyCrop(MetaData& metaData, const cv::Point2i& cropCenter,
const OPTransformationParameter& param_, const PoseModel poseModel);
const cv::Size& cropSize, const PoseModel poseModel);
// Flipping
bool estimateFlip(const MetaData& metaData,
const OPTransformationParameter& param_);
Expand Down
2 changes: 1 addition & 1 deletion include/caffe/openpose/oPDataTransformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class OPDataTransformer {
void generateDataAndLabel(Dtype* transformedData, Dtype* transformedLabel, const Datum& datum,
const Datum* datumNegative);
void generateDepthLabelMap(Dtype* transformedLabel, const cv::Mat& depth) const;
void generateLabelMap(Dtype* transformedLabel, const cv::Mat& image, const cv::Mat& maskMiss,
void generateLabelMap(Dtype* transformedLabel, const cv::Size& imageSize, const cv::Mat& maskMiss,
const MetaData& metaData) const;
void putGaussianMaps(Dtype* entry, const cv::Point2f& center, const int stride, const int gridX, const int gridY,
const float sigma) const;
Expand Down
12 changes: 6 additions & 6 deletions src/caffe/openpose/dataAugmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace caffe {
}

void applyCrop(cv::Mat& imageAugmented, const cv::Point2i& cropCenter, const cv::Mat& image,
const unsigned char defaultBorderValue, const OPTransformationParameter& param_)
const unsigned char defaultBorderValue, const cv::Size& cropSize)
{
if (!image.empty())
{
Expand All @@ -175,8 +175,8 @@ namespace caffe {
throw std::runtime_error{"Input and output images must be different"
+ getLine(__LINE__, __FUNCTION__, __FILE__)};
// Parameters
const auto cropX = (int) param_.crop_size_x();
const auto cropY = (int) param_.crop_size_y();
const auto cropX = (int)cropSize.width;
const auto cropY = (int)cropSize.height;
// Crop image
// 1. Allocate memory
imageAugmented = cv::Mat(cropY, cropX, image.type(), cv::Scalar{(double)defaultBorderValue});
Expand Down Expand Up @@ -227,11 +227,11 @@ namespace caffe {
}

void applyCrop(MetaData& metaData, const cv::Point2i& cropCenter,
const OPTransformationParameter& param_, const PoseModel poseModel)
const cv::Size& cropSize, const PoseModel poseModel)
{
// Update metaData
const auto cropX = (int) param_.crop_size_x();
const auto cropY = (int) param_.crop_size_y();
const auto cropX = (int)cropSize.width;
const auto cropY = (int)cropSize.height;
const int offsetLeft = -(cropCenter.x - (cropX/2));
const int offsetUp = -(cropCenter.y - (cropY/2));
const cv::Point2f offsetPoint{(float)offsetLeft, (float)offsetUp};
Expand Down
Loading

0 comments on commit 6d7e794

Please sign in to comment.