python检测网格
来源:互联网 发布:dnf淘宝买金币安全吗 编辑:程序博客网 时间:2024/05/21 10:03
我有一个简单的网格图像,我想确定网格大小,例如6x6,使用Python和cv212x12等等。。我测试它上面3x3网格,我打算确定网格大小通过计算有多少垂直/水平行通过检测他们的形象:我的代码检测线路,可以看到下面,但是有多个行发现每一行在我的形象:(有两个1px绿线画的每一行图片)我不能简单的行数除以两个因为(取决于网格的大小)有时只是一行将它们分开。我怎样才能更准确地检测和画一行在原始图像中发现每一行吗?我有调整阈值设置,减少图像黑色和白色,但我仍然会多个行。我认为这是因为精明的边缘检测?
I have a simple grid in an image, I am trying to determine the grid size, e.g. 6x6, 12x12, etc. Using Python and cv2.
I am testing it with the above 3x3 grid, I was planning to determine the grid size by counting how many vertical / horizontal lines there are by detecting them in the image:
import cv2import numpy as npim = cv2.imread('photo2.JPG')gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)imgSplit = cv2.split(im)flag,b = cv2.threshold(imgSplit[2],0,255,cv2.THRESH_OTSU) element = cv2.getStructuringElement(cv2.MORPH_CROSS,(1,1))cv2.erode(b,element)edges = cv2.Canny(b,150,200,3,5)while(True): img = im.copy() lines = cv2.HoughLinesP(edges,1,np.pi/2,2, minLineLength = 620, maxLineGap = 100)[0] for x1,y1,x2,y2 in lines: cv2.line(img,(x1,y1),(x2,y2),(0,255,0),1) cv2.imshow('houghlines',img) if k == 27: breakcv2.destroyAllWindows()
My code detects the lines, as can be seen below, however there are multiple lines detected for each line in my image:
(there are two 1px green lines drawn for every line in the image)
I cannot simply divide the number of lines by two because (depending on the grid size) sometimes just the one line will be drawn.
How can I more accurately detect and draw a single line for every line detected in the original image?
I have tweaked threshold settings, reducing the image to black and white, yet I still get multiple lines. I assume this is because of the canny edge detection?
(原文:Problem may be because canny detects both edges of your line, so considered as two lines. One option is to iterate through the lines, and find the nearby lines. If near discard one.)
楼主:由于@AbidRahmanK,我最终做什么。
(原文:Thanks @AbidRahmanK, that is what I ended up doing.)
我最后遍历的线和删除线在10px的:
I ended up iterating through the lines and removing lines that were within 10px of one another:
lines = cv2.HoughLinesP(edges,1,np.pi/180,275, minLineLength = 600, maxLineGap = 100)[0].tolist()for x1,y1,x2,y2 in lines: for index, (x3,y3,x4,y4) in enumerate(lines): if y1==y2 and y3==y4: # Horizontal Lines diff = abs(y1-y3) elif x1==x2 and x3==x4: # Vertical Lines diff = abs(x1-x3) else: diff = 0 if diff < 10 and diff is not 0: del lines[index]gridsize = (len(lines) - 2) / 2
- python检测网格
- 大规模网格形碰撞检测
- 网格算法-STG游戏弹幕检测思路
- 使用Python实现网格索引
- python程序-->字符图网格
- 网格
- 网格
- 网格
- 网格
- 网格布检验报告及备案玻璃纤维网格布的检测方式
- Ogre碰撞检测,精确到物体网格三角面
- [OpenGL] 二维游戏:网格布局与碰撞检测
- python matplot 画网格坐标轴方法
- python检测当前系统
- python 检测内存溢出
- python检测网站
- python检测质数程序
- 【Python】检测Web服务质量
- EOJ 3276 连续正整数之和(模拟)
- 2017 ACM/ICPC Asia Regional Shenyang Online 1005 number number number(矩阵快速幂)
- xshell5使用ssh连接阿里云服务器
- python使用pip安装第三方库的方法
- logrotate
- python检测网格
- 类的初始化顺序
- JDBC
- Servlet基础
- 二叉树遍历——转载于网易博客summer
- phpdoc
- 2017-09-10 LeetCode_020 Valid Parentheses
- java volatile关键字的用法
- Qt 线程同步之 QWaitCondition