Ask Your Question

Revision history [back]

Well saying I've used the code from the tutorial tells me you just copy pasted the code. Those samples are there for you to adapt it to your needs ... Questions like this never get decent support, because it tells us you did not try anything rather then copying the code.

You could follow these steps

  • Replace CV_RETR_TREE by CV_RETR_EXTERNAL to remove useless contours and only keep the interesting contours
  • Then calculate the area of your contours, using contourArea()
  • Now define a threshold for minimal and maximal area, to keep only your rectangle contour

Using that final contour you can cut that part of the image out, using the region of interest approach.