Implementing Product Visual Search
A picture is worth a thousand words. See how to turn pictures into product information for users.
Join the DZone community and get the full member experience.Join For Free
We will capture a product image from our developed shopping application using a device camera.
- We will show the returned products list.
Java JDK 1.8 or higher is recommended.
Android Studio is recommended.
Huawei Android device with HMS core 220.127.116.110 or higher.
Before developing an app, you will need to register as a HUAWEI developer.
Integrating the App Gallery Connect (AGC) SDK.
1. Enable the ML kit in Manage APIs.
2. Integrate the following dependencies in the app-level build.gradle.
3. Add the AGC plugin at the top of the app.gradle file.
4. Add the following permissions in the manifest.
Camera permission: android.permission.CAMERA: Obtains real-time images or videos from a camera.
Internet access permission: android.permission.INTERNET: Accesses cloud services on the Internet.
Storage write permission: android.permission.WRITE_EXTERNAL_STORAGE: Upgrades the algorithm version.
Storage read permission: android.permission.READ_EXTERNAL_STORAGE: Reads photos stored on a device.
5. To request camera permission in realtime.
6. Add the following code in the Application class
The API key can be obtained either from AGC or the integrated agcconnect-services.json.
7. To create an analyzer for our product visual search.
8. To capture an image from a camera.
9. Once the image has been captured, the onActivityResult() method will be executed.
The onSuccess() callback will give us a list of MLProductVisionSearch objects, which can be used to get the product id and image URL of each product. Also, we can get the product type using productVisionSearch.getType(). getType(), which returns numbers that can be mapped.
10. We can achieve the product type mapping with the following code.
11. To get product id and image URL from MLVisionSearchProductImage.
Opinions expressed by DZone contributors are their own.