Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use raspberry pie 4+OLED+USB camera to build bar code scanning equipment

Shulou Source: shulou.com Published: 2022-06-01 22:44:03 10月31日 Update

Editor to share with you how to use raspberry pie 4+OLED+USB camera to build barcode scanning equipment, I hope you will learn something after reading this article, let's discuss it together!

Raspberry pie 4 related hardware purchase

The 4GB version of raspberry pie 4. The official price is $65, JD.com 300 minus 40 to $389.

Micro HDMI to HDMI line. Raspberry pie 4 has changed its power port.

HDMI female to female adapter. Used to extend the HDMI line.

Raspberry pie smart butler. Contains programmable fan, RGB lights and OLED display module.

System installation

Download the official system https://www.raspberrypi.org/downloads/ on the official website.

Use Win32 Disk Imager to write the image to sdcard.

Insert the card into raspberry pie 4 and connect the power supply. Note: the power supply is at least 3A output, do not casually connect the USB interface for power supply.

System configuration

Turn on I2C, VNC, and SSH.

To connect remotely through Windows, you can install tightvncserver and xrdp:

Sudo apt updatesudo apt install tightvncserver xrdp

Next, check to see if there is enough disk space:

Df-HFilesystem Size Used Avail Use% Mounted on/dev/root 32G 8.9G 21G 30% / devtmpfs 1.9G 0 1.9G 0% / devtmpfs 2.1G 0 2.1G 0% / dev/shmtmpfs 2.1G 9.1m 2.1G 1% / runtmpfs 5.3M 4.1k 5.3m 1% / run/locktmpfs 2.1g 0 2.1G 0% / sys/fs/cgroup/dev/mmcblk0p1 265M 54M 211M 21% / boottmpfs 405M 4.1k 405m 1% / run/user/1000

If the sdcard storage space is not fully utilized, you can configure it through raspi-config:

Sudo raspi-config

Install OpenCV

OpenCV is used to open the camera to obtain video frames.

Download the latest version of source code: https://github.com/opencv/opencv/releases

Install all dependent packages:

Sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libjpeg-dev libpng-dev libtiff-dev

Compile and run (it takes a few hours here, very slowly):

Mkdir buildcd buildcmake-DCMAKE_BUILD_TYPE=Release-DCMAKE_INSTALL_PREFIX=/usr/local-DOPENCV_GENERATE_PKGCONFIG=ON.. make-j4sudo make installC/C++ code

Download the raspberry pie version of Dynamsoft Barcode Reader SDK: https://www.dynamsoft.com/Downloads/Dynamic-Barcode-Reader-Download.aspx

Create a CMakeLists.txt file. Add libDynamsoftBarcodeReader.so, OpenCV-related libraries, and WiringPi required for compilation links:

Link_directories ("${PROJECT_SOURCE_DIR} / platforms/linux/") find_package (OpenCV REQUIRED) include_directories ("${PROJECT_BINARY_DIR}"${PROJECT_SOURCE_DIR} / include/") add_executable (BarcodeReader ssd1306_i2c.c BarcodeReader.cxx) target_link_libraries (BarcodeReader "DynamsoftBarcodeReader" ${OpenCV_LIBS} wiringPi)

Use OpenCV to obtain camera video stream:

# include # include Mat frame;VideoCapture capture (0); for (;;) {int key = waitKey (10); if ((key & 0xff) = = 27/*ESC*/) break; capture > > frame; / / read the next frame from camera if (frame.empty ()) {cerr resultsCount; iIndex++) {snprintf (pszTemp, 4096, "Barcode% d:\ r\ n", iIndex+ 1); printf (pszTemp) Snprintf (pszTemp, 4096, "Type:% s, Value:% s\ r\ n", pResults- > results [iIndex]-> barcodeFormatString, pResults- > results [iIndex]-> barcodeText); printf (pszTemp); draw_OLED (pszTemp);} free (pszTemp); CBarcodeReader::FreeTextResults (& pResults);} CBarcodeReader reader;int iRet = reader.InitLicense ("LICENSE-KEY"); reader.SetTextResultCallback (textResultCallback,NULL); capture > > frame Int width = capture.get (CAP_PROP_FRAME_WIDTH); int height = capture.get (CAP_PROP_FRAME_HEIGHT); iRet = reader.StartFrameDecoding (10,10, width, height, frame.step.p [0], IPF_RGB_888, "); for (;;) {int key = waitKey (10); if ((key & 0xff) = = 27/*ESC*/) break; capture > > frame / / read the next frame from camera if (frame.empty ()) {cerr

Tags: Raspberry camera camera system bar bar code power program compile run device official interface version space article video configuration next code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Shulou Technology Shulou Tech Info Apple