Skip to content

Commit 8c919c4

Browse files
committed
Refactor for 23a Python Importer demo
1 parent 2bab65e commit 8c919c4

9 files changed

+81
-14
lines changed

HumanDetection.slx

64 KB
Binary file not shown.

HumanDetection_import.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"SimulinkCodeImporterVersion": 1,
3+
"LibraryFileName": "HumanDetection",
4+
"CustomCode": {
5+
"SourceFiles": ".\\detectHuman.py",
6+
"GlobalVariableInterface": false
7+
},
8+
"FunctionsToImport": "detectHuman.detectHumanFromFrame",
9+
"FunctionSettings": {
10+
"Name": "detectHuman.detectHumanFromFrame",
11+
"PortSpecArray": [
12+
{
13+
"ArgName": "image",
14+
"PortName": "image",
15+
"Scope": "Output",
16+
"Index": "1",
17+
"Type": "uint8",
18+
"Size": "[300 400 3]",
19+
"IsGlobal": false
20+
},
21+
{
22+
"ArgName": "image",
23+
"PortName": "image",
24+
"Scope": "Input",
25+
"Index": "1",
26+
"Type": "uint8",
27+
"Size": "[480 640 3]",
28+
"IsGlobal": false
29+
}
30+
],
31+
"IsDeterministic": false
32+
}
33+
}

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This example shows users how to integrate Python Human detection code into Simul
2929
To use this example,
3030
1. open and run the runme.m first in MATLAB;
3131
2. Then start the base_python_example_21a.slx
32-
3. Run simulaiton.
32+
3. Run simulation.
3333

3434

3535
## Product dependencies

README.mlx

7.43 MB
Binary file not shown.

base_python_example_23a.slx

27.6 KB
Binary file not shown.
27.5 KB
Binary file not shown.

detectHuman.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22
# import imutils
33
import numpy as np
44
import cv2
5+
import hogClass
56

7+
def detectHumanFromFrame(image):
68

7-
class hogObject:
8-
detector = cv2.HOGDescriptor()
9-
def __init__(self):
10-
self.detector.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
11-
12-
13-
def getHogObject():
14-
return hogObject()
15-
16-
17-
def detectHumanFromFrame(image, hog):
9+
hog = hogClass.hogObject()
10+
1811
image = np.asarray(image)
1912
# image = imutils.resize(image, width=min(400, image.shape[1]))
2013
ratio = image.shape[0] / image.shape[1]
@@ -33,8 +26,6 @@ def detectHumanFromFrame(image, hog):
3326

3427

3528
if __name__ == "__main__":
36-
37-
hog = hogObject()
3829

3930
cap = cv2.VideoCapture('livedata.mp4')
4031
ret, image = cap.read()

detectHuman_detectHumanFromFrame.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
classdef detectHuman_detectHumanFromFrame < matlab.System
2+
% Python def detectHumanFromFrame imported from python module detectHuman.py
3+
methods(Access = protected)
4+
function validateInputsImpl(obj, varargin)
5+
if ~isempty(varargin{1})
6+
validateattributes(varargin{1}, {'uint8'}, {'size',[480 640 3]});
7+
end
8+
end
9+
function setupImpl(obj)
10+
py.importlib.import_module('detectHuman');
11+
end
12+
function [image] = stepImpl(obj,image)
13+
image = uint8(py.detectHuman.detectHumanFromFrame(image));
14+
end
15+
function varargout = getOutputDataTypeImpl(obj)
16+
varargout{1} = 'uint8';
17+
end
18+
function varargout = getOutputSizeImpl(obj)
19+
varargout{1} = [300 400 3];
20+
end
21+
function varargout = isOutputComplexImpl(obj)
22+
varargout{1} = false;
23+
end
24+
function varargout = isOutputFixedSizeImpl(obj)
25+
varargout{1} = true;
26+
end
27+
end
28+
methods(Static, Access = protected)
29+
function simMode = getSimulateUsingImpl
30+
simMode = 'Interpreted execution';
31+
end
32+
end
33+
end

hogClass.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import cv2
2+
3+
class hogObject:
4+
detector = cv2.HOGDescriptor()
5+
def __init__(self):
6+
self.detector.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
7+
8+
9+
def getHogObject():
10+
return hogObject()

0 commit comments

Comments
 (0)