Barcode detection by webcam.

조회 수: 13 (최근 30일)
Duc Do Minh
Duc Do Minh 2015년 12월 18일
댓글: Walter Roberson 2015년 12월 19일
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

채택된 답변

Walter Roberson
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.
You can see snapshot() being used in this Computer Vision demo
  댓글 수: 2
Duc Do Minh
Duc Do Minh 2015년 12월 19일
Thank you very much! but Does "snapshot()" trigger or delay video output display? I want to make a live analysis and show the video through a figure and barcode is detected and encode in background, only the result can be showed in the figure or the code is showed in Command Window.
Walter Roberson
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 CenterFile Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by