Skip to content

Commit fa8c01f

Browse files
committed
add opencv_tracker python file
1 parent 81cca0f commit fa8c01f

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

‎bitwise_operation_opencv.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import cv2
2+
import numpy as np
3+
4+
# height width channls
5+
img1 = np.zeros((250,500,3) , np.uint8)
6+
img1 = cv2.rectangle(img1,(200,0),(300,100) , (255,255,255) , -1)
7+
img2 = cv2.imread('messi5.jpg')
8+
9+
cv2.imshow('Main image1' , img1)
10+
cv2.imshow('Main image2' , img2)
11+
12+
img2 = cv2.resize(img2 ,(500,250)) # width height
13+
print(img1.shape)
14+
print(img2.shape)
15+
16+
# Bitwise Operations #
17+
18+
bitAnd = cv2.bitwise_and(img1 , img2)
19+
bitOr = cv2.bitwise_or(img1 , img2)
20+
bitXor = cv2.bitwise_xor(img1 , img2)
21+
bitnot1 = cv2.bitwise_not(img1)
22+
bitnot2 = cv2.bitwise_not(img2)
23+
24+
# cv2.imshow('bitAnd' , bitAnd)
25+
# cv2.imshow('bitOr' , bitOr)
26+
# cv2.imshow('bitXor' , bitXor)
27+
# cv2.imshow('bitnot1' , bitnot1)
28+
# cv2.imshow('bitnot2' , bitnot2)
29+
30+
cv2.waitKey(0)
31+
cv2.destroyAllWindows()

‎opencv_trackbar.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import cv2
2+
import numpy as np
3+
4+
def nothing(x):
5+
print(x)
6+
7+
img = np.zeros((300,512,3) , np.uint8)
8+
cv2.namedWindow('image')
9+
10+
cv2.createTrackbar('B', 'image' , 0 , 255 , nothing)
11+
cv2.createTrackbar('G', 'image' , 0 , 255 , nothing)
12+
cv2.createTrackbar('R', 'image' , 0 , 255 , nothing)
13+
14+
switches = '0 : OFF\n 1 : ON'
15+
cv2.createTrackbar(switches, 'image' , 0 , 1 , nothing)
16+
17+
18+
while True:
19+
cv2.imshow('image' , img)
20+
k = cv2.waitKey(1) & 0xFF
21+
if k == 27:
22+
break
23+
24+
b = cv2.getTrackbarPos('B','image')
25+
g = cv2.getTrackbarPos('G','image')
26+
r = cv2.getTrackbarPos('R','image')
27+
switch = cv2.getTrackbarPos(switches,'image')
28+
29+
if switch == 1:
30+
img[:] = [b,g,r]
31+
else:
32+
pass
33+
34+
35+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)