question of matlab arduino

i have code in matlab
if true
% code
end
close all;
clear all;
clc;
rgbInputImage = imread('sedang (7).jpg');
rgbInputImage = imresize(rgbInputImage, 0.234);
sharpfilter = fspecial('unsharp');
rgbInputImage = imfilter(rgbInputImage, sharpfilter, 'replicate');
gaussianfilter = fspecial('gaussian', [7 7], 5);
rgbInputImage = imfilter(rgbInputImage, gaussianfilter, 'symmetric', 'conv');
labInputImage = applycform(rgbInputImage,makecform('srgb2lab'));
Lbpdfhe = uint8(labInputImage(:,:,1));
labOutputImage = cat(3,Lbpdfhe,labInputImage(:,:,2),labInputImage(:,:,3));
rgbOutputImage = applycform(labOutputImage,makecform('lab2srgb'));
figure, imshow(rgbInputImage);
figure, imshow(rgbOutputImage);
img=rgbOutputImage;
final_image = zeros(size(img,1), size(img,2));
if(size(img, 3) > 1)
for i = 1:size(img,1)
for j = 1:size(img,2)
r = img(i,j,1);
g = img(i,j,2);
b = img(i,j,3);
if (r > 92 && g > 40 && b > 20)
v=[r,g,b];
if((max(v) - min(v)) > 15)
if(abs(r-g) > 15 && r > g && r >b)
final_image(i,j) = 1;
end
end
end
end
end
end
binaryImage=im2bw(final_image,0.6);
figure, imshow(binaryImage);
binaryImage = imfill(binaryImage, 'holes');
figure, imshow(binaryImage);
binaryImage = bwareaopen(binaryImage,1000);
figure,imshow(binaryImage);
labeledImage = bwlabel(binaryImage, 8);
blobMeasurements = regionprops(labeledImage, final_image, 'all');
numberOfPeople = size(blobMeasurements, 1)
imagesc(rgbInputImage); title('Outlines, from bwboundaries()');
hold on;
boundaries = bwboundaries(binaryImage);
for k = 1 : numberOfPeople
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
imagesc(rgbInputImage);
hold on;
title('Original with bounding boxes');
for k = 1 : numberOfPeople
thisBlobsBox = blobMeasurements(k).BoundingBox;
x1 = thisBlobsBox(1);
y1 = thisBlobsBox(2);
x2 = x1 + thisBlobsBox(3);
y2 = y1 + thisBlobsBox(4);
x = [x1 x2 x2 x1 x1];
y = [y1 y1 y2 y2 y1];
plot(x, y, 'LineWidth', 2);
end
hold on;
if (numberOfPeople >= 9)
text(200,50,strcat('\color{green}kondisi: sepi'))
disp('kondisi : sepi')
else if (numberOfPeople <= 13)
text(200,50,strcat('\color{green}kondisi : ramai'))
disp('kondisi : ramai')
end
end
s = serial('com3','BAUD', 9600);
fopen(s);
for m=1:10
numberOfPeople=numberOfPeople;
fprintf(s,'%s',numberOfPeople,'sync');
end
fclose(s);
and code in arduino
if true
% code
end
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int numberOfPeople;
void setup(){
Serial.begin(9600);
lcd.begin(16,1);
}
void loop()
{
if(Serial.available())
{
numberOfPeople=Serial.read();
lcd.setCursor(0,0);
lcd.print(numberOfPeople);
delay(1000);
}
}
sometimes lcd display execution from matlab but sometimes lcd not display execution from matlab. why? what solution about this? or my code is wrong?

Answers (0)

This question is closed.

Tags

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!