opencv笔记

1.读取图片
imge = cv2.imread(IMAGE_PATH)

2.转灰度图
gray = cv2.cvtColor(imge, cv2.COLOR_BGR2GRAY)

3.图像缩放
 image = cv2.resize(image, (400, int(400 * image.shape[0] / image.shape[1])))

4.高期模糊
gray = cv2.GaussianBlur(gray, (5, 5), 0)

5.局部自适应阀值二值化
binary = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 101, 0)

6.轮廓检测
contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

7.轮廓边长
arc_length = cv2.arcLength(contour, True)

8.轮廓最小包围框
rect = cv2.minAreaRect(contour)

9.轮廓面积
 area = cv2.contourArea(contour)

10.在图上画轮廓
cv2.drawContours(img, good_contours, -1, (0, 0, 255), 4)

11.角点检测
corners = cv2.goodFeaturesToTrack(gray, 10000, 0.05, 10, blockSize=5, useHarrisDetector=False, k=0.04)

12.角点亚像素处理
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 40, 0.001)
cv2.cornerSubPix(gray, corners, (5, 5), (-1, 1), criteria)

13.在图上画角点
for epoch in range(len(corners)):
    cv2.circle(img, (corners[epoch][0][0], corners[epoch][0][1]), 3, (0, 255, 255), -1)

14.边缘检测
image = cv2.GaussianBlur(image, (5, 5), 0)
edges = cv2.Canny(image, 100, 200)

15、dnn运行神经网络模型
model = cv2.dnn.readNetFromONNX(ONNX_MODEL_SAVE_PATH)
blob = cv2.dnn.blobFromImage(image,
                             scalefactor=1,
                             size=(28, 28),
                             mean=[0, 0, 0],
                             swapRB=False,
                             ddepth=cv2.CV_32F,
                             crop=False)
model.setInput(blob)
out = model.forward()
st_out = softmax(out, axis=1)

16、SIFT特征
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT().create(nfeatures=1000)
kp1, des1 = sift.detectAndCompute(gray1, None)

17、找到两个平面之间的转换矩阵
H,mask = cv2.findHomography(src_pts,dst_pts,cv2.RANSAC,5.0)

18、透视变换,将图片投影到一个新的视平面
dst = cv2.perspectiveTransform(pts, H)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值