Ask Your Question

crop image to itself c++

asked 2017-07-27 01:39:18 -0500

Nicolet gravatar image

updated 2017-07-27 03:34:22 -0500


When I crop image to itself do I need the .clone() function?

I mean:

Mat image = imread("somePath.bmp");

What is the right way to crop it?

image = image(rect(0,0,10,10)).clone();

or I can save the clone() and write

image = image(rect(0,0,10,10));

Thanks to all the helpers

edit retag flag offensive close merge delete


image = image(rect(0,0,10,10)); is ok

jsxyhelu gravatar imagejsxyhelu ( 2017-07-27 08:46:57 -0500 )edit

why not roi = image(rect(0,0,10,10));

jsxyhelu gravatar imagejsxyhelu ( 2017-07-27 08:47:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-07-27 02:09:37 -0500

vps gravatar image

updated 2017-07-27 03:49:30 -0500

Hi ,

You can try below code for cropping the image

Mat image = imread("somePath.bmp");
image(Rect(Point(0, 10), Point(10, 0))).copyTo(cropped_image);
imshow("cropped_image", cropped_image);
edit flag offensive delete link more


Hi , thank you for your reply

I want to save the copy by value that happed when we using .clone() or .copyTo

When I using large images it could be inefficient time consuming

Nicolet gravatar imageNicolet ( 2017-07-27 06:11:19 -0500 )edit

I am applying this on large images. Just try once and let me know. I am also beginner :)

vps gravatar imagevps ( 2017-07-27 14:20:48 -0500 )edit

@Nicolet, if you do not do a copy, you will be working directly on the pixels of the original image. If it is just visualising, then do imshow("cropped_image", cropped_image(Rect(x,y,w,h)));

StevenPuttemans gravatar imageStevenPuttemans ( 2017-07-28 03:18:37 -0500 )edit

Question Tools

1 follower


Asked: 2017-07-27 01:39:18 -0500

Seen: 4,896 times

Last updated: Jul 27 '17