-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (44 loc) · 1.94 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
import cv2
import numpy as np
video = cv2.VideoCapture("RollingCan.mov")
result = cv2.VideoWriter('Output.mp4', cv2.VideoWriter_fourcc(*"mp4v"), 20.0, (3840, 1080))
detectedFrames = 0
if not video.isOpened():
print("Error opening video file")
while video.isOpened():
ret1, frameOut = video.read()
ret2, frameIn = video.read()
totalFrames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
if 1 and ret2:
frameGray = cv2.medianBlur(frameOut, 5)
frameGray = cv2.cvtColor(frameGray, cv2.COLOR_BGR2GRAY)
rows = frameGray.shape[0]
circles = cv2.HoughCircles(frameGray, cv2.HOUGH_GRADIENT, 1, 100000000, param1 = 150, param2 = 15, minRadius = 80, maxRadius = 90)
if circles is not None:
detectedFrames += 1
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
center = (i[0], i[1])
# circle center
cv2.circle(frameOut, center, 10, (0, 0, 0), -1)
# circle outline
radius = i[2]
cv2.circle(frameOut, center, radius, (0, 255, 0), 3)
frameOut = cv2.putText(frameOut, "{}/{} frames detected".format(detectedFrames, totalFrames), (600, 300), cv2.FONT_HERSHEY_SCRIPT_COMPLEX, 3, (0, 0, 0), 2, cv2.LINE_AA)
frameOut = cv2.putText(frameOut, "Output", (900, 100), cv2.FONT_HERSHEY_SCRIPT_COMPLEX, 3, (0, 0, 0), 2,
cv2.LINE_AA)
frameIn = cv2.putText(frameIn, "Input", (900, 100), cv2.FONT_HERSHEY_SCRIPT_COMPLEX, 3, (0, 0, 0), 2,
cv2.LINE_AA)
try:
combinedImage = np.concatenate((frameIn, frameOut), axis=1)
except ValueError:
break
result.write(combinedImage)
cv2.imshow("RollingCanProject", combinedImage)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
else:
break
video.release()
result.release()
cv2.destroyAllWindows()