the raspi connect the monitor the show image delay

3 views (last 30 days)
if true
function [light_r,light_g,light_y]= fcn(img_R,img_G,img_B)
light_r =0;
light_g =0;
light_y =0;
img = uint8(zeros(320,240,3));
img(:,:,1) = img_R;
img(:,:,2) = img_G;
img(:,:,3) = img_B;
img_hsv = rgb2hsv(img);
%%%%%%%%%%%%%紅色區域的門檻值%%%%%%%%%%%%%%%%%%
h_redMin = 0.002;
h_redMax = 0.103;
s_redMin = 0.131;
s_redMax = 0.880;
v_redMin = 0.741;
v_redMax = 1.000;
%%%%%%%%%%%%%綠色區域的門檻值%%%%%%%%%%%%%%%%%%
h_greenMin = 0.248;
h__greenMax = 0.386;
s__greenMin = 0.298;
s__greenMax = 1.000;
v__greenMin = 0.129;
v__greenMax = 1.000;
%%%%%%%%%%%%%黃色區域的門檻值%%%%%%%%%%%%%%%%%%
h_yellowMin = 0.153;
h__yellowMax = 0.178;
s__yellowMin = 0.157;
s__yellowMax = 0.804;
v__yellowMin = 0.800;
v__yellowMax = 1.000;
%%%%%%%%%%%%%%%取出HSV值%%%%%%%%%%%%%%%%%%%%%%%%%
h = img_hsv(:,:,1);
s = img_hsv(:,:,2);
v = img_hsv(:,:,3);
bw = ((h>=h_redMin) & (h <= h_redMax) & (s >= s_redMin) & (s<= s_redMax) & ...
(v >= v_redMin ) & (v <= v_redMax))|((h >= h_greenMin ) & (h <= h__greenMax) & ...
(s >= s__greenMin ) & (s <= s__greenMax) & (v >= v__greenMin ) & (v <= v__greenMax))| ...
((h >= h_yellowMin ) & (h <= h__yellowMax) & (s >= s__yellowMin ) & (s <= s__yellowMax) &(v >= v__yellowMin ) & (v <= v__yellowMax));
a = double(img); %原圖
b = bw; %二值圖
c = uint8(cat(3,a(:,:,1 ).*b,a(:,:,2).*b,a(:,:,3).*b)); %結果
d = rgb2hsv(c);
h_d = d(:,:,1);
s_d = d(:,:,2);
v_d = d(:,:,3);
[y,x,z] = size(c);
Red_y=zeros(y,1);
Green_y=zeros(y,1);
Yellow_y=zeros(y,1);
for i=1:y
for j=1:x
if((h_d(i,j)>=h_redMin) & (h_d(i,j) <= h_redMax)) & (s_d(i,j) >= s_redMin) & (s_d(i,j)<= s_redMax) & ...
(v_d(i,j) >= v_redMin ) & (v_d(i,j) <= v_redMax)
Red_y(i,1)= Red_y(i,1)+1;
elseif((h_d(i,j) >= h_greenMin ) & (h_d(i,j) <= h__greenMax) & ...
(s_d(i,j) >= s__greenMin ) & (s_d(i,j) <= s__greenMax) & (v_d(i,j) >= v__greenMin ) & (v_d(i,j) <= v__greenMax))
Green_y(i,1)= Green_y(i,1)+1;
elseif((h_d(i,j) >= h_yellowMin ) & (h_d(i,j) <= h__yellowMax) & (s_d(i,j) >= s__yellowMin ) & (s_d(i,j) <= s__yellowMax) & ...
(v_d(i,j) >= v__yellowMin ) & (v_d(i,j) <= v__yellowMax))
Yellow_y(i,1)= Yellow_y(i,1)+1;
end
end
end
Max_Red_y=max(Red_y);
Max_Green_y=max(Green_y);
Max_Yellow_y=max(Yellow_y);
if((Max_Red_y> Max_Green_y)&&(Max_Red_y> Max_Yellow_y))
light_r =1;
elseif((Max_Green_y> Max_Red_y)&&(Max_Green_y> Max_Yellow_y))
light_g =1;
elseif((Max_Yellow_y> Max_Green_y)&&(Max_Yellow_y> Max_Red_y))
light_y = 1;
else
light_r =0;
light_g =0;
light_y =0;
end
end
i use this function on the simulink but embbeded the raspi the image have serious delay How can I improve?

Answers (0)

Categories

Find more on 安装和许可简介 in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!