Before the pandemic (actually a couple of years before), as I was trying to find a super easy way to show the power of a pre-trained network in MATLAB, I made this example from my desk in the office. Behind there is a "board" half of which is magnetic and the other half is cloth-covered so I can hang things with pushpins on it.
Here's a picture of me standing in front of this board, scowling at my computer screen for some reason.
And here's the code I was using. But I am not in my office now so you will see different pictures.
First set up my webcam
I first set up my webcam, and make sure it's working. You may be pleasantly surprised to learn that your webcam can be used in MATLAB Online. And I import the pretrained network alexnet.
I could try to preview the image next to be sure it's ok. I don't feel the need right now.
Next test taking a snapshot
I next test the camera by taking a snapshot
So far, so good.
Use the pretrained network to identify the picture contents
I resize that image to be the correct dimensions for alexnet. I could crop or resize it.
rect = [floor((r-height)/2), floor((c-width)/2), width-1, height-1];
[label, values] = classify(net, I227);
And put the identification label in the title.
Now let's make a collection of similar pictures
You may remember a time when you went somewhere with friends or family and used one of those photo booths to take a sequence of (often silly) pictures. Here's how I can do that in MATLAB using tiledlayout.
Finally I clean up the camera device since I'm finished using it for now. This means deleting it from MATLAB, and then clearing the variable pointing to it from my workspace.
Back to the original picture
When I did the same thing with the original picture from my office, the outcome made me laugh. Here it is.
What are some of your experiences?
I believe it's the magnets on the board that are drawing the network's focus for the prediction. Have you taken advantage of your webcam to have fun in MATLAB? Any unexpected results. Let us know here.
Copyright 2021 The MathWorks, Inc.