-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
73 lines (57 loc) · 1.58 KB
/
test.py
File metadata and controls
73 lines (57 loc) · 1.58 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
import cv2
import os
image1 = r'C:\Users\ITRIUser\Desktop\Untitled.png'
image2 = r'C:\Users\ITRIUser\Desktop\Untitled2.png'
image3 = r'C:\Users\ITRIUser\Desktop\Untitled3.jpg'
background_path = 'raw_background.jpg'
bg = cv2.imread(background_path)
I0 = cv2.imread(image1)
I1 = cv2.imread(image2)
I2 = cv2.imread(image3)
IG0 = cv2.cvtColor(I0, cv2.COLOR_BGR2GRAY)
IG1 = cv2.cvtColor(I1, cv2.COLOR_BGR2GRAY)
IG2 = cv2.cvtColor(I2, cv2.COLOR_BGR2GRAY)
bgg = cv2.cvtColor(bg, cv2.COLOR_BGR2GRAY)
BI = (IG0 - IG1)
thresh = 50
im_bw = cv2.threshold(BI, thresh, 255, cv2.THRESH_BINARY)[1]
im_bw2 = cv2.bitwise_not(im_bw)
final = cv2.medianBlur(im_bw, 3)
cv2.imshow('name', final)
cv2.waitKey(0)
"""
import numpy as np
import cv2 as cv
org = cv.imread('raw_background.jpg', 0)
mask = cv.imread('test1.jpg', 0)
if org is None:
print("Error: Unable to load raw_background.jpg")
exit()
if mask is None:
print("Error: Unable to load test1.jpg")
exit()
if org.shape != mask.shape:
print("Error: The images must be the same size for bitwise operations.")
exit()
org = IG1
mask = IG2
current = org.copy()
tracker = 0
while True:
cv.imshow('org', current)
k = cv.waitKey(0)
if k == ord('c'):
if tracker == 0:
current = cv.bitwise_xor(org, mask)
tracker += 1
elif tracker == 1:
current = cv.threshold(current, thresh, 255, cv2.THRESH_BINARY)[1]
tracker = 2
elif tracker == 2:
current = org.copy()
tracker = 0
if k == 27:
break
cv.destroyAllWindows()
"""