error in arduino object
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
barath V
am 3 Mär. 2020
Kommentiert: barath V
am 20 Mär. 2020
error:Undefined function or variable 'ard'.
fprintf(ard,'%d',index) %"here is where we send the position of image to arduino"
clc;
clear all;
CAMERA = videoinput('pointgrey', '1');%camera initialization
start(CAMERA);
ard = serial('COM3','BaudRate',9600); %arduino initialization
fopen(ard);
pause(1);
for b = 1:8
automate(CAMERA)
pause(8)
end
fclose(ard)
stop(CAMERA); %stop camera acquisition
function[addition] = bodekke(imagename) %bodekke function mathematics behind the autofocus detection
im = double(imread(imagename))
bd = [-1 0 1]
cbd = conv2(im,bd)
squaredcbd = cbd.^2
addition = sum(squaredcbd(:))
end
function automate(CAMERA)
for i = 1:30 %to capture images
filename = sprintf('testtry%02d.jpg',i);
img = im2double(getsnapshot(CAMERA)); %captures images
img = rgb2gray(img);
imwrite(img,filename)
end
D = 'C:\Users\PRL\Desktop\just'; %location where image is stored
S = dir(fullfile(D,'*.jpg'));
for k = 1:numel(S) %applies bodekke to all images
F = fullfile(D,S(k).name);
addition(k) = bodekke(F); %bodekke function call
end
plot(addition); %plotting values just for our visual understanding
[m,index] = max(addition)
hold on
plot(index,m,'*')
hold off
title("bodekke with spot images")
fprintf(ard,'%d',index) %"here is where we send the position of image to arduino"
end
0 Kommentare
Akzeptierte Antwort
Charan Jadigam
am 19 Mär. 2020
Hi,
The serial object ‘ard’ is not defined in the scope of function ‘bodekke’ and so MATLAB is throwing an error. Try passing serial Arduino object to the function ‘bodekke’ and change the function declaration to add serial object ‘ard’ in argument list as shown below.
automate(CAMERA,ard);
function[addition] = bodekke(imagename,ard);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Acquisition Toolbox Supported Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!