0. 참고 자료
https://kr.mathworks.com/help/deeplearning/ug/classify-images-from-webcam-using-deep-learning.html
딥러닝을 사용하여 웹캠 영상 분류하기 - MATLAB & Simulink - MathWorks 한국
이 예제의 수정된 버전이 있습니다. 사용자가 편집한 내용을 반영하여 이 예제를 여시겠습니까?
kr.mathworks.com
1. 스냅샷만 확인
camera = webcam; net = googlenet; inputSize = net.Layers(1).InputSize(1:2) figure im = snapshot(camera); image(im) im = imresize(im,inputSize); [label, score] = classify(net, im); title({char(label),num2str(max(score),2)}); |
2. 연속 화면으로 확인
h = figure; while ishandle(h) im = snapshot(camera); image(im) im = imresize(im,inputSize); [label,score] = classify(net, im); title({char(label), num2str(max(score),2)}); drawnow end |
3. 상위예측 표시하기
h = figure; h.Position(3) = 2*h.Position(3); ax1 = subplot(1,2,1); ax2 = subplot(1,2,2); im = snapshot(camera); image(ax1,im) im = imresize(im,inputSize); [label,score] = classify(net,im); title(ax1,{char(label),num2str(max(score),2)}); [~,idx] = sort(score,'descend'); idx = idx(5:-1:1); classes = net.Layers(end).Classes; classNamesTop = string(classes(idx)); scoreTop = score(idx); barh(ax2,scoreTop) xlim(ax2,[0 1]) title(ax2, 'Top 5') xlabel(ax2, 'Probability') yticklabels(ax2,classNamesTop) ax2.YAxisLocation = 'right'; |
4. 영상 연속 분류 후 상위예측 표시
h = figure; h.Position(3) = 2*h.Position(3); ax1 = subplot(1,2,1); ax2 = subplot(1,2,2); ax2.PositionConstraint = 'innerposition'; while ishandle(h) % 이미지의 화면표시 및 분류 im = snapshot(camera); image(ax1,im) im = imresize(im,inputSize); [label,score] = classify(net,im); title(ax1,{char(label),num2str(max(score,2))}); % 예측결과 상위 5개 선별 [~,idx] = sort(score,'descend'); idx = idx(5:-1:1); scoreTop = score(idx); classNamesTop = string(classes(idx)); % 히스토그램의 플로팅 barh(ax2,scoreTop) title(ax2,scoreTop) xlabel(ax2,'Probability') xlim(ax2,[0 1]) yticklabels(ax2,classNamesTop) ax2.YAxisLocation = 'right'; drawnow end |