Skip to content

Commit 12891ad

Browse files
committed
This commit contain nine code examples of using deepstack AI sever.
1 parent eef189f commit 12891ad

16 files changed

+3833
-1
lines changed

README.md

Lines changed: 1654 additions & 1 deletion
Large diffs are not rendered by default.

python/.ipynb_checkpoints/Readme-checkpoint.ipynb

Lines changed: 1686 additions & 0 deletions
Large diffs are not rendered by default.

python/.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.linting.pylintEnabled": true
3+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
import cv2
3+
import requests
4+
5+
cap = cv2.VideoCapture(0)
6+
7+
progress_tracker = 0
8+
prediction_json = {}
9+
skip_frame = 20
10+
while(cap.isOpened()):
11+
valid, frame = cap.read()
12+
13+
14+
if valid == True:
15+
progress_tracker += 1
16+
17+
if(progress_tracker % skip_frame == 0):
18+
retval, new_frame = cv2.imencode('.jpg', frame)
19+
response = requests.post("http://localhost:80/v1/vision/face",
20+
files={"image":new_frame}).json()
21+
prediction_json = response['predictions']
22+
print(prediction_json)
23+
24+
num_prediction_json = len(prediction_json)
25+
for i in range(num_prediction_json):
26+
red, green, blue = 200, 100, 200
27+
frame = cv2.rectangle(frame, (prediction_json[i]['x_min'], prediction_json[i]['y_min']),
28+
(prediction_json[i]['x_max'], prediction_json[i]['y_max']), (red, green, blue), 1)
29+
30+
31+
cv2.imshow('Image Viewer', frame)
32+
33+
if cv2.waitKey(1) & 0xFF == ord('q'):
34+
break
35+
36+
else:
37+
break
38+
39+
cap.release()
40+
cv2.destroyAllWindows()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
import cv2
3+
import requests
4+
5+
cap = cv2.VideoCapture(0)
6+
out = cv2.VideoWriter("face_detection_from_camera_to_file.avi", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
7+
,24,((int(cap.get(3)), int(cap.get(4)))))
8+
9+
progress_tracker = 0
10+
prediction_json = {}
11+
skip_frame = 20
12+
print('<============================= Press contrl + c to break ===============================>')
13+
14+
while(cap.isOpened()):
15+
valid, frame = cap.read()
16+
17+
18+
if valid == True:
19+
progress_tracker += 1
20+
21+
if(progress_tracker % skip_frame == 0):
22+
retval, new_frame = cv2.imencode('.jpg', frame)
23+
response = requests.post("http://localhost:80/v1/vision/face",
24+
files={"image":new_frame}).json()
25+
prediction_json = response['predictions']
26+
print(prediction_json)
27+
28+
num_prediction_json = len(prediction_json)
29+
for i in range(num_prediction_json):
30+
red, green, blue = 100, 50, 200
31+
frame = cv2.rectangle(frame, (prediction_json[i]['x_min'], prediction_json[i]['y_min']),
32+
(prediction_json[i]['x_max'], prediction_json[i]['y_max']), (red, green, blue), 1)
33+
out.write(frame)
34+
35+
else:
36+
break
37+
38+
39+
cap.release()
40+
out.release()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
import cv2
3+
import requests
4+
5+
6+
cap = cv2.VideoCapture('furious.mp4')
7+
8+
progress_tracker = 0
9+
prediction_json = {}
10+
skip_frame = 20
11+
12+
while(cap.isOpened()):
13+
valid, frame = cap.read()
14+
15+
16+
if valid == True:
17+
progress_tracker += 1
18+
19+
if(progress_tracker % skip_frame == 0):
20+
retval, new_frame = cv2.imencode('.jpg', frame)
21+
response = requests.post("http://localhost:80/v1/vision/face",
22+
files={"image":new_frame}).json()
23+
prediction_json = response['predictions']
24+
print(prediction_json)
25+
26+
num_prediction_json = len(prediction_json)
27+
for i in range(num_prediction_json):
28+
red, green, blue = 100, 50, 200
29+
frame = cv2.rectangle(frame, (prediction_json[i]['x_min'], prediction_json[i]['y_min']),
30+
(prediction_json[i]['x_max'], prediction_json[i]['y_max']), (red, green, blue), 1)
31+
32+
33+
cv2.imshow('Image Viewer', frame)
34+
35+
if cv2.waitKey(1) & 0xFF == ord('q'):
36+
break
37+
38+
else:
39+
break
40+
41+
cap.release()
42+
cv2.destroyAllWindows()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
import cv2
3+
import requests
4+
5+
cap = cv2.VideoCapture('furious.mp4')
6+
out = cv2.VideoWriter("face_detection_from_video_to_file.avi", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'),
7+
24,((int(cap.get(3)), int(cap.get(4)))))
8+
9+
progress_tracker = 0
10+
prediction_json = {}
11+
skip_frame = 20
12+
13+
while(cap.isOpened()):
14+
valid, frame = cap.read()
15+
16+
17+
if valid == True:
18+
progress_tracker += 1
19+
20+
if(progress_tracker % skip_frame == 0):
21+
retval, new_frame = cv2.imencode('.jpg', frame)
22+
response = requests.post("http://localhost:80/v1/vision/face",
23+
files={"image":new_frame}).json()
24+
prediction_json = response['predictions']
25+
print(prediction_json)
26+
27+
num_prediction_json = len(prediction_json)
28+
for i in range(num_prediction_json):
29+
red, green, blue = 100, 50, 200
30+
frame = cv2.rectangle(frame, (prediction_json[i]['x_min'], prediction_json[i]['y_min']),
31+
(prediction_json[i]['x_max'], prediction_json[i]['y_max']), (red, green, blue), 1)
32+
out.write(frame)
33+
34+
else:
35+
break
36+
37+
print('<==============Video file as been full written with face bounding boxes============>')
38+
39+
cap.release()
40+
out.release()

