Ask Your Question
1

Image Crop

asked 2014-02-26 12:12:25 -0600

dondan1976 gravatar image

Hello there,

I have an image that's 320 x 240 in size. I draw a rectangle area over the image that needs to be cropped. I get 4 values from the rectangle and they are,

  1. X = X-axis value from top left of rectangle.
  2. Y = Y-axis value from top left of rectangle.
  3. Width = Width of rectangle.
  4. Height = Height of rectangle.

Now what am doing is,

Rect r(X, Y, Width, Height); Mat orig_Image; Mat cropped_Image = orig_Image(r).clone();

I tried some other approaches also. But what i see is that the cropping is not 100% accurate.

It looks like the Y axis seems to be off by few pixels.

Is there a different approach to cropping?

I am working on a C++ project.

Thanks in advance.

edit retag flag offensive close merge delete

Comments

1
Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-26 14:01:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-03-02 22:42:39 -0600

Amit gravatar image

croping should be done by this method in C++, i got accurate croping image.

Rect roi(r.x, r.y, r.width, r.height);
Mat image_roi = image(roi);
image_roi.copyTo(cropimage);
imwrite("cropimage.jpg",image_roi);
edit flag offensive delete link more

Comments

I try this code posted by @Amit

    Rect roi(r.x, r.y, r.width, r.height);
Mat image_roi = image(roi);
image_roi.copyTo(cropimage);
imwrite("cropimage.jpg",image_roi);

Error on image(roi) method could you please explain the image(roi) method? Is it is built-in method or the programmer want to write the definition for that image(roi) method? Help me to solve the error I am working in java project Thanks

Asha gravatar imageAsha ( 2015-01-30 00:43:20 -0600 )edit

Question Tools

Stats

Asked: 2014-02-26 12:12:25 -0600

Seen: 17,483 times

Last updated: Mar 02 '14