Barcode detection by webcam.
조회 수: 13 (최근 30일)
이전 댓글 표시
I'm using 2013a version and i have a project which uses webcam to read barcode. My functions are based on a demo of Matlab vision, how could i read and decode through webcam directly, not using "getsnapshot"? I'm sorry for my bad grammar. Here is my code:
obj = videoinput('winvideo', 2,'YUY2_640x480');
set(obj,'ReturnedColorSpace','rgb');
src_obj = getselectedsource(obj);
get(src_obj);
vidRes = get(obj, 'VideoResolution');
nBands = get(obj, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
FinalCode1=0;
while (1)
ip_im = getsnapshot(obj);
imshow(ip_im);
%filter
fi_im=imsharpen(ip_im);
% Convert from RGB to Gray
gray_im= rgb2gray(fi_im);
%1
%Threshold Image to black and white
J = im2bw(gray_im, graythresh(gray_im));
%Resize and process
J=imresize(J,[240 320]);
Row = [80 120 160]';
[R,F] = Feature(J, Row);
[Center, Width, Num] = Bar(F);
[Sequence, Num] = Detection(Width, Num, 2);
[LGCode, LCode, GCode, RCode, LCodeRev, GCodeRev, RCodeRev] = Codebook;
[Code, Conf] = Recognition(Center, Width, Sequence, Num, LGCode, LCode, GCode, RCode, LCodeRev, GCodeRev, RCodeRev);
%Validation
OddSum= Code(1:1)+Code(3:3)+Code(5:5)+Code(7:7)+Code(9:9)+Code(11:11)+Code(13:13);
EvenSum = Code(2:2)+Code(4:4)+Code(6:6)+Code(8:8)+Code(10:10)+Code(12:12);
Checksums = OddSum + 3*EvenSum;
Valid = and((not(mod(Checksums,10))),(Conf >= 0.7));
FinalCode=uint64(0);
for i = 1 :13
FinalCode=FinalCode*10 + uint64(Code(i:i));
end
if and(Valid ,(FinalCode ~= FinalCode1))
Code'
sprintf('%013i',FinalCode)
FinalCode1 = FinalCode';
end
end
댓글 수: 0
채택된 답변
Walter Roberson
2015년 12월 18일
If you were using R2014a or later, instead of using getsnapshot() from the Image Acquisition Toolbox, you could use snapshot() from the USB Webcams support package.
The general purpose of getsnapshot() and snapshot() are the same: they obtain a single frame from the video feed so that the frame can be analyzed.
댓글 수: 2
Walter Roberson
2015년 12월 19일
snapshot() does not trigger or delay video output. If you are using the Computer Vision toolbox you can create whatever output image you want and then step() the array with a videoplayer object to have the image displayed.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!