Barcode recognition on an image
Last updated
Last updated
You can use this for creating a bot that scans product codes. A useful feature is the fact that it can also scan QR-codes
The address of the function that recognizes a barcode on an image is https://store.salebot.ai/function/cv2barcode
To scan an image you need to sends these parameters from the block:
{"photo":"the link to the barcode/QR-code or the variable with the link","api_key":"api access key from the settings"}
For example, to send an image for scanning you need to send these parameters:
In the arrow in the field “User enters data” enter the variable #{attachments}.
An example of the code
{"photo":"#{attachments}","api_key":"8629fe13ba9efebefd27a7afd701767f"}
Where “photo” is a link to the barcode image, in our case it’s the variable that holds the link to the image that was sent to the bot.
The next parameter is api_key - API access key from the project’s settings
The function works like this:
The client sends a picture of the barcode, the function demands for it to get scanned and, if successful, it sends the barcode as a number and the operation status equals “ok”
barcode -> "4500000000567" status -> "ok"
The status of scanning can be:
ok - the barcode was recognized
barcode not recognized - as you could’ve guessed, the barcode was not recognized
error image reading - again, self explanatory
error subscription - this functionality isn’t available to your type of subscription
The variable status can be set as a condition on an arrow and can send the client to the appropriate block
For example, if an arrow has a condition of the variable “status” and the value of “barcode not recognized” then we display the message “The code wasn’t recognized, try again” and send a second request for the photo.