Libraries are spaces where people of all ages can practice lifelong learning. The existence of libraries ensures that knowledge and technology are available to everyone. And of course, we are all familiar with libraries. In the past, we used to borrow books in the library by using a special library card that contains our personal information. Well, now it's more convenient, a QR code or student ID card is enough. In this chapter, we are going to build up a small book borrowing & returning system based on HuskyLens.
Let's recall the process of borrowing books, as shown below.
Flow chart of book borrowing in a library:
We will use the tag recognition function of HUSKYLENS to create a system that can realize the book borrowing and returning books through QR code.
In this project, we are going to learn about the tag recognition function of HUSKYLENS, using its built-in machine learning function to distinguish learned tags. And here we're not going to introduce how to input the information to a tag. Assuming that there is a tag containing our information, by which we can borrow and return books after entering the system. Through the function of SIoT, the time of borrowing and returning books will be recorded and sent to the administrator to realize the function of remote monitoring.
When borrowing books, whether by manual or self-service borrow and return, we need to scan the barcode of the library card through the scanning device. Each borrower has its own unique barcode, so we just need to find replacements for the scanning device and barcode to build up this project.
Code scanning device -----> HUSKYLENS Tag Recognition Function
Barcode -----> April Tag
Tag recognition technology refers to the technology of effective and standardized coding and recognition of items, which is the basics of informatization. With people's increasing awareness of health and safety, the food industry has increasingly higher requirements on the quality and safety of products (from raw materials, transportation, production, storage, traceability and management). Tag recognition also plays an important role in meeting the needs of companies for product tracking and tracing.
Tag recognition technology mainly includes barcode technology, IC card technology, radio-frequency recognition technology, optical symbol recognition technology, speech recognition technology, biometric recognition technology, remote sensing, robot intelligent perception and other technologies.
AprilTags is a visual reference system from a UMich project team for AR, robotics and camera calibration. The tag acts as a barcode, storing a small amount of information (tag ID), while also providing a simple and accurate 6D (X, Y, Z, roll, pitch, yaw) pose estimation for the tag.
AprilTag recognition mainly includes the following steps:
1. Edge detection: find out the edge contour in the image.
2. Quadrangle detection: find out the quadrangles in the contour.
3. Decoding: match and check the quadrangles.
Through these steps, the tag recognition function of HUSKYLENS can recognize different AprilTags. So, we just need to put different AprilTags on different commodities for recognition.
1. Tag Detecting
When Huskylens detects a tag, the tag will be automatically selected by the white frame on the screen.
2. Tag Learning
Point the "+" symbol at the tag, long or short press the "Learning button" to complete the first tag learning. After releasing the "study button", the screen will display: "Press the button again to continue! Press other buttons to end. " To continue learning the next tag, press the "Learning button" before the countdown ends. If you no longer need to learn other tags, press the "Function button" before the countdown ends, or do not operate and wait for the end of the countdown.
The tag ID is consistent with the sequence of inputting, that is, the learned tags will be labeled as "tag: ID1", "tag: ID2", "tag: ID3", and so on, and the frame color corresponding to different tags is also different.
3.Recognition the tag
When the HuskyLens encountered the learned tags, a colored frame with an ID will be automatically displayed on the screen. The size of the frame changes along with the size of the QR code tag and the frame will automatically track these QR code tags.
After learning the tag recognition function of HUSKYLENS, let's see how to design the book borrowing system. The first function to be realized is to make the camera able to recognize different tags. Each tag represents an individual borrower. Here, we define a variable to represent the number of books borrowed. Borrower A is a borrower. The LCD will show our operations in real-time. However, book returning is also contained in the system, so we need to use a button to switch the mode, and realize remote monitoring through the IoT module.
Task 1: Realize the function of book borrowing and returning
In this step, we are going to learn how to use HUSKYLENS to learn the tags. If the tags have already been learned, we can borrow and return the books.
Here we set a variable, through the change of variable to determine whether to borrow or return the book. For book borrowing, in the beginning, each person can borrow no more than two books. When reaching the upper limit, the books need to be returned before the next borrowing. Then, for book returning, the basis of book return is that we have borrowed books (so we should set the number of borrowed books to 1 or 2 initially). The change in the number of borrowed and returned books can be displayed on the screen in real-time.
Task 2: Realize function switching
After completing the function of borrowing and returning books, we need to integrate them, so we need a button to switch the mode between book borrowing and returning.
Task 3: Realize remote monitoring function
After finishing the above functions, we may keep a record of the date of book borrowing and returning, as well as remind the administrator of the possibility that some books may be out of stock. To realize these functions, we can use IoT module to set up a remote monitoring system.
HUSKYLENS: I2C Pin (T-SDA, R-SCL, + —5V, - —GND)
Button: Digital Pin 4
IoT module: UART Port (T-RX (green line), R-TX (green line), + —VCC, - —GND), unplug RX when uploading program, plug after successful upload.
LCD Display: I2C Pin (SDA—SDA, SCL—SCL, VCC—5V, GND—GND)
We need to realize the book borrowing and returning of Borrower A through tag scanning of HUSKYLENS. So, we create a variable,“number of the borrowed book”, and set its initial value to 0 (indicating that there is no borrowing or returning operation). And the maximum number of borrowed books can be set to 2, which means that each person can borrow up to two books at the same time. IWhen using HUSKYLENS to scan the AprilTag code, the LCD will display the value of the "number of borrowed books" in real-time. Each scan will increase the number of borrowed books by 1. When the number of borrowed books reaches 2, the display "need to return". When the book is returned, the "number of borrowed books" will be reduced by 1 each time the QR code is scanned. When there is no book to return, it will prompt "No return"
Step1: Mind+ software settings
Open Mind+ software (version1.6.5), switch to "Offline", click "Extensions", choose “Arduino Uno” under “Board”, click "HUSKYLENS AI Camera" under "Sensor", click "OBLOQ IOT Module" under "Communication", and click "LCD1602 module" under "Display".
Step2: Instruction learning
Let's look at some of the main instructions.
Step3: Flow chart analysis
1) Sample program of book borrowing: the initial value of "number of books borrowed” needs to be set to 0.
2) Program of book returning: set the initial number of borrowed books to 1 or 2.
When the sample program (1) is selected, and the HUSKYLENS recognizes the AprilTags code, book borrowing can be achieved. When the learned tags is scanned, the screen will display "YES" (the screen can only display English, the specific content can be set by yourself), indicating that the operation of borrowing books can be carried out. 3s later, the screen displays "Move the QR", indicating you need to move the tag away from the camera, and then the number of books borrowed this time will be displayed.
When the sample program (2) is selected, and HUSKYLENS recognizes the AprilTags code, returning can be achieved. When the learned tag is scanned, the screen will display "YES", indicating that it is possible to return the book. After 3s, the screen displays "move the QR", indicating the need to move the tag out of the camera, and then shows the number of books to return.
In order to combine the above codes into a project, we need a switch function. Here we choose to press the button to switch it. Logiccally, the program needs a variable to control the switch in different modes, so we set a variable called "switch function" and initialize the value to 0. 0 for borrowing mode. While 1 for returning mode. At the same time, we can improve the content displayed on the display screen to remind the borrower.
On the basis of the previous program, we add a pressing button to switch the mode. When the program is operating, the "Press button to select Status" is displayed on the screen. The default is the book borrowing mode. When a tag is scanned by the HUSKYLENS, books can be borrowed. After borrowing a book, press the button to switch the mode to return the book.
(1) Status selection
(2) Status of book borrowing
(3) State of book returning
After finishing the above designs, let’s try adding the IoT module to keep track of the time you borrow and return books. When the inventory of books is less than two, the administrator will be infromed. But how can we implement these functions? Firstly, for the time of borrowing and returning, an IoT module is enough. It can automatically record the time when the message is received, so we can use the module to generate a message when the book is borrowed or returned. After that, for the notice to the administrator, in order to be more convenient, we can set the inventory as 3 (the inventory can be set by yourselves, here we set to 3), and when it is less than 3, it will inform the administrator the shortage.
When the program is operating, it requires a successful connection of SIoT (the IoT module light turns green) before switching mode through the button. If we choose the book borrowing mode, the book borrowing can be completed when the tag is scanned by HuskyLens camera. And then the screen shows "borrow: 1", the message of "Borrower"(jieshuzhe) on the web shows "borrowed 1", and "Administrator"(guanlizhe) on the web shows "Out of stock", which exactly matches the functions we designed.
When SIoT connects successfully, a project called "Borrower"(jieshuzhe) is generated under the SIoT project.
Click "check device list" under the "Borrow"(jieshu) project to see the two messages we sent.
Click “check message” under "Borrower"(jieshuzhe).
Click “check message” under "Administrator"(guanlizhe).
In this project, we learned a new function of HUSKYLENS and basically realized book borrowing and returning (as well as display the date of the check and return), and sending messages to managers to notice them.
1. Learn the working principle of tag recognition;
2. Learn the learning process of HUSKYLENS tag recognition;
3. Learn the instructions related to HUSKYLENS tag recognition;
4. Flexible use of variables to realize different effects.
In this project, we only develop a system of book borrowing and returning for one borrower. Could you add 2 new borrowers based on this function? When you finished, think about what's missing if it's a library management system. Give it a shot!