Ai
2 Star 14 Fork 5

computer-vision/OpenCV-Python-Tutorial

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
minAreaRect-旋转矩形.py 814 Bytes
一键复制 编辑 原始数据 按行查看 历史
GH 提交于 2017-07-27 12:52 +08:00 . fitEllipse
# -*- 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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/computer-vision/OpenCV-Python-Tutorial.git
git@gitee.com:computer-vision/OpenCV-Python-Tutorial.git
computer-vision
OpenCV-Python-Tutorial
OpenCV-Python-Tutorial
master

搜索帮助