Barcode detection by webcam.

15 Ansichten (letzte 30 Tage)
Duc Do Minh
Duc Do Minh am 18 Dez. 2015
Kommentiert: Walter Roberson am 19 Dez. 2015
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 18 Dez. 2015
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 Kommentare
Duc Do Minh
Duc Do Minh am 19 Dez. 2015
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 am 19 Dez. 2015
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by