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++.
Asked
Active
Viewed 1,696 times
-4
-
1To be honest, this is like one of the first steps when using OpenCV, and definitely not worth asking for on Stack Overflow, since most "getting started" tutorials cover this topic. Also, have a look at the multiple options shown in the [documentation](https://docs.opencv.org/4.0.1/d3/d63/classcv_1_1Mat.html#ad543b6bd296ae1247032c750af4718e1). – HansHirse Mar 12 '19 at 13:29
-
I understand you. The thing is that i am not learning it and i just needed to learn this thing. I spend around 20 minutes trying to find exactly this thing, but i didn't. Anyway, thank you for your reply. – Anton Barinov Mar 12 '19 at 14:40
-
Possible duplicate of [openCv crop image](https://stackoverflow.com/questions/14365411/opencv-crop-image) (Just searched SO for "crop opencv"...) – Dan Mašek Mar 12 '19 at 14:55
-
@DanMašek i already got an answer below. The question that you send is about cropping specific area with 4 points. I dont need it. I needed some kind of padding, and i got it and marked question as answered. – Anton Barinov Mar 12 '19 at 18:39
1 Answers
2
Simple:
int padding = 5;
cv::Mat crop = cv::Mat(img, cv::Rect(padding, padding, img.cols - 2 * padding, img.rows - 2 * padding));

Nuzhny
- 1,869
- 1
- 7
- 13