error in image capture

3 views (last 30 days)
barath V
barath V on 3 Mar 2020
Commented: barath V on 3 Mar 2020
iam getting this error always,i dont know what this error means and how to fix it?
error: Undefined function or variable 'CAMERA'.
img = im2double(getsnapshot(CAMERA)); %captures images
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()
pause(10)
end
plot(value); %plotting values just for our visual understanding
[m,index] = max(value)
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()
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);
value(k) = bodekke(F); %bodekke function call
end
end

Answers (1)

Walter Roberson
Walter Roberson on 3 Mar 2020
function automate()
need to be
function automate(CAMERA)
and your line
automate()
Needs to be
automate(CAMERA)
  1 Comment
barath V
barath V on 3 Mar 2020
hi it worked thanks,but iam having another problem now.
error: Error using imaqdevice/getsnapshot (line 65)
A timeout occurred during GETSNAPSHOT.
img = im2double(getsnapshot(CAMERA)); %captures images

Sign in to comment.

Categories

Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!