How To Scan QR Codes With A Raspberry Pi + OpenCV + Python

Поделиться
HTML-код
  • Опубликовано: 19 июн 2024
  • All scripts dived into here will display decoded QR data live, one will also capture the information into a text file and the final will use specific QR codes to control the GPIO.
    Full Article - core-electronics.com.au/tutor...
    Make sure to use the Previous Raspberry Pi 'Buster' OS with this Guide.
    Related Information
    QR Code Creator - www.the-qrcode-generator.com/
    Flashing 'Buster' OS onto a Raspberry Pi - core-electronics.com.au/tutor...
    Facial Recognition Raspberry Pi - core-electronics.com.au/tutor...
    Object and Animal Recognition With Raspberry Pi - core-electronics.com.au/tutor...
    Hand Tracking & Gesture Control With Raspberry Pi - core-electronics.com.au/tutor...
    Use Your Phone to Control Your Raspberry Pi - core-electronics.com.au/tutor...
    Speed Camera Raspberry Pi - core-electronics.com.au/tutor...
    Terminal Commands
    sudo apt-get update
    sudo apt-get install python3-opencv
    sudo apt-get install libqt4-test python3-sip python3-pyqt5 libqtgui4 libjasper-dev libatlas-base-dev -y
    pip3 install opencv-contrib-python==4.1.0.25
    sudo modprobe bcm2835-v4l2
    Cameras in combination with machine learning create the most powerful sensor you can ever put on a Raspberry Pi. Open-CV is a huge resource that helps solve real-time computer vision and image processing problems. To install it and the other required packages it is best done by typing and entering the above 5 lines into the Raspberry Pi Terminal. This guide focuses on QR (Quick Response) Codes. These are absolutely everywhere in our modern world and for great reason. Sharing a lot of similarities to barcodes, but instead of a laser, a camera is used to identify spaces between black and white squares markings. Encoding data this way is incredibly useful and, with machine learning, it has never been easier to decode their secrets. There are lots of standards and types of QR codes but this system will work with all common types.
    If you have any questions about this content or want to share a project you're working on head over to our maker forum, we are full time makers and here to help - coreelec.io/forum
    Core Electronics is located in the heart of Newcastle, Australia. We're powered by makers, for makers. Drop by if you are looking for:
    Raspberry Pi 4 Model B (4GB) Ultimate Kit Bundle (AVALIABLE!) - core-electronics.com.au/raspb...
    Raspberry Pi 4 Model B 4GB (Used Here): core-electronics.com.au/catal...
    Raspberry Pi High Quality Camera (Used Here): core-electronics.com.au/catal...
    Raspberry Pi 6mm Wide Angle Camera Lens: core-electronics.com.au/catal...
    Raspberry Pi Official Camera Module V2 : core-electronics.com.au/catal...
    Great Electronic Starter Kit by Kitronik (Breadboard, LEDs, Resistors + heaps more): core-electronics.com.au/catal...
    Raspberry Pi 4 Power Supply: core-electronics.com.au/catal...
    0:00 Intro
    0:19 QR Code Overview
    0:43 Creating Custom QR Codes
    0:56 Open-CV
    1:10 What You Need and Terminal Commands
    1:58 Hardware Build
    2:27 Code Download Location
    2:44 Simple Code
    3:14 Data Record Code
    3:55 GPIO Control Code
    4:45 The Pay Off
    5:06 Where to Now
    5:24 Outro

