error:Undefined function or variable 'values'.
이전 댓글 표시
clc;
clear all;
CAMERA = videoinput('pointgrey', '1');%camera initialization
start(CAMERA);
a = serial('COM3','BaudRate',9600); %arduino initialization
fopen(a);
pause(1);
for a = 1:8
automate(CAMERA)
pause(8)
end
plot(values); %plotting values just for our visual understanding
[m,index] = max(values)
fprintf(a,'%d',index) %"here is where we send the position of image to arduino"
fclose(a)
hold on
plot(index,m,'*')
hold off
title("bodekke with spot images")
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);
queen(k) = bodekke(F); %bodekke function call
end
end
댓글 수: 26
KSSV
2020년 3월 3일
Which line number? How did you run/ call the function?
barath V
2020년 3월 3일
Alex Mcaulley
2020년 3월 3일
Where are you doing this? I can't see this line...
Adam
2020년 3월 3일
You clearly aren't doing. Given that you have
clear all
at the top, then only these lines will have any impact before the plot instruction:
CAMERA = videoinput('pointgrey', '1');%camera initialization
start(CAMERA);
a = serial('COM3','BaudRate',9600); %arduino initialization
fopen(a);
pause(1);
for a = 1:8
automate(CAMERA)
pause(8)
end
None of these lines assigns anything to 'values'
barath V
2020년 3월 3일
barath V
2020년 3월 3일
You need to get to understand how different workspaces work in Matlab (and many languages, for that matter)
A function has its own sealed workspace. The only variables it sees are those you pass in (unless it is a nested function), the only variables the outside world will see are the ones it returns as arguments. Once you understand the scope of workspaces and error like this is 100% self-explanatory from the message it gives.
You define ard in your code at the top, but you do not pass it to the automate function so this function does not know of a variable called ard, hence the error. Pass it in as an argument if you wish to use it in the function.
barath V
2020년 3월 5일
KALYAN ACHARJYA
2020년 3월 5일
This error is completely different from previous one. May be: please look on the avalible port number in arduino interface.
barath V
2020년 3월 5일
Walter Roberson
2020년 3월 5일
Pass ard into the function?
barath V
2020년 3월 5일
Walter Roberson
2020년 3월 5일
You are not calling drawnow() or pause(), so you will only see the final graphics result. drawnow() or pause() tell the graphics system that the changes to the graphics objects can be sent to the display.
You are not sending a line terminator with your fprintf()
barath V
2020년 3월 6일
Walter Roberson
2020년 3월 6일
I am not clear as to what you are saying? Are you saying that plot(addition) is not producing a visual result, but the marking of the maximum is working?
You are still not sending a line termination to the arduino '%d\n'
barath V
2020년 3월 6일
Walter Roberson
2020년 3월 8일
You imwrite using the filename pattern testtry%02d.jpg but it is not clear that your current directory is the same as the directory that you look inside, 'C:\Users\PRL\Desktop\just' . It would be better for you to move the assignment to D to before the for i loop, and that you use
imwrite(img, fullfile(D,filename))
barath V
2020년 3월 9일
Walter Roberson
2020년 3월 9일
After you do
S = dir(fullfile(D,'*.jpg'));
what shows up for size(S) ?
barath V
2020년 3월 9일
barath V
2020년 3월 9일
Walter Roberson
2020년 3월 9일
Use instrfind() to locate the com port object, and delete() the object. And change your code to delete(a) after you fclose(a)
Walter Roberson
2020년 3월 9일
For the purpose of debugging, after
title("bodekke with spot images")
add
fprintf('%d of %d elements in addition are finite', nnz(isfinite(addition)), numel(addition));
barath V
2020년 3월 20일
답변 (1개)
barath V
2020년 3월 9일
0 개 추천
댓글 수: 3
Walter Roberson
2020년 3월 20일
Your automate function is already capturing the video and writing it to file.
barath V
2020년 3월 21일
Walter Roberson
2020년 3월 21일
Use different folders instead of always using
D = 'C:\Users\PRL\Desktop\just';
You could use uigetdir to have the user tell you the directory. Or you could look in the folder and see what subfolders already exist and use the next available one.
카테고리
도움말 센터 및 File Exchange에서 Point Grey Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!