Rich's Wordpress

又一个WordPress站点

OpenCV 14: Gradients

The gradients are edge-like regions that are present in the image. It is similar to edge detection.

import cv2 as cv
import numpy as np

img = cv.imread('/Users/richzha/Desktop/CV/Image/Cat3.jpg')
cv.imshow('Cat', img)

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)

Laplacian

# Laplacian
lap = cv.Laplacian(gray, ddepth=cv.CV_64F)
lap = np.uint8(np.absolute(lap))
cv.imshow('Laplacian', lap)

Sobel

# Sobel
sobelx = cv.Sobel(gray, cv.CV_64F, 1, 0)
sobely = cv.Sobel(gray, cv.CV_64F, 0, 1)
cv.imshow('Sobel X', sobelx)
cv.imshow('Sobel Y', sobely)

combined_sobel = cv.bitwise_or(sobelx,sobely)
cv.imshow('Combined Sobel', combined_sobel)

Canny

# Canny Edge
canny = cv.Canny(gray, 150, 175)
cv.imshow('Canny', canny)

cv.waitKey(0)
OpenCV 14: Gradients

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top