Ask Your Question
0

crop image to itself c++

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

Nicolet gravatar image

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

Hi

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

Comments

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

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

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

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

1 answer

Sort by ยป oldest newest most voted
1

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

vps gravatar image

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

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

Comments

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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 6,273 times

Last updated: Jul 27 '17