Regionprops function in Simulink

조회 수: 11 (최근 30일)
Emmet Brown
Emmet Brown 2016년 9월 24일
댓글: Walter Roberson 2019년 5월 26일
Hello. I've problem with using regionprops function in Simulink.
The function 'regionprops' is not supported for standalone code generation.
So I made block with such code
function [x1,y1] = f(In)
coder.extrinsic('regionprops');
s = regionprops(In,'centroid');
centroids = cat(1, s.centroid);
x1 = centroids(1,1);
y1 = centroids(1,2);
Now I get error that field with parameters is not exist
Attempt to extract field 'centroid' from 'mxArray'.
line 5, column 20:
  댓글 수: 1
Fernando Camacho Villalobos
Fernando Camacho Villalobos 2019년 5월 26일
Hi! Did you solve this problem? I need to create the same block for Simulink. Help me, please.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 25일
Before the
s = regionprops(In,'centroid');
line, you need
s = struct('centroid', 0);
This signals to the code generator that the mxArray that is returned from the regionprops call needs to be brought into the workspace.
You might find that you need to use one of the methods of indicating variable sized arrays; see http://www.mathworks.com/help/fixedpoint/ug/defining-variable-size-data-for-code-generation.html since you are expecting multiple centroids back.
Your code seems to collect all of the centroids, but then it appears to only pay attention to the first of them. I do not see the point of collecting them all in that case.
s = struct('centroid', [0 0]);
s = regionprops(In,'centroid');
x1 = s.centroid(1,1);
y1 = s.centroid(1,2);
You might still need to worry about variable-sized arrays though.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 5월 26일
In cases where you are only paying attention to one region, it might make sense to use tools such as bwareafilt() to filter down to a single region first, so that you can predict the size of the return data from regionprops.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by