question of matlab arduino
Info
This question is closed. Reopen it to edit or answer.
Show older comments
i have code in matlab
if true
% code
end
clc
clear all
close all
background=imread('frame210.jpg');
foreground=imread('frame245.jpg');
a=rgb2gray(background);
b=rgb2gray(foreground);
diff_im=imsubtract(a,b);
diff_im = medfilt2(diff_im, [5 5]);
diff_im_a=im2bw(diff_im,0.18);
diff_im_b=bwareaopen(diff_im_a,500,8);
bw=bwlabel(diff_im_b,8);
bw=imfill(bw,'holes');
figure(1);imshow(diff_im);
figure(2);imshow(diff_im_a);
figure(3);imshow(diff_im_b);
figure(4);imshow(bw);
hold on
stats=regionprops(bw,'BoundingBox','Centroid');
for object=1:length(stats)
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
hold off
S1 = serial ('COM3', 'BAUD', 9600);
data1=bc(1);
data2=bc(2);
fopen(S1);
serialbreak(S1,1);
fprintf(S1,['%s:%s'],[data1;data2],'sync');
fclose (S1);
clear all
and code in arduino
if true
% code
end
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int data1;
int data2;
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
}
void loop()
{
if(Serial.available())
{
data1=Serial.read();
data2=Serial.read();
lcd.setCursor(0,0);
lcd.print('x= ');lcd.print(data1);
lcd.setCursor(0,1);
lcd.print('y= ');lcd.print(data2);
delay(10000);
lcd.clear();
}
}
i want position x and y of centroid can display in lcd. this code correct or not. do you have solution?
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!