霍夫圆检测
API接口
circles=cv.HoughCircles(mdian,cv.HOUGH_GRADIENT,1,50,param1=n,param2=30,minRadius=50,maxRadius=120)
图片 要用什么算法 分辨率 圆和圆的距离 canny边界检测的上界 多少点在圆上才取 半径最小最大值
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
path=r"F:\xingtai.jfif"
img=cv.imread(path)
rows,cols=img.shape[:2]
cv.imshow("1",img)
gray=cv.cvtColor(img,cv.COLOR_BGRA2GRAY)
cla=cv.createCLAHE(clipLimit=4.0,tileGridSize=(8,8))
gray1=cla.apply(gray)
n=400
mdian=cv.medianBlur(gray1,5)
canny=cv.Canny(mdian,n/2,n)
circles=cv.HoughCircles(mdian,cv.HOUGH_GRADIENT,1,50,param1=n,param2=30,minRadius=50,maxRadius=120)
for i in circles[0,:]:
cv.circle(img,(int(i[0]),int(i[1])),int(i[2]),(0,255,0),2)
cv.imshow("1",img)
cv.waitKey(0)
cv.destroyAllWindows()
角点检测1:
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
path=r"F:\kaibi.png"
img=cv.imread(path)
rows,cols=img.shape[:2]
cv.imshow("1",img)
gray=cv.cvtColor(img,cv.COLOR_BGRA2GRAY)
gray=np.float32(gray)
dst=cv.cornerHarris(gray,2,3,0.04,)
dst = cv.dilate(dst, None)
img[dst>0.000001*dst.max()]=[0,0,255]
cv.imshow("1",img)
cv.waitKey(0)
cv.destroyAllWindows()
角点测shi-tomas检测
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
path=r"F:\kaibi.png"
img=cv.imread(path)
rows,cols=img.shape[:2]
cv.imshow("1",img)
gray=cv.cvtColor(img,cv.COLOR_BGRA2GRAY)
corners=cv.goodFeaturesToTrack(gray,1000,0.01,10)
for i in corners:
x,y=i.ravel()
cv.circle(img,(int(x),int(y)),2,(0,0,255),-1)
cv.imshow("1",img)
cv.waitKey(0)
cv.destroyAllWindows()
角点数量最大值,质量,角点之间的距离
SIFT算法检测特征点 (SURF用不了 python版本高了)
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
path=r"F:\chenhao.jpg"
img=cv.imread(path)
rows,cols=img.shape[:2]
cv.imshow("1",img)
gray=cv.cvtColor(img,cv.COLOR_BGRA2GRAY)
sift=cv.xfeatures2d.SIFT_create()
kp,des=sift.detectAndCompute(gray,None)
cv.drawKeypoints(img,kp,img,flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv.imshow("1",img)
cv.waitKey(0)
cv.destroyAllWindows()
ORB算法检测特征点
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
path=r"F:\chenhao.jpg"
img=cv.imread(path)
rows,cols=img.shape[:2]
cv.imshow("1",img)
orb=cv.ORB_create(nfeatures=5000)
kp,des=orb.detectAndCompute(img,None)
img2=cv.drawKeypoints(img,kp,None,flags=0)
cv.imshow("1",img2)
cv.waitKey(0)
cv.destroyAllWindows()
fast算法检测特征点
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
path=r"F:\chenhao.jpg"
img=cv.imread(path)
rows,cols=img.shape[:2]
cv.imshow("1",img)
fast=cv.FastFeatureDetector_create(threshold=30)
kp=fast.detect(img,None)
img2=cv.drawKeypoints(img,kp,None,color=(255,0,0))
cv.imshow("1",img2)
cv.waitKey(0)
cv.destroyAllWindows()
阈值是和周围灰度值的差值阈值