Skip to content

Commit 7acdb34

Browse files
authored
Merge pull request #2 from yanndebray/main
Improvements coming with Python Importer for Simulink
2 parents efafff7 + 5522250 commit 7acdb34

File tree

93 files changed

+762
-66
lines changed

Some content is hidden

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

93 files changed

+762
-66
lines changed

.gitattributes

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
* text=auto
2+
3+
*.fig binary
4+
*.mat binary
5+
*.mdl binary diff merge=mlAutoMerge
6+
*.mdlp binary
7+
*.mex* binary
8+
*.mlapp binary
9+
*.mldatx binary
10+
*.mlproj binary
11+
*.mlx binary
12+
*.p binary
13+
*.sfx binary
14+
*.sldd binary
15+
*.slreqx binary merge=mlAutoMerge
16+
*.slmx binary merge=mlAutoMerge
17+
*.sltx binary
18+
*.slxc binary
19+
*.slx binary merge=mlAutoMerge
20+
*.slxp binary
21+
22+
## Other common binary file types
23+
*.docx binary
24+
*.exe binary
25+
*.jpg binary
26+
*.pdf binary
27+
*.png binary
28+
*.xlsx binary

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
slprj/

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: 49 additions & 30 deletions

README.mlx

7.43 MB
Binary file not shown.

base_python_example_23a.slx

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

debug.ipynb

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

detectHuman.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import time
2-
import imutils
2+
# import imutils
33
import numpy as np
4-
from cv2 import cv2
4+
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)
19-
image = imutils.resize(image, width=min(400, image.shape[1]))
12+
# image = imutils.resize(image, width=min(400, image.shape[1]))
13+
ratio = image.shape[0] / image.shape[1]
14+
new_height = int(400 * ratio)
15+
image = cv2.resize(image, (400,new_height))
2016

2117
# Detecting all the regions in the Image that has a pedestrians inside it
2218
(regions, _) = hog.detector.detectMultiScale(
@@ -30,8 +26,6 @@ def detectHumanFromFrame(image, hog):
3026

3127

3228
if __name__ == "__main__":
33-
34-
hog = hogObject()
3529

3630
cap = cv2.VideoCapture('livedata.mp4')
3731
ret, image = cap.read()
@@ -41,7 +35,7 @@ def detectHumanFromFrame(image, hog):
4135
# Reading the video stream
4236
ret, image = cap.read()
4337
if ret:
44-
image = detectHumanFromFrame(image, hog)
38+
image = detectHumanFromFrame(image)
4539
cv2.imshow("Image", image)
4640
cv2.waitKey(5)
4741
if cv2.waitKey(5) & 0xFF == ord('q'):

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()

license.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Copyright (c) 2020, The MathWorks, Inc.
2-
All rights reserved.
3-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6-
3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings.
7-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8-
9-
10-
11-
1+
Copyright (c) 2020, The MathWorks, Inc.
2+
All rights reserved.
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6+
3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings.
7+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8+
9+
10+
11+

pySimCV.prj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MATLABProject xmlns="http://www.mathworks.com/MATLABProjectFile"/>

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv-python
2+
numpy
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Ref="" Type="Relative"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="556b23f8-b46f-40bc-ba39-5688323b44fd" type="Reference"/>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info File="runme.m" GroupUUID="default" Icon="" Name="runme" Type="StartUp" Visible="0">
3+
<Extension Name="StartUpPrev" Value="HEAD"/>
4+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="89a2a5cc-1383-4cf9-8298-ba7852a76583" type="EntryPoint"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="Test" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="test" type="Label"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="Other" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="other" type="Label"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="Convenience" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="convenience" type="Label"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="None" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="none" type="Label"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="Derived" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="derived" type="Label"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="Design" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="design" type="Label"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="Artifact" ReadOnly="READ_ONLY"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="artifact" type="Label"/>

resources/project/Project.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info MetadataType="fixedPathV2"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info DataType="None" Name="Classification" ReadOnly="1" SingleValued="1"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="FileClassCategory" type="Category"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design"/>
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="setup_python.m" type="File"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="license.txt" type="File"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="README.MD" type="File"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design"/>
5+
</Category>
6+
</Info>

0 commit comments

Comments
 (0)