Skip to content

Commit

Permalink
Merge pull request opencv#22899 from mshabunin:fix-videoio-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Dec 1, 2022
2 parents 5696629 + 5862b50 commit 6c399aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
25 changes: 0 additions & 25 deletions modules/videoio/src/cap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,29 +698,4 @@ int VideoWriter::fourcc(char c1, char c2, char c3, char c4)
return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24);
}


void applyMetadataRotation(const IVideoCapture& cap, OutputArray mat)
{
bool rotation_auto = 0 != cap.getProperty(CAP_PROP_ORIENTATION_AUTO);
int rotation_angle = static_cast<int>(cap.getProperty(CAP_PROP_ORIENTATION_META));

if(!rotation_auto || rotation_angle%360 == 0)
{
return;
}

cv::RotateFlags flag;
if(rotation_angle == 90 || rotation_angle == -270) { // Rotate clockwise 90 degrees
flag = cv::ROTATE_90_CLOCKWISE;
} else if(rotation_angle == 270 || rotation_angle == -90) { // Rotate clockwise 270 degrees
flag = cv::ROTATE_90_COUNTERCLOCKWISE;
} else if(rotation_angle == 180 || rotation_angle == -180) { // Rotate clockwise 180 degrees
flag = cv::ROTATE_180;
} else { // Unsupported rotation
return;
}

cv::rotate(mat, mat, flag);
}

} // namespace cv
30 changes: 28 additions & 2 deletions modules/videoio/src/cap_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ class IVideoCapture
virtual int getCaptureDomain() { return CAP_ANY; } // Return the type of the capture object: CAP_DSHOW, etc...
};

void applyMetadataRotation(const IVideoCapture& cap, OutputArray mat);

class IVideoWriter
{
public:
Expand All @@ -245,6 +243,34 @@ class VideoCapturePrivateAccessor

//===================================================

// Utility

static inline void applyMetadataRotation(const IVideoCapture& cap, OutputArray mat)
{
bool rotation_auto = 0 != cap.getProperty(CAP_PROP_ORIENTATION_AUTO);
int rotation_angle = static_cast<int>(cap.getProperty(CAP_PROP_ORIENTATION_META));

if(!rotation_auto || rotation_angle%360 == 0)
{
return;
}

cv::RotateFlags flag;
if(rotation_angle == 90 || rotation_angle == -270) { // Rotate clockwise 90 degrees
flag = cv::ROTATE_90_CLOCKWISE;
} else if(rotation_angle == 270 || rotation_angle == -90) { // Rotate clockwise 270 degrees
flag = cv::ROTATE_90_COUNTERCLOCKWISE;
} else if(rotation_angle == 180 || rotation_angle == -180) { // Rotate clockwise 180 degrees
flag = cv::ROTATE_180;
} else { // Unsupported rotation
return;
}

cv::rotate(mat, mat, flag);
}

//===================================================

// Wrapper

class LegacyCapture : public IVideoCapture
Expand Down

0 comments on commit 6c399aa

Please sign in to comment.