提交 4faace17 编写于 作者: G Gines Hidalgo

90 and 270 rotations working again #1586

上级 9433792b
......@@ -418,6 +418,7 @@ OpenPose Library - Release Notes
1. Main improvements:
2. Functions or parameters renamed:
3. Main bugs fixed:
1. 90 and 270-degree rotations working again.
4. Changes/additions that affect the compatibility with the OpenPose Unity Plugin:
......
......@@ -112,6 +112,11 @@ namespace op
*/
explicit Matrix(const void* cvMatPtr);
/**
* Analog to cv::Mat(int rows, int cols, int type, void *data, size_t step=AUTO_STEP)
*/
explicit Matrix(const int rows, const int cols, const int type);
/**
* Analog to cv::Mat(int rows, int cols, int type, void *data, size_t step=AUTO_STEP)
* Very important: This Matrix will only "borrow" this pointer, so the caller must make sure to maintain the
......
......@@ -13,13 +13,15 @@ namespace op
OP_API void keepRoiInside(Rectangle<int>& roi, const int imageWidth, const int imageHeight);
OP_API void transpose(Matrix& matrix);
/**
* It performs rotation and flipping over the desired Mat.
* @param cvMat 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(Matrix& cvMat, const double rotationAngle, const bool flipFrame = false);
OP_API void rotateAndFlipFrame(Matrix& frame, const double rotationAngle, const bool flipFrame = false);
/**
* Wrapper of CV_CAP_PROP_FRAME_COUNT to avoid leaving OpenCV dependencies on headers.
......
......@@ -54,6 +54,19 @@ namespace op
}
}
Matrix::Matrix(const int rows, const int cols, const int type) :
spImpl{std::make_shared<ImplMatrix>()}
{
try
{
spImpl->mCvMat = cv::Mat(rows, cols, type);
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
Matrix::Matrix(const int rows, const int cols, const int type, void* cvMatPtr) :
spImpl{std::make_shared<ImplMatrix>()}
{
......
......@@ -224,14 +224,28 @@ namespace op
}
}
void transpose(Matrix& matrix)
{
cv::Mat cvMatrix = OP_OP2CVMAT(matrix);
Matrix matrixFinal(matrix.cols(), matrix.rows(), matrix.type());
cv::Mat cvMatrixFinal = OP_OP2CVMAT(matrixFinal);
cv::transpose(cvMatrix, cvMatrixFinal);
std::swap(matrix, matrixFinal);
}
void rotateAndFlipFrame(Matrix& frame, const double rotationAngle, const bool flipFrame)
{
try
{
cv::Mat cvMatFrame = OP_OP2CVMAT(frame);
if (!cvMatFrame.empty())
// cv::flip() does not moidify the memory location of the cv::Mat, but cv::transpose does
if (!frame.empty())
{
const auto rotationAngleInt = (int)std::round(rotationAngle) % 360;
// Transposing
if (rotationAngleInt == 90 || rotationAngleInt == 270 || rotationAngleInt == -90 || rotationAngleInt == -270)
transpose(frame);
// Mirroring (flipping)
cv::Mat cvMatFrame = OP_OP2CVMAT(frame);
if (rotationAngleInt == 0 || rotationAngleInt == 360)
{
if (flipFrame)
......@@ -239,7 +253,6 @@ namespace op
}
else if (rotationAngleInt == 90 || rotationAngleInt == -270)
{
cv::transpose(cvMatFrame, cvMatFrame);
if (!flipFrame)
cv::flip(cvMatFrame, cvMatFrame, 0);
}
......@@ -252,7 +265,6 @@ namespace op
}
else if (rotationAngleInt == 270 || rotationAngleInt == -90)
{
cv::transpose(cvMatFrame, cvMatFrame);
if (flipFrame)
cv::flip(cvMatFrame, cvMatFrame, -1);
else
......@@ -260,7 +272,7 @@ namespace op
}
else
error("Rotation angle = " + std::to_string(rotationAngleInt)
+ " != {0, 90, 180, 270} degrees.", __LINE__, __FUNCTION__, __FILE__);
+ " != {0, 90, 180, 270} degrees.", __LINE__, __FUNCTION__, __FILE__);
}
}
catch (const std::exception& e)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册