import cv2 import matplotlib.pylab as plt import numpy as np img1 = cv2.imread('D:\\gudugudu\\Pictures\\weixin\\xiaotidaya.jpg', cv2.IMREAD_ANYCOLOR) img2 = cv2.imread('D:\\gudugudu\\Pictures\\weixin\\guoqing.jpg', cv2.IMREAD_GRAYSCALE) img3 = cv2.imread('D:\\gudugudu\\Pictures\\weixin\\zhaoyang.jpg', cv2.IMREAD_GRAYSCALE) img_x = cv2.resize(img1, (500, 500)) img_y = cv2.resize(img2, (500, 500)) img_z = cv2.resize(img3, (500, 500)) vc = cv2.VideoCapture("D:\\gudugudu\\Pictures\\weixin\\WeChat_20240706150425.mp4") #梯度计算 #Soble算子 det = cv2.Soble(src, drpth, dx, dy, ksize);上下,左右的差异 #计算方法: 右-左*系数, 上-下*系数; def soble(img): soblex = cv2.Soble(img, cv2.CV_64F, 1, 0, ksize = 3) soblex = cv2.convertScaleAbs(soblex) cv2.imshow('name', soblex) cv2.waitKey(0) cv2.destroyAllWindows() #分别计算xy再求和; def Soblexy(img): soblex = cv2.Soble(img, cv2.CV_64F, 1, 0, ksize = 3) sobley = cv2.Soble(img, cv2.CV_64F, 0, 1, ksize = 3) soblexy = cv2.addWeighted(soblex, 0.5, sobley, 0.5, 0) cv2.imshow('name', soblexy) cv2.waitKey(0) cv2.destroyAllWindows() #scharr算子: 数值大一些,结果的差异更加敏感 #laplacian算子: 对于差异更加敏感, 但是对于噪点的判断有误 def scharr(img): scharrx = cv2.Scharr(img, cv2.CV_64F, 1, 0) scharry = cv2.Scharr(img, cv2.CV_64F, 0, 1) scharrx = cv2.convertScaleAbs(scharrx) scharry = cv2.convertScaleAbs(scharry) scharrxy = cv2.addWeighted(scharrx, 0.5, scharry, 0.5, 0) cv2.imshow('name', scharrxy) cv2.waitKey(0) cv2.destroyAllWindows() def LapLacion(img): laplacion = cv2.Laplacian(img, cv2.CV_64F) laplacion = cv2.convertScaleAbs(laplacion) cv2.imshow('name', laplacion) cv2.waitKey(0) cv2.destroyAllWindows()
opencv_day6
最新推荐文章于 2024-09-10 17:00:42 发布