Skip to content

Commit

Permalink
Renamed intRound to avoid bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gineshidalgo99 committed Jan 18, 2019
1 parent f0664bc commit 1f13f81
Show file tree
Hide file tree
Showing 29 changed files with 247 additions and 208 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

-----------------

| | Python (CUDA GPU) | Python (CPU)| CUDA GPU | CPU | Debug mode |
| :---: | :---: | :---: | :---: |:---: | :---: |
| **Linux** | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/1)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/2)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/3)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/4)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/5)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) |
| **MacOS** | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/6)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/7)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/8)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) |
<!-- | **Windows** | | | | | | -->
| | `Python (CUDA GPU)` | `Python (CPU)` | `CUDA GPU` | `CPU` | `Debug mode` |
| :---: | :---: | :---: | :---: |:---: | :---: |
| **`Linux`** | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/1)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/2)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/3)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/4)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/5)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) |
| **`MacOS`** | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/6)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/7)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) | [![Status](https://travis-matrix-badges.herokuapp.com/repos/CMU-Perceptual-Computing-Lab/openpose/branches/master/8)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose) |
<!-- | **`Windows`** | | | | | | -->
<!--
Note: Currently using [travis-matrix-badges](https://github.com/bjfish/travis-matrix-badges) vs. traditional [![Build Status](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose.svg?branch=master)](https://travis-ci.org/CMU-Perceptual-Computing-Lab/openpose)
-->
Expand Down
7 changes: 4 additions & 3 deletions doc/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ OpenPose Library - Release Notes
1. Changed several functions on `core/`, `pose/`, `face/`, and `hand/` modules.
3. `CPU_ONLY` changed by `USE_CUDA` to keep format.
3. Main bugs fixed:
1. Scaling resize issue fixed: ~1-pixel offset due to not considering 0-based indexes.
1. Scaling resize issue fixed: approximately 1-pixel offset due to not considering 0-based indexes.
2. Ubuntu installer script now works even if Python pip was not installed previously.
3. Flags to set first and last frame as well as jumping frames backward and forward now works on image directory reader.

Expand Down Expand Up @@ -203,7 +203,7 @@ OpenPose Library - Release Notes
4. CvMatToOpInput requires PoseModel to know the normalization to be performed.
5. Created `net/` module in order to reduce `core/` number of classes and files and for future scalability.
3. Main bugs fixed:
1. Slight speed up (~1%) for performing the non-maximum suppression stage only in the body part heatmaps channels, and not also in the PAF channels.
1. Slight speed up (around 1%) for performing the non-maximum suppression stage only in the body part heatmaps channels, and not also in the PAF channels.
2. Fixed core-dumped in PoseRenderer with GUI when changed element to be rendered to something else than skeleton.
3. 3-D visualizer does not crash on exit anymore.
4. Fake pause ('m' key pressed) works again.
Expand Down Expand Up @@ -320,8 +320,9 @@ OpenPose Library - Release Notes
9. Renamed `--frame_keep_distortion` as `--frame_undistort`, which performs the opposite operation (the default value has been also changed to the opposite).
10. Renamed `--camera_parameter_folder` as `--camera_parameter_path` because it could also take a whole XML file path rather than its parent folder.
11. Default value of flag `--scale_gap` changed from 0.3 to 0.25.
12. Moved most sh scripts into the `scripts/` folder. Only models/getModels.sh and the *.bat files are kept under `models/` and `3rdparty/windows`.
12. Moved most sh scripts into the `scripts/` folder. Only models/getModels.sh and the `*.bat` files are kept under `models/` and `3rdparty/windows`.
13. For Python compatibility and scalability increase, template `TDatums` used for `include/openpose/wrapper/wrapper.hpp` has changed from `std::vector<Datum>` to `std::vector<std::shared_ptr<Datum>>`, including the respective changes in all the worker classes. In addition, some template classes have been simplified to only take 1 template parameter for user simplicity.
14. Renamed intRound, charRound, etc. by positiveIntRound, positiveCharRound, etc. so that people can realize it is not safe for negative numbers.
3. Main bugs fixed:
1. CMake-GUI was forcing to Release mode, allowed Debug modes too.
2. NMS returns in index 0 the number of found peaks. However, while the number of peaks was truncated to a maximum of 127, this index 0 was saving the real number instead of the truncated one.
Expand Down
13 changes: 8 additions & 5 deletions include/openpose/gpu/cuda.hu
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,37 @@

namespace op
{
// VERY IMPORTANT: These fast functions does NOT work for negative integer numbers.
// E.g., positiveIntRound(-180.f) = -179.

// Round functions
// Signed
template<typename T>
inline __device__ char charRound(const T a)
inline __device__ char positiveCharRound(const T a)
{
return char(a+0.5f);
}

template<typename T>
inline __device__ signed char sCharRound(const T a)
inline __device__ signed char positiveSCharRound(const T a)
{
return (signed char)(a+0.5f);
}

template<typename T>
inline __device__ int intRound(const T a)
inline __device__ int positiveIntRound(const T a)
{
return int(a+0.5f);
}

template<typename T>
inline __device__ long longRound(const T a)
inline __device__ long positiveLongRound(const T a)
{
return long(a+0.5f);
}

template<typename T>
inline __device__ long long longLongRound(const T a)
inline __device__ long long positiveLongLongRound(const T a)
{
return (long long)(a+0.5f);
}
Expand Down
2 changes: 1 addition & 1 deletion include/openpose/producer/datumProducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace op
&& frameLast > spProducer->get(CV_CAP_PROP_FRAME_COUNT)-1)
error("The desired last frame must be lower than the length of the video or the number of images."
" Current: " + std::to_string(frameLast) + " vs. "
+ std::to_string(intRound(spProducer->get(CV_CAP_PROP_FRAME_COUNT))-1) + ".",
+ std::to_string(positiveIntRound(spProducer->get(CV_CAP_PROP_FRAME_COUNT))-1) + ".",
__LINE__, __FUNCTION__, __FILE__);
// Set frame first and step
if (spProducer->getType() != ProducerType::FlirCamera && spProducer->getType() != ProducerType::IPCamera
Expand Down
2 changes: 1 addition & 1 deletion include/openpose/producer/flirReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace op
private:
SpinnakerWrapper mSpinnakerWrapper;
Point<int> mResolution;
long long mFrameNameCounter;
unsigned long long mFrameNameCounter;

cv::Mat getRawFrame();

Expand Down
6 changes: 0 additions & 6 deletions include/openpose/producer/producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ namespace op
*/
void checkFrameIntegrity(cv::Mat& frame);

/**
* It performs flipping and rotation over the desired cv::Mat.
* @param cvMat cv::Mat with the frame matrix to be flipped and/or rotated.
*/
void flipAndRotate(cv::Mat& cvMat) const;

/**
* Protected function which checks that the frame producer has ended. If so, if resets
* or releases the producer according to mRepeatWhenFinished.
Expand Down
13 changes: 8 additions & 5 deletions include/openpose/utilities/fastMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,37 @@ namespace op
// E.g., std::round is really slow (~300 ms vs ~10 ms when I individually apply it to each element of a whole
// image array

// VERY IMPORTANT: These fast functions does NOT work for negative integer numbers.
// E.g., positiveIntRound(-180.f) = -179.

// Round functions
// Signed
template<typename T>
inline char charRound(const T a)
inline char positiveCharRound(const T a)
{
return char(a+0.5f);
}

template<typename T>
inline signed char sCharRound(const T a)
inline signed char positiveSCharRound(const T a)
{
return (signed char)(a+0.5f);
}

template<typename T>
inline int intRound(const T a)
inline int positiveIntRound(const T a)
{
return int(a+0.5f);
}

template<typename T>
inline long longRound(const T a)
inline long positiveLongRound(const T a)
{
return long(a+0.5f);
}

template<typename T>
inline long long longLongRound(const T a)
inline long long positiveLongLongRound(const T a)
{
return (long long)(a+0.5f);
}
Expand Down
8 changes: 8 additions & 0 deletions include/openpose/utilities/openCv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ namespace op
const int borderMode = cv::BORDER_CONSTANT, const cv::Scalar& borderValue = cv::Scalar{0,0,0});

OP_API void keepRoiInside(cv::Rect& roi, const int imageWidth, const int imageHeight);

/**
* It performs rotation and flipping over the desired cv::Mat.
* @param cvMat cv::Mat with the frame matrix to be rotated and/or flipped.
* @param rotationAngle How much the cvMat element should be rotated. 0 would mean no rotation.
* @param flipFrame Whether to flip the cvMat element. Set to false to disable it.
*/
OP_API void rotateAndFlipFrame(cv::Mat& cvMat, const double rotationAngle, const bool flipFrame = false);
}

#endif // OPENPOSE_UTILITIES_OPEN_CV_HPP
2 changes: 1 addition & 1 deletion include/openpose/wrapper/wrapperAuxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ namespace op
renderers.emplace_back(std::static_pointer_cast<Renderer>(poseGpuRenderer));
// Display
const auto numberViews = (producerSharedPtr != nullptr
? intRound(producerSharedPtr->get(ProducerProperty::NumberViews)) : 1);
? positiveIntRound(producerSharedPtr->get(ProducerProperty::NumberViews)) : 1);
auto finalOutputSizeGui = finalOutputSize;
if (numberViews > 1 && finalOutputSizeGui.x > 0)
finalOutputSizeGui.x *= numberViews;
Expand Down
6 changes: 4 additions & 2 deletions src/openpose/calibration/gridPatternFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,11 @@ namespace op
for (auto lm = 0; lm < numberPointsInLine; lm++)
{
const auto mX = fastMax(
0, fastMin(imageSize.width-1, intRound(fourPointsVector[i].x + lm*pointDirection[i].x)));
0, fastMin(
imageSize.width-1, positiveIntRound(fourPointsVector[i].x + lm*pointDirection[i].x)));
const auto mY = fastMax(
0, fastMin(imageSize.height-1, intRound(fourPointsVector[i].y + lm*pointDirection[i].y)));
0, fastMin(
imageSize.height-1, positiveIntRound(fourPointsVector[i].y + lm*pointDirection[i].y)));
const cv::Vec3b bgrValue = image.at<cv::Vec3b>(mY, mX);
sum += (bgrValue.val[0] + bgrValue.val[1] + bgrValue.val[2])/3;
count++;
Expand Down
12 changes: 6 additions & 6 deletions src/openpose/core/scaleAndSizeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace op
error("Only 1 of the dimensions of net input resolution can be <= 0.",
__LINE__, __FUNCTION__, __FILE__);
if (poseNetInputSize.x <= 0)
poseNetInputSize.x = 16 * intRound(
poseNetInputSize.x = 16 * positiveIntRound(
poseNetInputSize.y * inputResolution.x / (float) inputResolution.y / 16.f
);
else // if (poseNetInputSize.y <= 0)
poseNetInputSize.y = 16 * intRound(
poseNetInputSize.y = 16 * positiveIntRound(
poseNetInputSize.x * inputResolution.y / (float) inputResolution.x / 16.f
);
}
Expand All @@ -68,10 +68,10 @@ namespace op
error("All scales must be in the range [0, 1], i.e., 0 <= 1-scale_number*scale_gap <= 1",
__LINE__, __FUNCTION__, __FILE__);

const auto targetWidth = fastTruncate(intRound(poseNetInputSize.x * currentScale) / 16 * 16, 1,
poseNetInputSize.x);
const auto targetHeight = fastTruncate(intRound(poseNetInputSize.y * currentScale) / 16 * 16, 1,
poseNetInputSize.y);
const auto targetWidth = fastTruncate(
positiveIntRound(poseNetInputSize.x * currentScale) / 16 * 16, 1, poseNetInputSize.x);
const auto targetHeight = fastTruncate(
positiveIntRound(poseNetInputSize.y * currentScale) / 16 * 16, 1, poseNetInputSize.y);
const Point<int> targetSize{targetWidth, targetHeight};
scaleInputToNetInputs[i] = resizeGetScaleFactor(inputResolution, targetSize);
netInputSizes[i] = targetSize;
Expand Down
2 changes: 1 addition & 1 deletion src/openpose/face/faceExtractorCaffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace op
// [0, 255]
else if (heatMapScaleMode == ScaleMode::UnsignedChar)
for (auto i = 0u ; i < volumeBodyParts ; i++)
heatMapsPtr[i] = (float)intRound(fastTruncate(heatMapsPtr[i]) * 255.f);
heatMapsPtr[i] = (float)positiveIntRound(fastTruncate(heatMapsPtr[i]) * 255.f);
// Avoid values outside original range
else
for (auto i = 0u ; i < volumeBodyParts ; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/openpose/face/faceGpuRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace op
{
// GPU rendering
#ifdef USE_CUDA
// I prefer std::round(T&) over intRound(T) for std::atomic
// I prefer std::round(T&) over positiveIntRound(T) for std::atomic
const auto elementRendered = spElementToRender->load();
const auto numberPeople = faceKeypoints.getSize(0);
const Point<int> frameSize{outputData.getSize(1), outputData.getSize(0)};
Expand Down
31 changes: 17 additions & 14 deletions src/openpose/gui/guiInfoAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ namespace op
}
}

void addPeopleIds(cv::Mat& cvOutputData, const Array<long long>& poseIds, const Array<float>& poseKeypoints,
const int borderMargin)
void addPeopleIds(
cv::Mat& cvOutputData, const Array<long long>& poseIds, const Array<float>& poseKeypoints,
const int borderMargin)
{
try
{
Expand All @@ -68,27 +69,28 @@ namespace op
const auto indexSecondary = i * poseKeypointsArea + poseKeypoints.getSize(2);
if (poseKeypoints[indexMain+2] > isVisible || poseKeypoints[indexSecondary+2] > isVisible)
{
const auto xA = intRound(poseKeypoints[indexMain]);
const auto yA = intRound(poseKeypoints[indexMain+1]);
const auto xB = intRound(poseKeypoints[indexSecondary]);
const auto yB = intRound(poseKeypoints[indexSecondary+1]);
const auto xA = positiveIntRound(poseKeypoints[indexMain]);
const auto yA = positiveIntRound(poseKeypoints[indexMain+1]);
const auto xB = positiveIntRound(poseKeypoints[indexSecondary]);
const auto yB = positiveIntRound(poseKeypoints[indexSecondary+1]);
int x;
int y;
if (poseKeypoints[indexMain+2] > isVisible && poseKeypoints[indexSecondary+2] > isVisible)
{
const auto keypointRatio = intRound(0.15f * std::sqrt((xA-xB)*(xA-xB) + (yA-yB)*(yA-yB)));
const auto keypointRatio = positiveIntRound(
0.15f * std::sqrt((xA-xB)*(xA-xB) + (yA-yB)*(yA-yB)));
x = xA + 3*keypointRatio;
y = yA - 3*keypointRatio;
}
else if (poseKeypoints[indexMain+2] > isVisible)
{
x = xA + intRound(0.25f*borderMargin);
y = yA - intRound(0.25f*borderMargin);
x = xA + positiveIntRound(0.25f*borderMargin);
y = yA - positiveIntRound(0.25f*borderMargin);
}
else //if (poseKeypoints[indexSecondary+2] > isVisible)
{
x = xB + intRound(0.25f*borderMargin);
y = yB - intRound(0.5f*borderMargin);
x = xB + positiveIntRound(0.25f*borderMargin);
y = yB - positiveIntRound(0.5f*borderMargin);
}
putTextOnCvMat(cvOutputData, std::to_string(poseIds[i]), {x, y}, WHITE_SCALAR, false, cvOutputData.cols);
}
Expand Down Expand Up @@ -125,16 +127,17 @@ namespace op
if (cvOutputData.empty())
error("Wrong input element (empty cvOutputData).", __LINE__, __FUNCTION__, __FILE__);
// Size
const auto borderMargin = intRound(fastMax(cvOutputData.cols, cvOutputData.rows) * 0.025);
const auto borderMargin = positiveIntRound(fastMax(cvOutputData.cols, cvOutputData.rows) * 0.025);
// Update fps
updateFps(mLastId, mFps, mFpsCounter, mFpsQueue, id, mNumberGpus);
// Fps or s/gpu
char charArrayAux[15];
std::snprintf(charArrayAux, 15, "%4.1f fps", mFps);
// Recording inverse: sec/gpu
// std::snprintf(charArrayAux, 15, "%4.2f s/gpu", (mFps != 0. ? mNumberGpus/mFps : 0.));
putTextOnCvMat(cvOutputData, charArrayAux, {intRound(cvOutputData.cols - borderMargin), borderMargin},
WHITE_SCALAR, true, cvOutputData.cols);
putTextOnCvMat(
cvOutputData, charArrayAux, {positiveIntRound(cvOutputData.cols - borderMargin), borderMargin},
WHITE_SCALAR, true, cvOutputData.cols);
// Part to show
// Allowing some buffer when changing the part to show (if >= 2 GPUs)
// I.e. one GPU might return a previous part after the other GPU returns the new desired part, it looks
Expand Down
Loading

0 comments on commit 1f13f81

Please sign in to comment.