-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsobel_prewitt_opencv.py
49 lines (37 loc) · 1.46 KB
/
sobel_prewitt_opencv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import cv2 as cv
def main(argv):
window_name = ('Sobel Demo - Simple Edge Detector')
scale = 1
delta = 0
ddepth = cv.CV_16S
if len(argv) < 1:
print('Not enough parameters')
print('Usage:\nmorph_lines_detection.py < path_to_image >')
return -1
# Load the image
src = cv.imread(argv, cv.IMREAD_COLOR)
# Check if image is loaded fine
if src is None:
print('Error opening image: ' + argv[0])
return -1
src = cv.GaussianBlur(src, (3, 3), 0)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
grad_x = cv.Sobel(gray, ddepth, 1, 0, ksize=3, scale=scale, delta=delta, borderType=cv.BORDER_DEFAULT)
grad_y = cv.Sobel(gray, ddepth, 0, 1, ksize=3, scale=scale, delta=delta, borderType=cv.BORDER_DEFAULT)
grad_x5= cv.Sobel(gray, ddepth, 1, 0, ksize=5, scale=scale, delta=delta, borderType=cv.BORDER_DEFAULT)
grad_y5 = cv.Sobel(gray, ddepth, 0, 1, ksize=5, scale=scale, delta=delta, borderType=cv.BORDER_DEFAULT)
abs_grad_x = cv.convertScaleAbs(grad_x)
abs_grad_y = cv.convertScaleAbs(grad_y)
abs_grad_x5 = cv.convertScaleAbs(grad_x5)
abs_grad_y5 = cv.convertScaleAbs(grad_y5)
grad = cv.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
grad5 = cv.addWeighted(abs_grad_x5, 0.5, abs_grad_y5, 0.5, 0)
#3x3
cv.imshow(window_name, grad)
#5x5
#cv.imshow(window_name, grad5)
cv.waitKey(0)
return 0
if __name__ == "__main__":
main('deneme.jpg')