Python实现哈夫变换
2021/10/21 17:09:57
本文主要是介绍Python实现哈夫变换,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import numpy as np import cv2 def Read_raw(filename,w,h,m): #初始化image image=[] for i in range(m*h): image.append([]) for j in range(w): image[i].append(255) #读取raw with open(filename,'rb') as f: data=f.read() #写入raw for i in range(m*h): for j in range(w): image[i][j]=data[i*w+j] print('读取文件{0}成功'.format(filename)) return image def Write_raw(filename,image): #将数组image转为bytes bt=bytearray() for i in range(len(image)): for j in range(len(image[i])): bt.append(image[i][j]) #写入raw with open(filename,'wb') as f: f.write(bt) f.close() print('写入文件{0}成功'.format(filename)) def Hough(x,y): all_b=[] for t in range(180): temp_theta=np.pi/(t+1) all_b.append(0) for i in range(1): temp_b=y[i]-np.tan(temp_theta)*x[i] ''' print('b=',temp_b) print('k=',round(np.tan(temp_theta),2)) print('x=',x[i],'y=',y[i]) ''' def threshold(filename): im=cv2.imread(filename,0) im=cv2.GaussianBlur(im,(5,5),0) canny=cv2.Canny(im,50,150) temp_x=[] temp_y=[] for i in range(len(canny)): for j in range(len(canny[i])): if canny[i][j]==255: temp_x.append(i) temp_y.append(j) return temp_x,temp_y x,y=threshold('lena1.jpg') Hough(x,y) |
这篇关于Python实现哈夫变换的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
原文链接: https://blog.csdn.net/qq_44924355/article/details/120889345
- 2025-01-13python项目部署
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门