Matlab finds webcam, but says after running the code it is invalid

Error "The webcam object is no longer valid. Please create a new connection to the webcam."
Please help, tried everything. Very thankful for any kind of help!

 Réponse acceptée

try these 3 commands:
1) clear all
2) imaqreset
3) Then a) cam =webcam b) preview cam

8 commentaires

Whenever clear or clear all or clear cam (where cam variable created using cam=webcam) is used, it clears reference to webcam and a fresh object has to be created again.
To create fresh object use command
cam=webcam %or any variable name you like
This works great for me
Thank you very much! That helped a lot!
Somehow I still get some other warnings like:
Warning: Unable to create an object to the specified Webcam.
> In matlab.webcam.internal/webcamDesktop/loadobj
In webcam.loadobj (line 367)
In Projekt (line 5)
Warning: Unable to restore webcam properties.
> In matlab.webcam.internal/webcamDesktop/loadobj
In webcam.loadobj (line 367)
In Projekt (line 5)
Warning: While loading an object of class 'nnet.cnn.TrainingOptionsSGDM':
'BatchNormalizationStatistics' is not an option for solver 'sgdm'.
MY CODE in "Projekt":
clc;
close all;
cam = webcam;
load myNet1;
x=0;
y=0;
height=400;
width=400;
Handbox=[x y height width];
while true
video = cam.snapshot;
Handbox_neu = insertObjectAnnotation(video,'rectangle',Handbox,'Handgeste');
video_neu = imcrop(video,Handbox);
video_neu = imresize(video_neu,[227 227]);
label=classify(myNet1,video_neu);
imshow(Handbox_neu);
title(char(label));
drawnow;
end
If you have any tips to solve these ones, I would be very thankful!
would you please attach myNet1.mat file so that I find the actual cuase of problem?
I think there may be some issue in myNet1.mat
I replaced Load myNet1 with
myNet1=alexnet; % You can use any net here, eg googlenet,vgg16, vgg19, resnet50, etc
And the code is running without issues.
If you attach myNet1.mat, I may find and resolve error.
Easiest solutin is :
clear cam; %close previous connections
cam=webcam;
Thank you!
Sadly I can not attach the myNet1 file as the system tells me that is has more than 5 MB. Even though I compressed it into a zip file, it still is too big.
If you have any idea, how I may be able to share it with you, I would be very thankful!
By replacing the load myNet1 with myNet1 = alexnet it also works for me and there are no other warnings coming up.
Thank you!
Its great that the solution is working for you.
Any how if you want to remove the error in load myNet1.mat, you can email me and attach that file in email.
Then I will tell you the actual cause of error and its remedy

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Share and Distribute Software dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by