Using vision.Cas​​cadeObjec​t​Detector on Simulink

2 visualizaciones (últimos 30 días)
Hello, I read the previous answers about the same problem but I am still not able to solve my problem. What i want is to detect water bottles and get their centroids. Here is my code,
function centroids = fcn(img)
coder.extrinsic('vision.CascadeObjectDetector');
detector = vision.CascadeObjectDetector('...\Bottle.xml');
bboxes = step(detector,img);
centroids = [bboxes(:,1)+(bboxes(:,3)/2),bboxes(:,2)+(bboxes(:,4)/2)];
And the errors are,
Unexpected MATLAB operator.
Function 'MATLAB Function' (#88.264.265), line 5, column 21:
":"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'MATLAB Function'
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error occurred in 'Swarm_Control/MATLAB Function'.
Component:Simulink | Category:Model error

Respuesta aceptada

Sebastian Castro
Sebastian Castro el 19 de Sept. de 2017
Editada: Sebastian Castro el 19 de Sept. de 2017
The issue here is that the step method of vision.CascadeObjectDetector can return a variable number of bounding boxes, from zero to (technically) infinite. See below for more info on variable-sized signals:
You can deal with this variable-size signal by either bounding the max size of the output or enabling dynamic memory allocation in your model.
A further option is to create a "wrapper" MATLAB function that uses vision.CascadeObjectDetector and always fills, for example, the N largest bounding boxes into a fixed-size output. Then, you can call that from Simulink without worrying about variable-sized signals. Instead, you have to pre-allocate that N-by-4 array of bounding boxes to, e.g., zeros and make sure you handle all the edge cases for filling that array with the output of the detector.
With this last approach you will still need to handle the variable-sized signals as above, but you will make sure that the output of your MATLAB Function block to the rest of the model is of a fixed size. It certainly helps with memory usage.
- Sebastian
  7 comentarios
Sebastian Castro
Sebastian Castro el 22 de Sept. de 2017
Hmm... since bboxes is an output, and not just local data, you may need to do this instead of coder.varsize.
- Sebastian
Kerem Asaf Tecirlioglu
Kerem Asaf Tecirlioglu el 22 de Sept. de 2017
Thanks a lot , got it working with the code
function bboxes = fcn(img)
coder.extrinsic('vision.CascadeObjectDetector');
coder.extrinsic('step(detector,img)');
detector =vision.CascadeObjectDetector('...Bottle.xml');
bboxes = zeros(1,4);
bboxes=step(detector,img);
And setting
%

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by