- Initializes webcam
- Runs infinite while loop that exits when q is pressed
- Within while loop:
- Checks for 'q' keypress
- Captures and image and resizes the image
- Classifies the image
- Updates figure to display current image and classification label
classifyVideo function does not work on Mac
2 次查看(过去 30 天)
显示 更早的评论
I am trying this example of Transfer Learning "Deep Learning: Transfer Learning in 10 lines of MATLAB Code".
All the given code works. But when I try to classify objects in live video using Macbook cam (as shown in the end of this video), the classifyVideo(myNet) function gives an error "Unrecognized function or variable 'classifyVideo'."
Can somebody tell me how I can classify objects using live cam on Macbook?
0 个评论
回答(1 个)
Prabhan Purwar
2020-7-15
Hi,
You can recreate the functionality by writing your own function which takes as input the network obj and performs the following tasks:
A sample function "classifyVideo.m" is pasted below for your reference:
function [] = classifyVideo(net)
% Initialize webcam
cam = webcam;
% Initialize figure
hf = figure;
while 1
% compares the current character to q
% if 'q' is pressed exit
if strcmp(get(hf,'currentcharacter'),'q')
close(hf)
break
end
% Acquire a single image
rgbImage = snapshot(cam);
% Resize image to fit AlexNet dimensions
resizedImage = imresize(rgbImage, [227 227]);
% Classify Image
label = classify(net,resizedImage);
% Display the image.
imshow(rgbImage);
% Display label
title(label);
% Update figure
hold on;
drawnow
% force the event queue to flush
figure(hf)
drawnow
end
% Clear camera object
clear('cam');
end
You can quickly test the function using the following:
>> net = alexnet;
>> classifyVideo(net) ;
You will have to install the "MATLAB Support Package for USB Webcams" from Add-On Explorer to be able to use the "webcam" command in the function.
More information about webcam use with MATLAB can be found here:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!