-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py.html
53 lines (43 loc) · 2.83 KB
/
main.py.html
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
<html>
<head>
<title>main.py</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #cc7832;}
.s1 { color: #a9b7c6;}
.s2 { color: #808080;}
.s3 { color: #6897bb;}
.s4 { color: #6a8759;}
</style>
</head>
<body bgcolor="#2b2b2b">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
main.py</font>
</center></td></tr></table>
<pre><span class="s0">import </span><span class="s1">cv2</span>
<span class="s2"># Capture livestream video content from camera 0</span>
<span class="s1">cap = cv2.VideoCapture(</span><span class="s3">0</span><span class="s1">)</span>
<span class="s0">while </span><span class="s1">(</span><span class="s3">1</span><span class="s1">):</span>
<span class="s2"># Take each frame</span>
<span class="s1">_</span><span class="s0">, </span><span class="s1">frame = cap.read()</span>
<span class="s2"># Convert to HSV for simpler calculations</span>
<span class="s1">hsv = cv2.cvtColor(frame</span><span class="s0">, </span><span class="s1">cv2.COLOR_BGR2HSV)</span>
<span class="s2"># Calcution of Sobelx</span>
<span class="s1">sobelx = cv2.Sobel(frame</span><span class="s0">, </span><span class="s1">cv2.CV_64F</span><span class="s0">, </span><span class="s3">1</span><span class="s0">, </span><span class="s3">0</span><span class="s0">, </span><span class="s1">ksize=</span><span class="s3">5</span><span class="s1">)</span>
<span class="s2"># Calculation of Sobely</span>
<span class="s1">sobely = cv2.Sobel(frame</span><span class="s0">, </span><span class="s1">cv2.CV_64F</span><span class="s0">, </span><span class="s3">0</span><span class="s0">, </span><span class="s3">1</span><span class="s0">, </span><span class="s1">ksize=</span><span class="s3">5</span><span class="s1">)</span>
<span class="s2"># Calculation of Laplacian</span>
<span class="s1">laplacian = cv2.Laplacian(frame</span><span class="s0">, </span><span class="s1">cv2.CV_64F)</span>
<span class="s1">cv2.imshow(</span><span class="s4">'sobelx'</span><span class="s0">, </span><span class="s1">sobelx)</span>
<span class="s1">cv2.imshow(</span><span class="s4">'sobely'</span><span class="s0">, </span><span class="s1">sobely)</span>
<span class="s1">cv2.imshow(</span><span class="s4">'laplacian'</span><span class="s0">, </span><span class="s1">laplacian)</span>
<span class="s1">k = cv2.waitKey(</span><span class="s3">5</span><span class="s1">) & </span><span class="s3">0xFF</span>
<span class="s0">if </span><span class="s1">k == </span><span class="s3">27</span><span class="s1">:</span>
<span class="s0">break</span>
<span class="s1">cv2.destroyAllWindows()</span>
<span class="s2"># release the frame</span>
<span class="s1">cap.release()</span></pre>
</body>
</html>