File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Import necessary libraries
2
+
3
+ import cv2
4
+ import numpy as np
5
+ import imutils
6
+
7
+ # Define your Brocade class
8
+ class Brocade :
9
+
10
+ def __init__ (self , imageName ):
11
+ self ._img = cv2 .imread (imageName , cv2 .IMREAD_COLOR )
12
+ self ._img = imutils .resize (self ._img , 600 )
13
+ self ._grayimg = cv2 .cvtColor (self ._img , cv2 .COLOR_BGR2GRAY )
14
+
15
+ # Kernel to Brocade the image
16
+ self ._kernel3 = np .array ([[- 2 , - 1 , 0 ],
17
+ [- 1 , 1 , 1 ],
18
+ [0 , 1 , 2 ]], dtype = np .float64 )
19
+
20
+ def getOrigImg (self ):
21
+ return self ._img
22
+ def getGrayImg (self ):
23
+ return self ._grayimg
24
+
25
+ # Member function to apply kernel on Filter of CV
26
+ def applyFilter (self ):
27
+ img = self ._img .copy ()
28
+ filtered = cv2 .filter2D (img , - 1 , self ._kernel3 )
29
+
30
+ return filtered
31
+
32
+
33
+ # Now real work :> !
34
+ if __name__ == "__main__" :
35
+
36
+ B = Brocade ("naruto.jpg" )
37
+ img = B .getOrigImg ()
38
+ grayimg = B .getGrayImg ()
39
+ filtered = B .applyFilter () # filter2D uses Correlation
40
+
41
+ res = np .hstack ((img , filtered )) # Join Original and filtered image
42
+
43
+ cv2 .imshow ("Result" , res )
44
+ cv2 .waitKey (0 )
45
+ cv2 .destroyAllWindows ()
You can’t perform that action at this time.
0 commit comments