# Cutting a table from an image

So, i use template matching to find corners of a table in the larger document, and then i need to cut it, and save as an image. But i could't find any function or lesson that could help me in it. Maybe someone can help or show a few useful links? C:\fakepath\screenshot1.jpg C:\fakepath\screenshot1.jpg

edit retag close merge delete

@sturkmen, please can you STOP reviving old topics?

( 2015-07-01 06:43:49 -0500 )edit

Sort by ยป oldest newest most voted

Hmm @Haris I think you are making it way to difficult. If I understood it correctly he already found the 3 corners using template matching, this he has the coordinates of those points. What I suggest is making a region of interest based on those points, using a Rect element and then do a deep copy using

Rect ROI(Point(x1,y1), Point(x2,y2));
Mat table = original( ROI ).clone();


Imaging marker top_right, bottom_left and bottom_right. I consider that each marker is now defined by a rectangle which you visualise. Then you can calculate the location based on:

int x1 = top_right.x;
int y1 = top_right.y + top_right.height;
int x2 = bottom_left.x + top_left.width;
int y2 = bottom_left.y;

more

Thanks both your and @Haris for help and the answers a lot. Will try suggested ways immediately.

( 2015-02-13 09:13:31 -0500 )edit

Try,

• Find contours, note that you need to extract only outer contour (use CV_RETR_EXTERNAL as mode).

• Now for each contour find bounding rect

• Use bound rect to crop each object, here you may use image ROI

more

1

@StevenPuttemans I agree you, the way you suggested would be the right way as he already found the corners, may be you could post this as the answer.

( 2015-02-13 07:26:26 -0500 )edit

Official site

GitHub

Wiki

Documentation