寻找轮廓之前需使用阈值或者canny边缘检测
找到轮廓
python
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
绘制轮廓
第三个参数是轮廓的索引
python
cv.drawContours(img, contours, -1, (0,255,0), 3)

轮廓面积
python
area = cv.contourArea(cnt)
轮廓周长(弧长)
python
perimeter = cv.arcLength(cnt,True)
轮廓的外接矩形
(1)直角矩形
python
x,y,w,h = cv.boundingRect(cnt)
cv.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
(2)旋转矩形


轮廓形状匹配
