Raspberry and interpreted function in simulink

Hello,
I need your help to solve my problem. I have to realized project in simulink which is based on communication with raspberry pi 3. Please see the model in simulink:
Inside the subsystem is :
And the interpreted function is :
function [DANE]=DetekcjaKata(image)
vidFrame = image;
figure(1);imshow(vidFrame);
Rmin=15;
Rmax=45;
[centers, radii] = imfindcircles(vidFrame,[Rmin Rmax],'ObjectPolarity','dark','Sensitivity',0.75);
viscircles(centers, radii,'EdgeColor','b');
%%Wykrycie kół znaczników
if size(centers,1)==3
hold on
plot(centers(1,1),centers(1,2),'xr')
plot(centers(2,1),centers(2,2),'xg')
plot(centers(3,1),centers(3,2),'xw')
pkt_AB=[centers(1,1),centers(1,2);centers(2,1),centers(2,2)];
L1=line([centers(1,1),centers(2,1)],[centers(1,2),centers(2,2)]);
dl_1 = pdist(pkt_AB,'euclidean');
pkt_AC=[centers(1,1),centers(1,2);centers(3,1),centers(3,2)];
L2=line([centers(1,1),centers(3,1)],[centers(1,2),centers(3,2)]);
dl_2 = pdist(pkt_AC,'euclidean');
pkt_BC=[centers(2,1),centers(2,2);centers(3,1),centers(3,2)];
L3=line([centers(2,1),centers(3,1)],[centers(2,2),centers(3,2)]);
dl_3 = pdist(pkt_BC,'euclidean');
DANE(1)=centers(1,1);
DANE(2)=centers(1,2);
DANE(3)=centers(2,1);
DANE(4)=centers(2,2);
DANE(5)=centers(3,1);
DANE(6)=centers(3,2);
DANE(7)=dl_1;
DANE(8)=dl_2;
DANE(9)=dl_3;
DANE(10)=1;
else
DANE=zeros(1,10);
end
end
end
I have the error :
then I change the type of data to double like this :
I get the error :
This application is looking for three circles and give me the value "x" and "y" of a centroid of the circle. It is good working on a wideo file, but problem is with raspberry..
Please help me solve this problem..
Regards,
Jan

 채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 19일
Please do not use "image" as a variable name; it confuses other programmers who think it must be referring to the image() function.
To generate code to execute on the Raspberry Pi, you will need to get rid of all of the graphics in the routine in their current form. The only graphics possible on the Pi are through the SDL Video Block. In other words, to display something you need to create an image of it. You would start with the input image and you would use the insertShape Computer Vision call. Your plot() calls are really just inserting markers; you can use insertMarker for that.
You will also need to make some changes to the order of your code to be able to generate code for it. For example you will need to have
DANE=zeros(1,10);
before you start assigning to DANE(1) and so on. The first assignment to a variable locks in the size and data type of the variable for model generation purposes.

댓글 수: 7

Jan Szlek
Jan Szlek 2017년 9월 25일
편집: Jan Szlek 2017년 9월 25일
Thank you for answer ! I just modified my program and now it look like below:
I main model nothing was change.
Inside the Subsystem I changed the interpreted function like bellow:
The function now is:
function DANE = fcn(obraz)
vidFrame = obraz;
coder.extrinsic('imfindcircles');
coder.extrinsic('pdist');
L_okr=0;
pkt_AB=zeros(2,2);
pkt_AC=zeros(2,2);
pkt_BC=zeros(2,2);
dl_1=0;
dl_2=0;
dl_3=0;
Rmin=15;
Rmax=45;
temp=zeros(3,2);
[centers, radii] = imfindcircles(vidFrame,[Rmin Rmax],'ObjectPolarity','dark','Sensitivity',0.75);
DANE=zeros(1,10);
L_okr=size(centers,2);
if L_okr==3
temp=centers;
pkt_AB=[temp(1,1),temp(1,2);temp(2,1),temp(2,2)];
dl_1 = pdist(pkt_AB,'euclidean');
pkt_AC=[temp(1,1),temp(1,2);temp(3,1),temp(3,2)];
dl_2 = pdist(pkt_AC,'euclidean');
pkt_BC=[temp(2,1),temp(2,2);temp(3,1),temp(3,2)];
dl_3 = pdist(pkt_BC,'euclidean');
DANE(1)=temp(1,1);
DANE(2)=temp(1,2);
DANE(3)=temp(2,1);
DANE(4)=temp(2,2);
DANE(5)=temp(3,1);
DANE(6)=temp(3,2);
DANE(7)=dl_1;
DANE(8)=dl_2;
DANE(9)=dl_3;
DANE(10)=1;
else
DANE=zeros(1,10);
end
end
Now I get this error:
What I do wrong ? On a video film from file all is ok, but not on a raspberry.. Please help me solve this problem. In attachment is the screen of error in better quality.
It is not possible to generate code for those three calls, size(), pdist, imfindcircles().
pdist() 'Euclidean' is easy enough to rewrite.
imfindcircles() will be more of a problem.
You only use size() to test that you got back exactly 3 circles. When you write the imfindcircles() logic yourself, you can stop if you encounter a 4th circle, so you do not need to use size() in that way.
Rewriting imfindcircles() will be a nuisance. See https://www.mathworks.com/help/images/ref/imfindcircles.html#bti4sim
Is it definite that you need to find circles? Would it be acceptable to instead do something like use regionprops() to detect blobs and request Centroid and Eccentricity and look for objects that have low Eccentricity ?
When I commented below part of code:
L_okr=size(centers,2);
if L_okr==3
temp=centers;
pkt_AB=[temp(1,1),temp(1,2);temp(2,1),temp(2,2)];
dl_1 = pdist(pkt_AB,'euclidean');
pkt_AC=[temp(1,1),temp(1,2);temp(3,1),temp(3,2)];
dl_2 = pdist(pkt_AC,'euclidean');
pkt_BC=[temp(2,1),temp(2,2);temp(3,1),temp(3,2)];
dl_3 = pdist(pkt_BC,'euclidean');
DANE(1)=temp(1,1);
DANE(2)=temp(1,2);
DANE(3)=temp(2,1);
DANE(4)=temp(2,2);
DANE(5)=temp(3,1);
DANE(6)=temp(3,2);
DANE(7)=dl_1;
DANE(8)=dl_2;
DANE(9)=dl_3;
DANE(10)=1;
else
DANE=zeros(1,10);
end
The program is good working, but of course the program doesn't perform its function.
The general function of this program is finding the marker (composed by 3 circles)from raspberry video then the robot which is control should stop. Always will be max 3 circles.
It would probably help if you posted a couple of sample images that would need to have the markers detected.
The marker looks like below. From multimedia file it is working, trouble is with raspberry. For work with raspberry I play it in external mode. The video is changing in steps:
1 - the marker is invisible,
2 - a piece of paper is moved to the right, so we can see only part of first circle,
3 - we can see 2 circles,
4 - we can see 3 circles,
5 - trigger is equal 1 (when the 3 circles are detected)
below program is working on a Matlab function block.
finally i want get something like this(it is from interpreted function, but plot the line, point, others marker I can do later on a matlab function block):
as I say all of this is working on a video
Could you attach one of the images by itself without the model and other extraneous information?
Hello,
I done my project another way. I had to modify almost everything. Now all is done in simulink using the necessary functions.
Thank you for any help !

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Raspberry Pi Hardware에 대해 자세히 알아보기

질문:

2017년 7월 20일

댓글:

2017년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by