python-tensorflow-opencv《计算机视觉的深度学习实践》代码笔记_第1页
python-tensorflow-opencv《计算机视觉的深度学习实践》代码笔记_第2页
python-tensorflow-opencv《计算机视觉的深度学习实践》代码笔记_第3页
python-tensorflow-opencv《计算机视觉的深度学习实践》代码笔记_第4页
python-tensorflow-opencv《计算机视觉的深度学习实践》代码笔记_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ython-tensorflow-opencv计算机视觉的深度学习实践代码笔记python-tensorflow-opencv计算机视觉的深度学习实践代码笔记01 课程概述tf_test:# 创建2个矩阵,前者12列,后者21列,然后矩阵相乘:matrix1 =tf.constant(3,3)# 上边的操作是定义图,然后会话Session去计算:with tf.Session() as sess:print(- )print(matrix1)Tensor(Const_2:0, shape(1, 2), dtypeint32)opencv_test:import cv2 as cv#释放窗cv.

2、destroyAllWindows()02图像预处理f1.py程序:import cv2img =cv2.imread(D:/pictures/opencv.png,0) #直接读为灰度图像for i in range(2000): #添加点噪声blur_1 =cv2.GaussianBlur(img,(5,5),0)blur_2 =cv2.medianBlur(img,5)plt.subplot(1,3,1),plt.imshow(img,gray),plt.title(img)#默认彩,另种彩bgrplt.subplot(1,3,2),plt.imshow(blur_1,gray),plt

3、.title(blur1)plt.subplot(1,3,3),plt.imshow(blur_2,gray),plt.title(blur2)plt.show()f1.py结果:f2.py程序:import cv2 as cvfrom matplotlib import pyplot as pltimg =cv.imread(D:/pictures/dave.png,0)plt.subplot(2,2,4),plt.imshow(sobely,cmap =gray)plt.title(Sobel Y), plt.xticks(), plt.yticks()plt.show()f2.py结果:

4、fft.py程序:import cv2 as cvplt.subplot(121),plt.imshow(img, cmap =gray)plt.title(Input Image), plt.xticks(), plt.yticks()plt.subplot(122),plt.imshow(magnitude_spectrum, cmap =gray)plt.title(Magnitude Spectrum), plt.xticks(), plt.yticks()plt.show()fft.py结果:clahe.py程序:import cv2import matplotlib.pyplot

5、as pltimg =cv2.imread(D:/pictures/timg.jpg,0) #直接读为灰度图像res =cv2.equalizeHist(img)#直接直图均衡化clahe =cv2.createCLAHE(clipLimit2,tileGridSize(10,10)cl1 =clahe.apply(img)# 限制对度适应直图均衡plt.show()clahe.py结果:filter_1.ipynb程序:kernel =np.ones(5,5),np.float32)/25dst =cv.filter2D(img,-1,kernel)plt.show()kernelfilte

6、r_1.ipynb结果:array(0.04, 0.04, 0.04, 0.04, 0.04,0.04, 0.04, 0.04, 0.04, 0.04,0.04, 0.04, 0.04, 0.04, 0.04,0.04, 0.04, 0.04, 0.04, 0.04,0.04, 0.04, 0.04, 0.04, 0.04, dtype=float32)03图像特征与描述imagestiching.py程序:def stitch(self, images, ratio0.75, reprojThresh4.0,showMatchesFalse):#获取输图# 匹配两张图的所有特征点,返回匹配结

7、果# 如果返回结果为空,没有匹配成功的特征点,退出算法if M is None:return None# 否则,提取匹配结果# 将图进视变换,result是变换后图result =cv2.warpPerspective(imageA, H, (imageA.shape1 +imageB.shape1, imageA.shape0)# 将图传result图最左端# 检测是否需要显图匹配# 成匹配图vis =self.drawMatches(imageA, imageB, kpsA, kpsB, matches, status)# 返回结果return (result, vis)# 返回匹配结果r

8、eturn resultdef detectAndDescribe(self, image):# 将彩图转换成灰度图gray =cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)descriptor =cv2.xfeatures2d.SIFT_create()# 检测SIFT特征点,并计算描述(kps, features) =descriptor.detectAndCompute(image, None)# 将结果转换成NumPy数组kps =np.float32(kp.pt for kp in kps)# 返回特征点集,及对应的描述特征return (kps, f

9、eatures)def matchKeypoints(self, kpsA, kpsB, featuresA, featuresB, ratio, reprojThresh):# 建暴匹配器matcher =cv2.DescriptorMatcher_create (BruteForce)# 使检测来图的SIFT特征匹配对,K=2rawMatches =matcher.knnMatch(featuresA, featuresB, 2)# 当最近距离跟次近距离的值于ratio值时,保留此匹配对if len(m) =2 and m0.distance m1.distance *ratio:# 存储

10、两个点在featuresA, featuresB中的索引值matches.append(m0.trainIdx, m0.queryIdx)# 当筛选后的匹配对于4时,计算视变换矩阵# 获取匹配对的点坐标# 计算视变换矩阵# 返回结果# 如果匹配对于4时,返回None# 联合遍历,画出匹配对for (trainIdx, queryIdx), s) in zip(matches, status):# 当点对匹配成功时,画到可视化图上if s =1:# 画出匹配对return vis# 读取拼接图# 把图拼接成全景图stitcher =Stitcher()(result, vis) =stitche

11、r.stitch(imageA, imageB, showMatchesTrue)# 显所有图cv2.destroyAllWindows()imagestiching.py结果:harris_corner.py程序:import numpy as npimport cv2 as cvfilename =./chessboard.pngimg =cv.imread(filename)cv.imwrite(D:/dst.jpg,img)if cv.waitKey(0) &0 xff =27:cv.destroyAllWindows()harris_corner.py结果:surf.py程序:imp

12、ort numpy as npimport cv2 as cvimg =cv.imread(./butterfly.jpg,0)surf =cv.xfeatures2d.SURF_create(400)surf.setHessianThreshold(50000)kp, des =surf.detectAndCompute(img,None)cv.waitKey(0)cv.destroyAllWindows()surf.py结果:sift.py程序:import cv2 as cvimgcv.drawKeypoints(gray,kp,img)cv.destroyAllWindows()sif

13、t.py结果:orb.py程序:import cv2 as cvimg3 =cv.drawMatches(img1,kp1,img2,kp2,matches:20,None, flags2)plt.imshow(img3),plt.show()orb.py结果:laplacian_sharpen.py程序:# 为了减少计算的维度,因此将图像转为灰度图img_gray =img.convert(L)# 得到转换后灰度图的像素矩阵img_arr =np.array(img_gray)h =img_arr.shape0 # w =img_arr.shape1 # 列# 拉普拉斯算锐化图像,阶微分new_img_arr =np.zeros(h, w) # 拉普拉斯锐化后的图像像素矩阵for i in range(2, h-1):laplace_img_arr =np.zeros(h, w)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论