Matlab finds webcam, but says after running the code it is invalid
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
1 vote
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!
Accepted Answer
Khalid Mahmood
on 1 May 2021
1 vote
try these 3 commands:
1) clear all
2) imaqreset
3) Then a) cam =webcam b) preview cam
8 Comments
Khalid Mahmood
on 1 May 2021
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
Mohammad Ali
on 1 May 2021
This works great for me
Marlene Patterer
on 2 May 2021
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!
Khalid Mahmood
on 2 May 2021
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
Khalid Mahmood
on 2 May 2021
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.
Khalid Mahmood
on 2 May 2021
Easiest solutin is :
clear cam; %close previous connections
cam=webcam;
Marlene Patterer
on 2 May 2021
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!
Khalid Mahmood
on 3 May 2021
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
More Answers (0)
Categories
Find more on Share and Distribute Software in Help Center and File Exchange
Tags
See Also
on 1 May 2021
on 3 May 2021
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)