Skip to content

Commit 0b1142c

Browse files
author
ChrisMaunder
committed
Updated to 1.6.5
1 parent 60239e9 commit 0b1142c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2214
-1641
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,4 @@ FodyWeavers.xsd
375375

376376
*.DS_Store
377377

378+
/demos/Python/Vision/detected

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
{
145145
"name": "Python 3.7/3.8: Current File",
146146
"type": "python",
147-
"python": "${workspaceFolder}/src/AnalysisLayer/bin/windows/python37/venv/bin/python",
147+
"python": "${workspaceFolder}/src/AnalysisLayer/bin/windows/python37/venv/Scripts/python",
148148
"request": "launch",
149149
"program": "${file}",
150150
"console": "integratedTerminal",

CodeProject.AI.sln

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D982BD8C
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demos", "demos", "{7F18EB64-C857-49C4-9380-70D3CCE6242B}"
1515
EndProject
16-
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Python", "demos\Python\Python.pyproj", "{25750BF1-1502-4F65-8D69-CEA8C87D6446}"
17-
EndProject
1816
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "API", "API", "{2379A486-0D28-4CAD-BB13-E77FBA538E0D}"
1917
EndProject
2018
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AnalysisLayer", "AnalysisLayer", "{156BFEDA-D477-43B2-92DA-FCC9BAF1F893}"
@@ -198,6 +196,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeProject.AI.API.Server.B
198196
EndProject
199197
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "ObjectDetectionYolo", "src\AnalysisLayer\ObjectDetectionYolo\ObjectDetectionYolo.pyproj", "{B6A1D372-264E-4F66-B7FB-7FF19587476F}"
200198
EndProject
199+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Python", "Python", "{37533562-EC4C-4FB4-8C42-FE327D1D79BD}"
200+
EndProject
201+
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Python", "demos\Python\Vision\Python.pyproj", "{25750BF1-1502-4F65-8D69-CEA8C87D6446}"
202+
EndProject
201203
Global
202204
GlobalSection(SolutionConfigurationPlatforms) = preSolution
203205
Debug|Any CPU = Debug|Any CPU
@@ -206,10 +208,6 @@ Global
206208
Release|x86 = Release|x86
207209
EndGlobalSection
208210
GlobalSection(ProjectConfigurationPlatforms) = postSolution
209-
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
210-
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Debug|x86.ActiveCfg = Debug|Any CPU
211-
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Release|Any CPU.ActiveCfg = Release|Any CPU
212-
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Release|x86.ActiveCfg = Release|Any CPU
213211
{C33D90E7-7570-46FB-9EB9-ED6B40A93A9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
214212
{C33D90E7-7570-46FB-9EB9-ED6B40A93A9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
215213
{C33D90E7-7570-46FB-9EB9-ED6B40A93A9B}.Debug|x86.ActiveCfg = Debug|Any CPU
@@ -310,12 +308,15 @@ Global
310308
{B6A1D372-264E-4F66-B7FB-7FF19587476F}.Debug|x86.ActiveCfg = Debug|Any CPU
311309
{B6A1D372-264E-4F66-B7FB-7FF19587476F}.Release|Any CPU.ActiveCfg = Release|Any CPU
312310
{B6A1D372-264E-4F66-B7FB-7FF19587476F}.Release|x86.ActiveCfg = Release|Any CPU
311+
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
312+
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Debug|x86.ActiveCfg = Debug|Any CPU
313+
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Release|Any CPU.ActiveCfg = Release|Any CPU
314+
{25750BF1-1502-4F65-8D69-CEA8C87D6446}.Release|x86.ActiveCfg = Release|Any CPU
313315
EndGlobalSection
314316
GlobalSection(SolutionProperties) = preSolution
315317
HideSolutionNode = FALSE
316318
EndGlobalSection
317319
GlobalSection(NestedProjects) = preSolution
318-
{25750BF1-1502-4F65-8D69-CEA8C87D6446} = {7F18EB64-C857-49C4-9380-70D3CCE6242B}
319320
{2379A486-0D28-4CAD-BB13-E77FBA538E0D} = {A8B76501-496A-4011-9C37-8308A1EBDFA7}
320321
{156BFEDA-D477-43B2-92DA-FCC9BAF1F893} = {A8B76501-496A-4011-9C37-8308A1EBDFA7}
321322
{3A860CDD-94B9-4002-BA08-87E8822DDE50} = {7F18EB64-C857-49C4-9380-70D3CCE6242B}
@@ -350,6 +351,8 @@ Global
350351
{25D75AFE-BEC9-43BF-BE44-B9068FF8E395} = {156BFEDA-D477-43B2-92DA-FCC9BAF1F893}
351352
{031F17E0-BE84-42AF-B9FE-4F928CB03D1B} = {D982BD8C-2257-413B-8513-8043AB3035F3}
352353
{B6A1D372-264E-4F66-B7FB-7FF19587476F} = {156BFEDA-D477-43B2-92DA-FCC9BAF1F893}
354+
{37533562-EC4C-4FB4-8C42-FE327D1D79BD} = {7F18EB64-C857-49C4-9380-70D3CCE6242B}
355+
{25750BF1-1502-4F65-8D69-CEA8C87D6446} = {37533562-EC4C-4FB4-8C42-FE327D1D79BD}
353356
EndGlobalSection
354357
GlobalSection(ExtensibilityGlobals) = postSolution
355358
SolutionGuid = {83740BD9-AEEF-49C7-A722-D7703D3A38CB}

Installers/Dev/clean.bat

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ goto:eof
167167
if /i "!dirMatched!" == "true" (
168168

169169
if /i "!doDebug!" == "true" (
170-
call %pwd%\utils.bat WriteLine "Marked for removal: !dirName!" !color_error!
170+
call %pwd%\utils.bat WriteLine "Marked for removal: !dirName!" "!color_error!"
171171
) else (
172172
rmdir /s /q "!dirName!";
173173

174174
if exist "!dirName!" (
175-
call %pwd%\utils.bat WriteLine "Unable to remove !dirName!" !color_error!
175+
call %pwd%\utils.bat WriteLine "Unable to remove !dirName!" "!color_error!"
176176
) else (
177-
call %pwd%\utils.bat WriteLine "Removed !dirName!" !color_success!
177+
call %pwd%\utils.bat WriteLine "Removed !dirName!" "!color_success!"
178178
)
179179
)
180180
) else (
181181
if /i "!doDebug!" == "true" (
182-
call %pwd%\utils.bat WriteLine "Not deleting !dirName!" !color_success!
182+
call %pwd%\utils.bat WriteLine "Not deleting !dirName!" "!color_success!"
183183
)
184184
)
185185
)
@@ -194,7 +194,7 @@ goto:eof
194194

195195
pushd "!BasePath!" >nul 2>nul
196196
if not "%errorlevel%" == "0" (
197-
call %pwd%\utils.bat WriteLine "Can't navigate to %cd%!BasePath!" "Red"
197+
call %pwd%\utils.bat WriteLine "Can't navigate to %cd%!BasePath! (but that's probably OK)" "!color_warn!"
198198
cd %pwd%
199199
exit /b %errorlevel%
200200
)

Installers/Dev/clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function cleanFiles() {
7777
pushd "${basePath}" >/dev/null
7878

7979
if [ $? -ne 0 ]; then
80-
writeLine "Can't navigate to $(pwd)/${basePath}" $color_error
80+
writeLine "Can't navigate to $(pwd)/${basePath} (but that's probably OK)" $color_warn
8181
popd >/dev/null
8282
return
8383
fi
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ProjectGuid>25750bf1-1502-4f65-8d69-cea8c87d6446</ProjectGuid>
66
<ProjectHome>
77
</ProjectHome>
8-
<StartupFile>registeration.py</StartupFile>
8+
<StartupFile>facevideo.py</StartupFile>
99
<SearchPath>
1010
</SearchPath>
1111
<WorkingDirectory>.</WorkingDirectory>
@@ -22,15 +22,9 @@
2222
<DebugSymbols>true</DebugSymbols>
2323
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
2424
</PropertyGroup>
25-
<ItemGroup>
26-
<Folder Include="detected\" />
27-
</ItemGroup>
28-
<ItemGroup>
29-
<Content Include="requirements.txt" />
30-
</ItemGroup>
3125
<ItemGroup>
3226
<Compile Include="benchmark.py" />
33-
<Compile Include="demoConfig.py" />
27+
<Compile Include="options.py" />
3428
<Compile Include="detect.py" />
3529
<Compile Include="face.py" />
3630
<Compile Include="facevideo.py" />
@@ -40,7 +34,7 @@
4034
<Compile Include="scene.py" />
4135
</ItemGroup>
4236
<ItemGroup>
43-
<Interpreter Include="..\..\src\AnalysisLayer\bin\windows\python37\venv\">
37+
<Interpreter Include="..\..\..\src\AnalysisLayer\bin\windows\python37\venv\">
4438
<Id>env</Id>
4539
<Version>3.7</Version>
4640
<Description>env (Python 3.7 (64-bit))</Description>
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
import argparse
99
import time
1010
from pathlib import Path
11-
1211
import requests
13-
import demoConfig as cfg
1412

15-
# deepstack credentials
16-
DEFAULT_IP_ADDRESS = cfg.serverHost
17-
DEFAULT_PORT = cfg.serverPort
18-
DEFAULT_IMAGES_FOLDER = cfg.imageDir
13+
from options import Options
1914

15+
opts = Options()
2016

2117
def main():
22-
parser = argparse.ArgumentParser(description="Perform benchmarking of DeepStack modules in CodeProject.AI")
18+
19+
DEFAULT_IP_ADDRESS = opts.serverHost
20+
DEFAULT_PORT = opts.serverPort
21+
DEFAULT_IMAGES_FOLDER = opts.imageDir + "/Objects"
22+
23+
parser = argparse.ArgumentParser(description="Perform benchmarking of CodeProject.AI Server")
2324
parser.add_argument(
2425
"--ip",
2526
default=DEFAULT_IP_ADDRESS,
@@ -32,9 +33,9 @@ def main():
3233
type=int,
3334
help="CodeProject.AI Server Port",
3435
)
35-
parser.add_argument(
36-
"--api_key", default=DEFAULT_API_KEY, type=str, help="Deepstack API key"
37-
)
36+
# parser.add_argument(
37+
# "--api_key", default=DEFAULT_API_KEY, type=str, help="Deepstack API key"
38+
#)
3839
parser.add_argument(
3940
"--images_folder",
4041
default=DEFAULT_IMAGES_FOLDER,
@@ -51,26 +52,20 @@ def main():
5152

5253
for i, img_path in enumerate(images):
5354
with open(img_path, "rb") as image_bytes:
54-
response = requests.post(
55-
cfg.serverUrl + "vision/detection",
56-
files={"image": image_bytes},
57-
data={"api_key": args.api_key},
58-
)
55+
response = requests.post(opts.endpoint("vision/detection"),
56+
files={"image": image_bytes}).json()
5957

60-
predictions = response.json()["predictions"]
61-
if (predictions == None):
62-
predictions = []
58+
predictions = response["predictions"]
59+
if (predictions == None):
60+
predictions = []
6361

6462
total_predictions = total_predictions + len(predictions)
65-
print(
66-
f"Processed image number {i} : {str(img_path)}, {len(predictions)} predictions"
67-
)
63+
print(f"Processed image {i} : {img_path}, {len(predictions)} predictions")
6864

6965
end_time = time.time()
7066
duration = end_time - start_time
71-
print(
72-
f"Processing completes in {round(duration, 5)} seconds, total of {total_predictions} predictions"
73-
)
67+
68+
print(f"Completes in {round(duration, 2)} seconds, {total_predictions} predictions, {round(total_predictions/duration,1)} ops/sec")
7469

7570

7671
if __name__ == "__main__":

demos/Python/Vision/detect.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
import requests
3+
from PIL import Image, ImageDraw
4+
5+
from options import Options
6+
7+
def main():
8+
9+
minConfidence = 0.4
10+
11+
opts = Options()
12+
opts.cleanDetectedDir()
13+
14+
imagedir = opts.imageDir + "/Objects"
15+
16+
# process all the files in the input directory and store the results in the
17+
# output directory
18+
filelist = os.listdir(imagedir)
19+
20+
for filename in filelist:
21+
if not filename.endswith(".jpg") and not filename.endswith(".png"):
22+
continue
23+
24+
filepath = os.path.join(imagedir, filename)
25+
image_data = open(filepath, "rb").read()
26+
image = Image.open(filepath).convert("RGB")
27+
28+
response = requests.post(opts.endpoint("vision/detection"),
29+
files={"image": image_data},
30+
data={"min_confidence": minConfidence}).json()
31+
32+
predictions = response["predictions"]
33+
if (predictions is None):
34+
predictions = []
35+
36+
print(f"Processed {filename}: {len(predictions)} predictions")
37+
38+
draw = ImageDraw.Draw(image)
39+
for object in predictions:
40+
label = object["label"]
41+
conf = object["confidence"]
42+
y_max = int(object["y_max"])
43+
y_min = int(object["y_min"])
44+
x_max = int(object["x_max"])
45+
x_min = int(object["x_min"])
46+
47+
draw.rectangle([(x_min, y_min), (x_max, y_max)], outline="red", width=5)
48+
draw.text((x_min, y_min), f"{label}")
49+
draw.text((x_min, y_min - 10), f"{round(conf*100.0,0)}")
50+
51+
(root, _) = os.path.splitext(filename)
52+
savedName = f"{root}.jpg"
53+
image.save(os.path.join(opts.detectedDir, savedName))
54+
55+
56+
if __name__ == "__main__":
57+
main()

demos/Python/Vision/face.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import requests
3+
from PIL import Image
4+
from options import Options
5+
6+
def main():
7+
8+
opts = Options()
9+
10+
filepath = os.path.join(opts.imageDir + "/People and actions/",
11+
"pexels-polina-tankilevitch-5848781.jpg")
12+
image_data = open(filepath, "rb").read()
13+
image = Image.open(filepath).convert("RGB")
14+
15+
opts.cleanDetectedDir()
16+
17+
response = requests.post(opts.endpoint("vision/face"),
18+
files = {"image": image_data}).json()
19+
20+
predictions = response["predictions"]
21+
if (predictions is None):
22+
predictions = []
23+
24+
print(f"Processed {filepath}: {len(predictions)} predictions")
25+
26+
i = 0
27+
for face in predictions:
28+
29+
y_max = int(face["y_max"])
30+
y_min = int(face["y_min"])
31+
x_max = int(face["x_max"])
32+
x_min = int(face["x_min"])
33+
cropped = image.crop((x_min, y_min, x_max, y_max))
34+
35+
filepath = os.path.join(opts.detectedDir, "image{}.jpg".format(i))
36+
cropped.save(filepath)
37+
38+
i += 1
39+
40+
if __name__ == "__main__":
41+
main()

demos/Python/Vision/facevideo.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# from https://github.com/DeepQuestAI/DeepStackExamples
2+
3+
import cv2
4+
import requests
5+
from options import Options
6+
7+
def main():
8+
9+
opts = Options()
10+
cap = cv2.VideoCapture(0)
11+
12+
frame_index = 0
13+
predictions = {}
14+
skip_frame = 5
15+
16+
while cap.isOpened():
17+
18+
if cv2.waitKey(1) & 0xFF == ord('q'):
19+
break
20+
21+
valid, frame = cap.read()
22+
if not valid:
23+
break;
24+
25+
frame_index += 1
26+
27+
if skip_frame > 1:
28+
if frame_index % skip_frame != 0:
29+
continue;
30+
31+
retval, new_frame = cv2.imencode('.jpg', frame)
32+
33+
response = requests.post(opts.endpoint("vision/face"),
34+
files={"image":new_frame}).json()
35+
36+
predictions = response['predictions']
37+
38+
print(f"Frame {frame_index}: {len(predictions)} predictions")
39+
40+
num_prediction_json = len(predictions)
41+
42+
for i in range(num_prediction_json):
43+
red, green, blue = 200, 100, 200
44+
frame = cv2.rectangle(frame,
45+
(predictions[i]['x_min'], predictions[i]['y_min']),
46+
(predictions[i]['x_max'], predictions[i]['y_max']),
47+
(red, green, blue), 1)
48+
49+
cv2.imshow('Image Viewer', frame)
50+
51+
cap.release()
52+
cv2.destroyAllWindows()
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
 (0)