Import video, read edge barcode and export a file with barcode information

2 ビュー (過去 30 日間)
Stephen Marsden
Stephen Marsden 2024 年 2 月 9 日
回答済み: Yatharth 2024 年 2 月 29 日
I have video that has time and orientation of the camera (azimuthh and elevation) written on each image in text. The same information is also in a barcode at the left edge of each image. I don't know the code, but I might be able to figure it out by comparing the barcode data to the image text. I need code that will select the video file and create a file with the barcode information. What would be the best approach?

回答 (1 件)

Yatharth
Yatharth 2024 年 2 月 29 日
Hi Stephen,
I understand that you want to extract information from both text and barcodes in a video.
I can suggest a high-level outline how you can acheive this.
Here are the general steps.
  1. Extract frames from the video at a certain frame rate.
  2. Apply Optical Character Recognition to the extract frames to read the time and camera orientation. You can use the 'ocr' funtion to recognize text using OCR. Here is the documentation for the same. https://www.mathworks.com/help/vision/ref/ocr.html
  3. Decoding the barcode data. You can refer to the documentation for the 'readBarcode' function here. https://www.mathworks.com/help/vision/ref/readbarcode.html
  4. Compare the extracted data with barcode data.
  5. Storing the extracted data in a file.
You may use this code as a template.
% Step 1: Video Frame Extraction
videoFile = 'path_to_your_video_file.mp4';
videoReader = VideoReader(videoFile);
frameRate = videoReader.FrameRate; % Or choose your own frame rate
% Step 2: Text Recognition (OCR)
ocrResults = [];
barcodeResults = [];
while hasFrame(videoReader)
frame = readFrame(videoReader);
% Step 3: Perform OCR on the entire frame (or a specific region if known)
textData = ocr(frame);
ocrResults = [ocrResults; textData];
% Step 4: Barcode Decoding
% Assuming the barcode is on the left edge of the frame
barcodeRegion = frame(:, 1:barcodeWidth, :); % Define barcodeWidth appropriately
barcodeData = readBarcode(barcodeRegion);
barcodeResults = [barcodeResults; barcodeData];
% Optional: Compare and analyze the data
% This step would depend on how the text and barcode data are structured
% and would require custom logic to match and verify the data.
% To process frames at a lower rate, you can add a pause or a frame skip logic here
end
% Step 5: Data Storage
% Save the results to a file
save('barcodeData.mat', 'barcodeResults');
% Optionally, save OCR results or combined data as needed
I hope this is what you were expecting.

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by