Wednesday, July 27, 2022

[FIXED] How to crop image's borders opencv

Issue

I have an image with size 640x400 and i need to crop the defined borders, so 5 px from each side. So, the end image will 630x390 and without the borders. What is the easiest way to do in with openCV in c++.


Solution

Simple:

int padding = 5;
cv::Mat crop = cv::Mat(img, cv::Rect(padding, padding, img.cols - 2 * padding, img.rows - 2 * padding));


Answered By - Nuzhny
Answer Checked By - Katrina (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.