Комментарии • 63

  • @simonvillada
    @simonvillada 2 года назад +1

    Amazing! I think its the best video tutuorial I have ever seen!

  • @hackerr2656
    @hackerr2656 2 года назад +1

    amazing, thanl you! 👍👍

  • @karique01
    @karique01 2 года назад

    is it possible to modify your source code so that it only recognizes qrs and barcodes in pairs (which will be very close together)?

  • @DarrylAdams
    @DarrylAdams 2 года назад +2

    I have not been to our makers space for a while (Covid was only part of the reason *sad*) but the boom gate we had was triggered by a pi accessing a remote control button. This could be even better as it could log details of each member. Interesting if you could use one pi to scan then broadcast to another so that the remote can be protected so people don't push the remote button...

    • @Core-Electronics
      @Core-Electronics  2 года назад

      That would be awesome! I'd love to see that 🙂

  • @syaduinotech3681
    @syaduinotech3681 2 года назад +3

    Superb, simple and clearly explain videos. Will try it for sure.. start with the pi zero.. hopefully its working. Anyway, hope author can also create content, how to record this qr code into the google sheet. Will be very useful for making attendance for my students. Tq sir

    • @jyvben1520
      @jyvben1520 2 года назад +1

      pi zero is probably not powerful enough, that is why the video used a pi 4b (4 cores at 1500 mhz)

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Glad you liked it, you could import the CSV file from the second example directly into Google sheets.

    • @lachyborne4684
      @lachyborne4684 2 года назад +1

      @@jyvben1520 Manged to get this and also facial recognition with a tensor flow model working on a pi zero w. It runs, but a bit slowly, really depends on what your use case is for anyone else attempting it!

  • @user-nz2op9zl3r
    @user-nz2op9zl3r 9 месяцев назад

    You are the best

  • @rogeriohartungtoppa3109
    @rogeriohartungtoppa3109 Год назад

    Do you know how to read micro qrcode using python? If is possible, could you make a video to explain the steps to create a script? Thanks from Brazil!

  • @franciscruz5759
    @franciscruz5759 8 месяцев назад

    hello, can i do this without any problem in raspberry pi lower versions like 3-1?

  • @PusherAtUrDoor
    @PusherAtUrDoor 2 года назад +1

    Hey! great video! just what I needed! all works as showed, however my camera is having a 5 -10 second delay. im using raspberry pi 3B+ (1gb) and rasp pi cam V1.3. What could be the issue, what do you think? Not enough ram?

    • @Dan070
      @Dan070 2 года назад +1

      Hey. I'm doing the same thing. You've already said the answer in short. OpenCV is HEAVY for a rpi. Pi 4 you can have more fps... but pretty much im getting 1 or 0.5 fps when using a camera + opencv on 3b.

    • @Core-Electronics
      @Core-Electronics  2 года назад

      The only issue with this type of computer vision is the computational power required to do it. Definitely using the slightly slower Raspberry Pi 3B+ is the issue here.

  • @asangalo
    @asangalo 2 года назад +1

    Really great video! Congrats! Can you tell me what best cost-benefit relation camera to read a qr-code of 6 x 6 inches from 5 meters of distance?

    • @Core-Electronics
      @Core-Electronics  2 года назад

      To manage that 5 Meters of distance I would want to use a lens I could zoom in with. Something like the Telephoto Camera Lens in combination with the HQ Camera Module. Linked both here - core-electronics.com.au/catalog/product/view/sku/CE06936 & core-electronics.com.au/catalog/product/view/sku/CE06935

  • @Fraunzi
    @Fraunzi 2 года назад +4

    Can you please make a face tracking pan tilt raspi camera tutorial? Love these videos!

    • @Core-Electronics
      @Core-Electronics  2 года назад +1

      Absolutely, next weeks episode will cover that very topic. 👍

    • @Fraunzi
      @Fraunzi 2 года назад +1

      You guys are AWESOME!

  • @thejopal7111
    @thejopal7111 2 года назад +1

    Great video! Is there a way to stop getting multiple readings of the same QR code stored in the csv? The text file currently does not store the data even though it is displayed in Thonny. Is there a way to fix this?

    • @Core-Electronics
      @Core-Electronics  2 года назад

      So there are three codes in the download section. The CSV code will store and save the data to the text file. Just open the text file once you have stopped the code.
      To stop multiple readings of the same QR Code you will need to alter the code slightly by adding an If statement. That way when it see the same QR code it will ignore it.

  • @Marc-qf8bs
    @Marc-qf8bs 2 года назад +1

    Thanks for the great video. Everything worked so far. I would also like to read in a data matrix code with your program. Unfortunately it doesn't work, can you help me?

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Nice mate! Glad the system is working for you. Because data matrices are encoded differently from QR codes the library we are using here won't understand them. However the | libdmtx | is purpose built to decode data matrices and is exactly what you should use.
      To incorporate this new library into Open-CV code have a look at this example - stackoverflow.com/questions/59989893/datamatrix-with-raspberry

  • @excellent_self_2294
    @excellent_self_2294 2 года назад +2

    Thanks for the video. I had a bit of an issue using the buster legacy image from pi imager (released 2022). The installation work but when using it in python (same way as your code), it doesn't work, it returns error : vidioc_qbuf invalid argument. Some sources said to increase gpu mem to 128 or even 144 but that didn't work.
    I reinstalled your image (from link) this time when doing sudo modprobe bcm2835-v4l2: it doesn't work (error : fatal, not found).
    can you please guide me to solve this issue, I have been struggling for weeks with the csi camera, given that my code was tested on ubuntu server and didn't work because of csi camera issue.
    Thanks :)

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Totally interesting errors. Come make a comment at the bottom of the full write up article with some screenshots of your errors. I'll best be able to help you get your system up and running that way 😊

  • @kingkringe5090
    @kingkringe5090 2 месяца назад

    i tryed this reciently w the new bookworm os but it seems the camera code is all broken/dependencys failed to install ;c, gonna try with the old OS

  • @brawlstrso1732
    @brawlstrso1732 2 года назад +2

    Hey, would I be able to connect the cables to the GPIO pins and light up the LEDs without using a breadboard? I only have cables and resistors

    • @Core-Electronics
      @Core-Electronics  2 года назад

      If you have a steady hand you can always solder this set up together, eliminating the need for the breadboard.

  • @sidraines
    @sidraines 2 года назад +1

    Love the video. Can the same set up work for normal barcodes?

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Absolutely and the code will be simpler. Have a look at what the OpenCV team has created - opencv.org/recognizing-one-dimensional-barcode-using-opencv/

  • @waledkhaled5439
    @waledkhaled5439 2 года назад +1

    very nice video .. can i do this on a streaming live video ?

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Any video feed that you can get into the Raspberry Pi can have this computer vision system evaluate it 😊 you may just have to tinker with the code. Then that information can be sent out of the Raspberry Pi in all different ways.

  • @abdurrazzak1612
    @abdurrazzak1612 Год назад +1

    u are awesome.

  • @terantejhastine
    @terantejhastine Год назад +1

    Is it possible to read the QR code that contains Pdf file url link from our database and print it immediately (just make sure the printer is connected to the raspberry pi)

    • @Core-Electronics
      @Core-Electronics  Год назад +1

      You should definitely be able to do that. I've been searching around for Python Libraries to make interfacing to a normal printer really easy but yet to find a perfect one for a Raspberry Pi system. CUPS may be what you need (along with some script writing) - www.cups.org/doc/overview.html

    • @terantejhastine
      @terantejhastine Год назад +1

      @@Core-Electronics Thanks, cause I've been watching a lot of videos about CUPS now. I will use a raspberry pi camera module 2 to scan the qr code using OpenCV . My only concern is what will be content of that qr code. I'm thinking if i can put a task/instructions on the qr code (that orders to print the file associated on it once scanned)

    • @Core-Electronics
      @Core-Electronics  Год назад +1

      QR Codes can Definitely Link to Websites which can then have the desired subject to be printed. Then all the orders/instructions to do the printing can be running on a Python script operating in the background.

    • @terantejhastine
      @terantejhastine Год назад +1

      @@Core-Electronics Thanks I'll comeback here once I made progress.

    • @Core-Electronics
      @Core-Electronics  Год назад

      Hit up our Forum if you need any extra help! Much easier for us to help you there 😊 You'll be able to send through pictures - forum.core-electronics.com.au/

  • @electronicsnoobject3545
    @electronicsnoobject3545 2 года назад +1

    I'm newbie and have problem installing library like this:
    "Package libqtgui4 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsolete, or is only available from another source".
    Can you help me? please

    • @Core-Electronics
      @Core-Electronics  2 года назад +1

      I absolutely can. Your problem is arising because currently there is compatability issues between Open-CV and the new 'Bullseye' OS. Flash and utilise the previous 'Buster' OS and you won't have this issue. core-electronics.com.au/tutorials/flash-buster-os-pi.html

    • @electronicsnoobject3545
      @electronicsnoobject3545 2 года назад

      @@Core-Electronics thankyou so much bro. it works🙏

    • @HaloHaunter360
      @HaloHaunter360 Год назад

      @@Core-Electronics if one does this, should they avoid using the get apt update and upgrade? will they just update it back to bullseye?

  • @nadavfedida2200
    @nadavfedida2200 2 года назад

    Really nice tutorial, just noticed i'm getting an error with "libqtgui4: saying not available. currently have Rpi4b os-version 11(bullseye). Any suggestions how to overcome this?

    • @nadavfedida2200
      @nadavfedida2200 2 года назад +1

      "E: Unable to locate package libqt4-test
      E: package 'libqtgui4' has no installation candidate"

    • @Core-Electronics
      @Core-Electronics  2 года назад +1

      Hey mate, perhaps the library has been updated. Try running this command | sudo apt-get install libqt5gui5 libqt5webkit5 libqt5test5 | and tell me how you go

  • @kysevader
    @kysevader 2 года назад

    If I didn't want a Camera , but rather to screenshare a QR code , what would I do? Get rid of the webcam but still gain the data off of, the QR code

  • @ssj5omar
    @ssj5omar 2 года назад +1

    I am getting Unable to locate package python3-opencv~ when trying to apply the install python3-opencv command. I am using raspberry pi zero W. Searched everywhere to fix this and nothing. Anyone have an idea?

    • @ssj5omar
      @ssj5omar 2 года назад +1

      Going to trying using Buster OS. Hopefully this fixes it.

    • @ssj5omar
      @ssj5omar 2 года назад

      pip3 install opencv-contrib-python==4.1.0.25
      sudo modprobe bcm2835-v4l2. Now these two aren't working but i got this far at least. For the pip install im getting a "THESE PACKAGES DO NOT MATCH THE HASHES FROM REQ...." error. I have tried deleting the cache directory and specifying no cache directory to no avail.
      And for the sudo modprob command im getting a "modprobe: FATAL: module bcm2835-v412 not found in directory /lib/modules/5.10.17. Im guessing that one depends on the previous command?

    • @Core-Electronics
      @Core-Electronics  2 года назад

      100% that will sort you, I rebuilt this yesterday to confirm continued full operation and all was well

    • @ssj5omar
      @ssj5omar 2 года назад

      @@Core-Electronics Thanks alot for the reply I appreciate it! Did you see my most recent message? Im getting a "THESE PACKAGES DO NOT MATCH HASES FROM.." error when trying to use pip3 install opencv-contrib-python==4.10.25. This is after using Buster OS. Any ideas or tips?

  • @shreyadhume8906
    @shreyadhume8906 2 года назад +2

    Hello,
    I am getting this error :
    Overload resolution failed: > - Can't parse 'pt1'. Sequence item with index 0 has a wrong type

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Sounds to me like it can't locate the camera. What kind of camera are you using with this system? Also what version of Raspberry Pi OS are you using? I highly recommend using the older 'Buster' Raspberry Pi OS for this application. Come pop me a comment at the bottom of the full article page if you keep running into issues.

    • @shreyadhume8906
      @shreyadhume8906 2 года назад +1

      @@Core-Electronics I'm using buster. And NoIR camera.

    • @Core-Electronics
      @Core-Electronics  2 года назад

      Cheers mate, type and enter the following into a new terminal window.
      raspistill -t 0
      If that doesn't open up a camera feed straight away (which you can close with CTRL-C) then double check that the camera is enabled in the Raspberry Pi Configuration Menu and that all the ribbon cables are connected securely and are right way around. If that doesn't fix it come jump onto our Core Electronics Forum as we can help you better there.

    • @coreelectronicssupportteam6775
      @coreelectronicssupportteam6775 2 года назад +1

      ​@@Core-Electronics Went through and checked it, I have it working over here. The problem could be to do with the v4l driver. That happens when you type and enter the below into your terminal.
      sudo modprobe bcm2835-v4l2

    • @shreyadhume8906
      @shreyadhume8906 2 года назад

      @@Core-Electronics camera is working, when I run the code it pops up the preview window but I'm getting that error. Also, don't know how to start new topic on core electronics forum.