- 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!