1 | initial version |
apologies, forgot to add some karma for this ..
"shaped thing over white background," - since opencv wants white contours on dark bg, you probably have to use THRESH_INVERT. also visualizing the binary image using imshow() might be helpful.
2 | No.2 Revision |
apologies, forgot to add some karma for this ..
"shaped thing over white background," - since opencv wants white contours on dark bg, you probably have to use THRESH_INVERT. also visualizing the binary image using imshow() might be helpful.
then, to see the outcome of your contours finding / warping, you'd need to run it in a loop, not only once:
thresh_callback( 0, 0 );
// rect is the RotatedRect (I got it from a contour...)
while(true) {
RotatedRect rect;
// matrices we'll use
Mat M, rotated, cropped;
// get angle and size from the bounding box
float angle = rect.angle;
Size rect_size = rect.size;
if (rect.angle < -45.) {
angle += 90.0;
swap(rect_size.width, rect_size.height);
}
// get the rotation matrix
M = getRotationMatrix2D(rect.center, angle, 1.0);
// perform the affine transformation
warpAffine(src, rotated, M, src.size(), INTER_CUBIC);
// crop the resulting image
getRectSubPix(rotated, rect_size, rect.center, cropped);
if (waitKey(10) > 0 ) break;
}