Skip to content

Commit 1279694

Browse files
committed
feat: include models in the repo
1 parent 441a427 commit 1279694

14 files changed

+39
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
.DS_Store

car_detect.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
import numpy as np
1111
from depthai_sdk.fps import FPSHandler
1212

13+
MODELS_DIR = Path(__file__).parent.joinpath("models/DepthAI")
14+
15+
DEFAULT_MODEL_LP_VENEZUELA = MODELS_DIR.joinpath("2022-09-17/frozen_inference_graph_openvino_2021.4_6shave.blob")
16+
1317
parser = argparse.ArgumentParser()
1418
parser.add_argument("-d", "--debug", default=True, help="Debug mode")
1519
parser.add_argument("-cam", "--camera", action="store_true", help="Use DepthAI 4K RGB camera for inference (conflicts with -vid)")
1620
parser.add_argument("-vid", "--video", type=argparse.FileType("r", encoding="UTF-8"), help="Path to video file to be used for inference (conflicts with -cam)")
17-
parser.add_argument("-nn", "--nn-blob-model", type=argparse.FileType("r", encoding="UTF-8"), help="Set path of the blob (NN model)")
21+
parser.add_argument("-nn", "--nn-blob-model", type=argparse.FileType("r", encoding="UTF-8"), default=DEFAULT_MODEL_LP_VENEZUELA, help="Set path of the blob (NN model)")
1822
parser.add_argument("-nnt", "--nn-threshold", type=float, default=0.5, help="Neural Network Confidence Thresholds")
1923
args = parser.parse_args()
2024

@@ -24,7 +28,6 @@
2428
NN_INPUT_IMG_WIDTH = 256
2529
NN_INPUT_IMG_HEIGHT = 256
2630

27-
MODELS_DIR = Path(__file__).parent.joinpath("models")
2831
SHAVES = 6 if args.camera else 8
2932

3033
pipeline = dai.Pipeline()

car_lp_detect.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111

1212
from utils import frame_norm, send_frame_to_queue, to_depthai_frame
1313

14+
MODELS_DIR = Path(__file__).parent.joinpath("models/DepthAI")
15+
16+
DEFAULT_MODEL_LP_VENEZUELA = MODELS_DIR.joinpath("2022-09-17/frozen_inference_graph_openvino_2021.4_6shave.blob")
17+
1418
parser = argparse.ArgumentParser()
1519
parser.add_argument("-d", "--debug", default=True, help="Debug mode")
1620
parser.add_argument("-cam", "--camera", action="store_true", help="Use DepthAI 4K RGB camera for inference (conflicts with -vid)")
1721
parser.add_argument("-vid", "--video", type=argparse.FileType("r", encoding="UTF-8"), help="Path to video file to be used for inference (conflicts with -cam)")
18-
parser.add_argument("-nn", "--nn-blob-model", type=argparse.FileType("r", encoding="UTF-8"), help="Set path of the blob (NN model)")
22+
parser.add_argument("-nn", "--nn-blob-model", type=argparse.FileType("r", encoding="UTF-8"), default=DEFAULT_MODEL_LP_VENEZUELA, help="Set path of the blob (NN model)")
1923
parser.add_argument("-nnt", "--nn-threshold", type=float, default=0.5, help="Neural Networks Confidence Thresholds")
2024
args = parser.parse_args()
2125

@@ -39,7 +43,7 @@
3943
cam.setPreviewSize(1024, 768)
4044
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
4145
cam.setInterleaved(False)
42-
cam.setBoardSocket(dai.CameraBoardSocket.RGB)
46+
cam.setBoardSocket(dai.CameraBoardSocket.CAM_A)
4347
else:
4448
# create a XLinkIn to send the video frames from video file
4549
vid = pipeline.create(dai.node.XLinkIn)
@@ -50,14 +54,14 @@
5054

