代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
# @Time : 2017/7/27 12:33
# @Author : play4fun
# @File : minAreaRect-旋转矩形.py
# @Software: PyCharm
"""
minAreaRect-旋转矩形.py:
"""
import cv2
import numpy as np
img = cv2.imread('../data/lightning.png')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
image, contours, hierarchy = cv2.findContours(imgray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = [cnt for cnt in contours if cv2.contourArea(cnt) > 100]
print('len(contours)', len(contours))
cnt = contours[0]
#方向是物体定向的角度
(x, y), (MA, ma), angle = cv2.fitEllipse(cnt)
print((x, y), (MA, ma), angle)
rect = cv2.minAreaRect(cnt)
box = cv2.boxPoints(rect)
box = np.int0(box)
img = cv2.drawContours(img, [box], 0, (0, 0, 255), 2)
cv2.imshow('fd', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。