资源简介
本例子是使用python-opencv的支持库实现的表针读数的识别算法
代码片段和文件信息
import cv2
import numpy as np
import time
import NUMBER
import screenshot
def dist_2_pts(x1 y1 x2 y2):
return np.sqrt((x2 - x1)**2 + (y2 - y1)**2)
def avg_circles(circles b):
avg_x=0
avg_y=0
avg_r=0
for i in range(b):
avg_x = avg_x + circles[0][i][0]
avg_y = avg_y + circles[0][i][1]
avg_r = avg_r + circles[0][i][2]
avg_x = int(avg_x/ (b))
avg_y = int(avg_y/(b))
avg_r = int(avg_r/(b))
return avg_x avg_y avg_r
def avg_circles_three(circles b):
number=[1]
avg_x = [000]
avg_y = [000]
avg_r = [000]
initial=[000]
for i in range(b):
if (initial[0] == 1 ):
if(dist_2_pts(avg_x[0]avg_y[0]circles[0][i][0]circles[0][i][1]) >= (avg_r[0]+circles[0][i][2])):
if(initial[1] == 1):
if (dist_2_pts(avg_x[1] avg_y[1] circles[0][i][0] circles[0][i][1]) >= (avg_r[1] + circles[0][i][2])):
if (initial[2] == 1):
avg_x[2] = (avg_x[2] + circles[0][i][0])/2
avg_y[2] = (avg_y[2] + circles[0][i][1])/2
avg_r[2] = (avg_r[2] + circles[0][i][2])/2
else:
initial[2] = 1
number[0]=number[0]+1
avg_x[2] = circles[0][i][0]
avg_y[2] = circles[0][i][1]
avg_r[2] = circles[0][i][2]
else:
avg_x[1] = (avg_x[1] + circles[0][i][0])/2
avg_y[1] = (avg_y[1] + circles[0][i][1])/2
avg_r[1] = (avg_r[1] + circles[0][i][2])/2
else:
initial[1] = 1
avg_x[1] = circles[0][i][0]
avg_y[1] = circles[0][i][1]
avg_r[1] = circles[0][i][2]
number[0] = number[0] + 1
else:
avg_x[0] = (avg_x[0] + circles[0][i][0])/2
avg_y[0] = (avg_y[0] + circles[0][i][1])/2
avg_r[0] = (avg_r[0] + circles[0][i][2])/2
else:
avg_x[0] = circles[0][i][0]
avg_y[0] = circles[0][i][1]
avg_r[0] = circles[0][i][2]
initial[0]=1
for i in range(3):
avg_x[i] = int(avg_x[i])
avg_y[i] = int(avg_y[i])
avg_r[i] = int(avg_r[i])
return avg_x avg_y avg_r number
def calibrate_gauge(gauge_number file_type):
img = cv2.imread(‘gauge-%s.%s‘ %(gauge_number file_type))
height width = img.shape[:2]
gray = cv2.cvtColor(img cv2.COLOR_BGR2GRAY) #convert to gray
#detect circles
circles = cv2.HoughCircles(gray cv2.HOUGH_GRADIENT 1 20 np.array([]) 100 80 int(height*0.1) int(height*0.48))
a b c = circles.shape
xyr = avg_circles(circles b)
‘‘‘
Circles=avg_circles_three(circlesb)
x=Circles[0][0]
y=Circles[1][0]
r=
- 上一篇:基于Python的酒店管理系统
- 下一篇:Python源码剖析.pdf59505
相关资源
- Python源码剖析.pdf59505
- 基于Python的酒店管理系统
- 打砖块
- python数据结构
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
评论
共有 条评论