基于Anaconda(python)的图像投影变换
一、安装和配置Anacond3
1.安装Anacond3,安装vscode,jupyter notebook等软件;
2.配置环境
pip install numpy
pip install matplotlib
pip install opencv-python
二、基于图像的逆透视变换完成目标的倾斜纠正,在vscode里用python编程完成。
1.基于透视的图像矫正(自动获取图像顶点变换)
以灰度图读入
腐蚀膨胀,闭合等操作
二值化图像
获取图像顶点
透视矫正
直接获取图像轮廓矫正
from imutils.perspective import four_point_transform
import imutils
import cv2
def Get_Outline(input_dir):
image = cv2.imread(input_dir)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5,5),0)
edged = cv2.Canny(blurred,75,200)
return image,gray,edged
def Get_cnt(edged):
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
docCnt =None
if len(cnts) > 0:
cnts =sorted(cnts,key=cv2.contourArea,reverse=True)
for c in cnts:
peri = cv2.arcLength(c,True) # 轮廓按大小降序排序
approx = cv2.approxPol