Ask Your Question
0

Cutting a table from an image

asked 2015-02-12 11:03:06 -0500

Storiy gravatar image

updated 2015-06-30 16:56:34 -0500

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.jpgimage description

edit retag flag offensive close merge delete

Comments

@sturkmen, please can you STOP reviving old topics?

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

2 answers

Sort by ยป oldest newest most voted
4

answered 2015-02-13 03:38:02 -0500

updated 2015-02-13 07:34:25 -0500

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();

EDIT: lets add how to add the coordinates of the ROI.

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;
edit flag offensive delete link more

Comments

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

Storiy gravatar imageStoriy ( 2015-02-13 09:13:31 -0500 )edit
4

answered 2015-02-12 22:32:37 -0500

Haris gravatar image

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

edit flag offensive delete link more

Comments

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.

Haris gravatar imageHaris ( 2015-02-13 07:26:26 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-02-12 11:03:06 -0500

Seen: 422 times

Last updated: Jun 30 '15