# The "canny" edge-detector does only work with grayscale images
# so to be sure, convert the image
# otherwise you will get something like:
# terminate called after throwing an instance of 'cv::Exception'
# what(): /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/work/OpenCV-2.2.0/modules/imgproc/src/canny.cpp:67: error: (-210) in function cvCanny
cvmat=cvmat.BGR2GRAY
# Use the "canny" edge detection algorithm (http://en.wikipedia.org/wiki/Canny_edge_detector)
# Parameters are two colors that are then used to determine possible corners
canny=cvmat.canny(50,150)
# Look for contours
# We want them to be returned as a flat list (CV_RETR_LIST) and simplified (CV_CHAIN_APPROX_SIMPLE)
# Both are the defaults but included here for clarity
# Positive angle values are clockwise and negative values counter clockwise (so -60 means 60 degree counter clockwise)
box=contour.min_area_rect
puts"found minimal rectangle with its center at (#{box.center.x.round},#{box.center.y.round}), width of #{box.size.width.round}px, height of #{box.size.height.round} and an angle of #{box.angle.round} degree"