5155
# Vehicle detection NN
5256
veh_nn = pipeline.createMobileNetDetectionNetwork()
53-
veh_nn.setBlobPath(blobconverter.from_zoo(name="vehicle-detection-0200", shaves=SHAVES))
57+
veh_nn.setBlobPath(blobconverter.from_zoo(name="vehicle-detection-0200", shaves=SHAVES, output_dir=MODELS_DIR))
5458
veh_nn.setConfidenceThreshold(args.nn_threshold)
5559
veh_nn.setNumInferenceThreads(2)
5660
veh_nn.input.setQueueSize(1)
5761

5862
# license plate detection NN
5963
lp_nn = pipeline.createMobileNetDetectionNetwork()
60-
lp_nn.setBlobPath(args.nn_blob_model.name)
64+
lp_nn.setBlobPath(args.nn_blob_model)
6165
lp_nn.setConfidenceThreshold(args.nn_threshold)
6266
lp_nn.setNumInferenceThreads(2)
6367
lp_nn.input.setQueueSize(1)

main.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
import numpy as np
1010
from depthai_sdk.fps import FPSHandler
1111

12+
MODELS_DIR = Path(__file__).parent.joinpath("models/DepthAI")
13+
14+
DEFAULT_MODEL_LP_VENEZUELA = MODELS_DIR.joinpath("2022-09-17/frozen_inference_graph_openvino_2021.4_6shave.blob")
15+
1216
parser = argparse.ArgumentParser()
1317
parser.add_argument("-d", "--debug", default=True, help="Debug mode")
1418
parser.add_argument("-cam", "--camera", action="store_true", help="Use DepthAI 4K RGB camera for inference (conflicts with -vid)")
1519
parser.add_argument("-vid", "--video", type=argparse.FileType("r", encoding="UTF-8"), help="Path to video file to be used for inference (conflicts with -cam)")
16-
# parser.add_argument("-nn", "--nn-blob-model", type=argparse.FileType("r", encoding="UTF-8"), required=True, help="Set path of the blob (NN model)")
20+
parser.add_argument("-nn", "--nn-blob-model", type=argparse.FileType("r", encoding="UTF-8"), default=DEFAULT_MODEL_LP_VENEZUELA, help="Set path of the blob (NN model)")
1721
args = parser.parse_args()
1822

1923
if not args.camera and not args.video:
@@ -23,6 +27,7 @@
2327

2428
# this is the label number of the label on the model trained that represent the license_plate
2529
LICENSE_PLATE_MODEL_LABEL_NUMBER = 1
30+
LP_NN_IMG_SIZE = (672, 384)
2631

2732

2833
def frame_norm(frame, bbox):
@@ -62,22 +67,22 @@ def create_pipeline():
6267
if args.camera:
6368
print("Creating Color Camera...")
6469
cam = pipeline.create(dai.node.ColorCamera)
65-
cam.setPreviewSize(672, 384)
70+
cam.setPreviewSize(640, 640)
6671
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
6772
cam.setInterleaved(False)
68-
cam.setBoardSocket(dai.CameraBoardSocket.RGB)
73+
cam.setBoardSocket(dai.CameraBoardSocket.CAM_A)
6974

7075
cam_xout = pipeline.create(dai.node.XLinkOut)
7176
cam_xout.setStreamName("cam_out")
7277
cam.preview.link(cam_xout.input)
7378

7479
# NeuralNetwork
7580
print("Creating License Plates Detection Neural Network...")
76-
lp_nn = set_neural_network("lp_nn", pipeline, 0.6, args.nn_blob_model.name)
81+
lp_nn = set_neural_network("lp_nn", pipeline, 0.6, args.nn_blob_model)
7782

7883
if args.camera:
7984
manip = pipeline.create(dai.node.ImageManip)
80-
manip.initialConfig.setResize(300, 300)
85+
manip.initialConfig.setResize(LP_NN_IMG_SIZE)
8186
manip.initialConfig.setFrameType(dai.RawImgFrame.Type.BGR888p)
8287
cam.preview.link(manip.inputImage)
8388
manip.out.link(lp_nn.input)
@@ -88,7 +93,7 @@ def create_pipeline():
8893

