1 | initial version |
Basically what you want to create is a binary mask, based on the contour that you have. You already got that one. Since you apply the contour functionality on it.
// Convert to binary image by thresholding it
threshold(gray, gray, 220, 255, THRESH_BINARY);
What you can do is simply multiply the original image, with the binary image. Which will suppress all non interesting image pixels and make them black. This is called masking. Then go through the complete image.
Another approach could be to first use the boundingbox property of a contour, and apply that bounding box as a region of interest on your binary image, then only process that smaller part.
2 | No.2 Revision |
Basically what you want to create is a binary mask, based on the contour that you have. You already got that one. Since you apply the contour functionality on it.
// Convert to binary image by thresholding it
threshold(gray, gray, 220, 255, THRESH_BINARY);
What you can do is simply multiply the original image, with the binary image. Which will suppress all non interesting image pixels and make them black. This is called masking. Then go through the complete image.
Another approach could be to first use the boundingbox property of a contour, and apply that bounding box as a region of interest on your binary image, then only process that smaller part.
Some sample code:
You can find it here since the forum doesn't allow me to paste the code for some reason...