python/furious.mp4

12.4 MB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import numpy as np
2+
import cv2
3+
import requests
4+
5+
cap = cv2.VideoCapture(0)
6+
7+
progress_tracker = 0
8+
prediction_json = {}
9+
skip_frame = 20
10+
while(cap.isOpened()):
11+
valid, frame = cap.read()
12+
13+
14+
if valid == True:
15+
progress_tracker += 1
16+
17+
if(progress_tracker % skip_frame == 0):
18+
retval, new_frame = cv2.imencode('.jpg', frame)
19+
response = requests.post("http://localhost:80/v1/vision/detection",
20+
files={"image":new_frame}).json()
21+
prediction_json = response['predictions']
22+
print(prediction_json)
23+
24+
num_prediction_json = len(prediction_json)
25+
for i in range(num_prediction_json):
26+
27+
color_space_values = np.random.randint(50, 255, size=(3,))
28+
red, green, blue = color_space_values
29+
red, green, blue = int(red), int(green), int(blue)
30+
31+
frame = cv2.rectangle(frame, (prediction_json[i]['x_min'], prediction_json[i]['y_min']),
32+
(prediction_json[i]['x_max'], prediction_json[i]['y_max']), (red, green, blue), 1)
33+
34+
35+
cv2.imshow('Image Viewer', frame)
36+
37+
if cv2.waitKey(1) & 0xFF == ord('q'):
38+
break
39+
40+
else:
41+
break
42+
43+
cap.release()
44+
cv2.destroyAllWindows()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import numpy as np
2+
import cv2
3+
import requests
4+
5+
cap = cv2.VideoCapture(0)
6+
out = cv2.VideoWriter("object_detection_from_camera_to_file.avi", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
7+
,24,((int(cap.get(3)), int(cap.get(4)))))
8+
9+
progress_tracker = 0
10+
prediction_json = {}
11+
skip_frame = 20
12+
print('<============================= Press contrl + c to break ===============================>')
13+
14+
while(cap.isOpened()):
15+
valid, frame = cap.read()
16+
17+
18+
if valid == True:
19+
progress_tracker += 1
20+
21+
if(progress_tracker % skip_frame == 0):
22+
retval, new_frame = cv2.imencode('.jpg', frame)
23+
response = requests.post("http://localhost:80/v1/vision/detection",
24+
files={"image":new_frame}).json()
25+
prediction_json = response['predictions']
26+
print(prediction_json)
27+
28+
num_prediction_json = len(prediction_json)
29+
for i in range(num_prediction_json):
30+
31+
color_space_values = np.random.randint(50, 255, size=(3,))
32+
red, green, blue = color_space_values
33+
red, green, blue = int(red), int(green), int(blue)
34+
35+
frame = cv2.rectangle(frame, (prediction_json[i]['x_min'], prediction_json[i]['y_min']),
36+
(prediction_json[i]['x_max'], prediction_json[i]['y_max']), (red, green, blue), 1)
37+
out.write(frame)
38+
39+
else:
40+
break
41+
42+
43+
cap.release()
44+
out.release()

0 commit comments

Comments
 (0)