8994
# NeuralNetwork
9095
print("Creating Vehicle Detection Neural Network...")
91-
veh_nn_path = blobconverter.from_zoo(name="vehicle-detection-adas-0002", shaves=SHAVES)
96+
veh_nn_path = blobconverter.from_zoo(name="vehicle-detection-adas-0002", shaves=SHAVES, output_dir=MODELS_DIR)
9297
veh_nn = set_neural_network("veh_nn", pipeline, 0.7, veh_nn_path)
9398

9499
if args.camera:
@@ -99,7 +104,7 @@ def create_pipeline():
99104
veh_xin.out.link(veh_nn.input)
100105

101106
rec_nn = pipeline.create(dai.node.NeuralNetwork)
102-
rec_nn.setBlobPath(blobconverter.from_zoo(name="text-recognition-0012", shaves=SHAVES))
107+
rec_nn.setBlobPath(blobconverter.from_zoo(name="text-recognition-0012", shaves=SHAVES, output_dir=MODELS_DIR))
103108
rec_nn.input.setBlocking(False)
104109
rec_nn.input.setQueueSize(1)
105110

@@ -116,7 +121,7 @@ def create_pipeline():
116121
rec_xin.out.link(rec_nn.input)
117122

118123
attr_nn = pipeline.create(dai.node.NeuralNetwork)
119-
attr_nn.setBlobPath(blobconverter.from_zoo(name="vehicle-attributes-recognition-barrier-0039", shaves=SHAVES))
124+
attr_nn.setBlobPath(blobconverter.from_zoo(name="vehicle-attributes-recognition-barrier-0039", shaves=SHAVES, output_dir=MODELS_DIR))
120125
attr_nn.input.setBlocking(False)
121126
attr_nn.input.setQueueSize(1)
122127

@@ -177,9 +182,9 @@ def lic_thread(det_queue: dai.Node, rec_queue: dai.Node) -> None:
177182
img = dai.ImgFrame()
178183
img.setTimestamp(tstamp)
179184
img.setType(dai.RawImgFrame.Type.BGR888p)
180-
img.setData(to_planar(cropped_frame, (120, 32)))
181-
img.setWidth(120)
182-
img.setHeight(32)
185+
img.setData(to_planar(cropped_frame, (94, 24)))
186+
img.setWidth(94)
187+
img.setHeight(24)
183188
rec_queue.send(img)
184189

185190
fps.tick("lic")
@@ -269,6 +274,8 @@ def attr_thread(q_attr, q_pass):
269274

270275
print("Starting pipeline...")
271276
with dai.Device(create_pipeline()) as device:
277+
print("press q to stop")
278+
272279
if args.camera:
273280
cam_out = device.getOutputQueue("cam_out", 1, True)
274281
else:
@@ -328,12 +335,12 @@ def get_frame():
328335
tstamp = time.monotonic()
329336

330337
lic_frame = dai.ImgFrame()
331-
lic_frame.setData(to_planar(frame, (300, 300)))
338+
lic_frame.setData(to_planar(frame, LP_NN_IMG_SIZE))
332339
lic_frame.setTimestamp(tstamp)
333340
lic_frame.setSequenceNum(frame_det_seq)
334341
lic_frame.setType(dai.RawImgFrame.Type.BGR888p)
335-
lic_frame.setWidth(300)
336-
lic_frame.setHeight(300)
342+
lic_frame.setWidth(LP_NN_IMG_SIZE[0])
343+
lic_frame.setHeight(LP_NN_IMG_SIZE[1])
337344
lp_in.send(lic_frame)
338345

339346
veh_frame = dai.ImgFrame()
@@ -343,9 +350,9 @@ def get_frame():
343350
veh_frame.setType(dai.RawImgFrame.Type.BGR888p)
344351
veh_frame.setWidth(300)
345352
veh_frame.setHeight(300)
346-
veh_frame.setData(to_planar(frame, (672, 384)))
347-
veh_frame.setWidth(672)
348-
veh_frame.setHeight(384)
353+
veh_frame.setData(to_planar(frame, LP_NN_IMG_SIZE))
354+
veh_frame.setWidth(LP_NN_IMG_SIZE[0])
355+
veh_frame.setHeight(LP_NN_IMG_SIZE[1])
349356
veh_in.send(veh_frame)
350357

351358
if args.debug:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)