Python中文
首页
教程
问答
标签
搜索
登录
注册
用Open检测图像中矩形的中心和角度
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一张照片如下:</p> <p><a href="https://i.stack.imgur.com/1jXgB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1jXgB.png" alt="Sample image containing many rectangle contours"/></a></p> <p>我需要找出矩形的数目,每个矩形的中心,测量平行于穿过中心的矩形长边的轴之间的角度,并从水平方向逆时针方向测量角度。我在图像中找到了矩形的数量。我很惊讶地找到了反射的中心和角度。通过瞬间并不能给我正确的答案。</p> <p>我的代码:</p> <pre><code>import cv2 import numpy as np import sys img = cv2.imread(str(sys.argv[1]),0) ret,thresh = cv2.threshold(img,127,255,0) contours,hierarchy = cv2.findContours(thresh,1,2) for contour in contours: area = cv2.contourArea(contour) if area>100000: contours.remove(contour) cnt = contours[0] epsilon = 0.02*cv2.arcLength(cnt,True) approx = cv2.approxPolyDP(cnt,epsilon,True) print 'No of rectangles',len(approx) #finding the centre of the contour M = cv2.moments(cnt) cx = int(M['m10']/M['m00']) cy = int(M['m01']/M['m00']) print cx,cy </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你可以这样做:</p> <ol> <li>连接组件标签,以便检测每个模式(在您的情况下是矩形)</li> <li>把不同图像中的图案分开</li> <li>(可选)如果图案不是所有矩形,则使用形状索引来区分它们</li> <li>使用主成分分析(PCA)计算主轴,它会给出你要找的角度。</li> </ol>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
VirtualEnvRapper错误:路径python2(来自python=python2)不存在
3 回答
virtualenvs上的pyinstaller,没有名为导入错误的模块
5 回答
virtualenvs是否可以退回到用户包而不是系统包?
2 回答
virtualenvwrapper CentOS7
10 回答
virtualenvwrapper IOError:[Errno 13]权限被拒绝
2 回答
virtualenvwrapper mkproject和shell在windows中的启动问题?
5 回答
virtualenvwrapper mkvirtualenv不工作但没有错误
7 回答
Virtualenvwrapper python bash
8 回答
virtualenvwrapper:“workon”何时更改到项目目录?
8 回答
virtualenvwrapper:mkvirtualenv可以工作,但是rmvirtualenv返回bash:没有这样的文件或目录
6 回答
virtualenvwrapper:virtualenv信息存储在哪里?
4 回答
virtualenvwrapper:命令“python设置.pyegg_info“失败,错误代码为1
3 回答
virtualenvwrapper:如何将mkvirtualenv的默认Python版本/路径更改为ins
9 回答
Virtualenvwrapper:模块“pkg_resources”没有属性“iter_entry_points”
2 回答
Virtualenvwrapper:没有名为virtualenvwrapp的模块
10 回答
Virtualenvwrapper.bash_profi的正确设置
2 回答
Virtualenvwrapper.hook:权限被拒绝
5 回答
virtualenvwrapper.sh:fork:资源暂时不可用Python/Djang
3 回答
Virtualenvwrapper.shlssitepackages命令不工作
6 回答
Virtualenvwrapper.sh函数在bash sh中不可用
10 回答