Alibaba cloud intelligent vision AI Quick Start


Intelligent visual AI open platform is an open platform for enterprise users, software and hardware service providers and developers, providing simple, easy-to-use, high-quality visual algorithms. The platform algorithm capability has been developed and precipitated by Alibaba Damo Institute machine intelligence laboratory and multiple vision teams in the group for many years, and has been verified by Alibaba e-commerce, pan entertainment, logistics and other large-scale businesses. Through API/SDK, it provides users with visual algorithm services, which helps users integrate quickly, realize digital, intelligent transformation and product innovation.

At present, the public beta phase provides five API interfaces: vehicle type identification, animal identification and plant identification, commodity understanding: commodity label and commodity classification. The following describes the calling of related interfaces based on Alibaba cloud Java Core SDK.


1. Service opening

Service opening

2. Service call

  • 2.1 pom.xml
  • 2.2 code sample
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.apache.commons.codec.binary.Base64;

public class Demo1 {

    //The parameters of DefaultProfile.getProfile are region, access_key_id, access_key_secret
    public static DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "LTAIOZZg********", "v7CjUJCMk7j9aKduMAQLjy********");
    public static DefaultAcsClient client = new DefaultAcsClient(profile);

    public static void main(String[] args) throws IOException {

        // Everything understands
        String animalPicUrl = "";
        String vehiclePicUrl = "";
        String plantPicUrl = "";
        String animalAction = "IdentifyAnimal";
        String vehicleAction = "RecognizeVehicle";
        String plantAction = "IdentifyPlant";

        Identify(animalAction, animalPicUrl); //Animal recognition
        Identify(vehicleAction,vehiclePicUrl); // Vehicle type recognition
        Identify(plantAction, plantPicUrl); // Plant identification

        // Commodity understanding
        String prodmlabelPicUrl = ",2142400964&fm=26&gp=0.jpg";
        String prodcategoryPicUrl = ",2142400964&fm=26&gp=0.jpg";
        String prodcategoryAction = "RecognizeProdcategory";
        String prodmlabelAction = "RecognizeProdmlabel";

        Identify(prodcategoryAction, prodcategoryPicUrl); // Commodity classification
        Identify(prodmlabelAction, prodmlabelPicUrl); // Commodity label


     * Identify unified interface
     * @param imageUrl Image URL to be detected
    public static void Identify(String Action, String imageUrl) throws IOException {
        CommonRequest request = new CommonRequest();
        Base64 base64 = new Base64();
        String encodePicContent = base64.encodeToString(getFileFromUrl(imageUrl));
        request.putBodyParameter("ImageContent", encodePicContent);
        CommonResponse response = null;
        try {
            response = client.getCommonResponse(request);
        } catch (ClientException e) {

     * Read image to Byte [] through URL in oss
     * @param url Public accessible image URL
     * @return byte[]
     * @throws IOException
    private static byte[] getFileFromUrl(String url) throws IOException{
        URL urlConet = new URL(url);
        HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
        con.setConnectTimeout(4 * 1000);
        InputStream inStream = con .getInputStream();//Get picture data through input stream
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[2048];
        int len = 0;
        while( ( != -1 ){
            outStream.write(buffer, 0, len);
        byte[] data =  outStream.toByteArray();
        return data;
  • 2.3 test result
{"Data":{"Name":"Dragen-Li","Description":"The origin of civet cat is China, which belongs to natural cat. It is a kind of breed that has been eliminated by many breeds in thousands of years. People are most familiar with the story of "civet cat for Prince" (Song Dynasty). This is also the earliest record about civet cat that can be found. Therefore, civet cat has such an English name DragonLi,from CFA The cat will grant. It is very popular with the people, because it has beautiful, thick fur, healthy body. Easy to feed and good at catching mice.","SpuId":"51","Score":0.7072075},"RequestId":"3A439130-04A7-48B5-BC23-D4FC2BFBF97E"}
{"Data":{"Name":"Benz CLS level","Description":"Mercedes, a brand of German Daimler group-Mercedes Benz unveiled a new car line at the 74th Geneva auto show in 2004:CLS Class. The new 4-door sedan combines the classic proportions of a two door coupe, an appealing exterior and the comfort and functionality of a luxury car. Perfectly inherit the style of Mercedes Benz.","SpuId":2641,"Score":0.9904089},"RequestId":"60A794F2-2889-4946-8E07-D9BECA715132"}
{"Data":{"Name":"Magnolia","Description":"Yulan (scientific name: Magnolia grandiflora  L): Evergreen trees, up to 30 m in origin; bark light brown or gray, thinly scaly cracking; branchlets thick. The leaves are thick leathery, oval, oblong oval or obovate oval, dark green and glossy. Flower white, fragrant, diameter 15-20 Cm; tepals 9-12,Thick fleshy, obovate, 6 long-10 Cm, width 5-7 Centimeters. The aggregate fruit is cylindrically oblong or ovoid, the follicles are back split, the back is round, and the top side has a long beak; the seeds are nearly ovoid or ovoid, about 14 mm long, about 6 mm in diameter, and the exotesta is red, except the seeds of the exotesta, the top is extended into a short neck. Florescence 5-6 Month, fruit period 9-10 Month. Native to Southeast North America. Cities to the south of the Yangtze River Valley in China are cultivated. Lanzhou and Beijing parks are also cultivated. The species is widely cultivated with more than 150 strains. The flower is large, white, lotus like and fragrant. It is a beautiful ornamental tree species for landscaping. It is suitable for moist and fertile soil, and has strong resistance to toxic gases such as sulfur dioxide, chlorine, hydrogen fluoride, etc.; it is also resistant to smoke and dust. The wood is yellow white, hard and heavy, which can be used for decoration. Aromatic oil can be extracted from leaves, twigs and flowers; used for flower extract. Ye was used to treat hypertension. Oil extraction from seeds, oil content 42.5%. (Overview picture resources:)","SpuId":129,"Score":0.9992467},"RequestId":"8FA0E710-CC9C-435E-840E-2E7575DDFAB6"}
{"Data":[{"CategoryName":"Boots","CategoryId":50011743,"Score":0.535344},{"CategoryName":"Outdoor leisure shoes","CategoryId":50019279,"Score":0.338715},{"CategoryName":"Climbing shoes/Hiking shoes","CategoryId":50019272,"Score":0.027337},{"CategoryName":"High shoes","CategoryId":50012907,"Score":0.026892},{"CategoryName":"Ski shoes/Snow boots","CategoryId":50019278,"Score":0.01566}],"RequestId":"97185D6B-1872-4409-BCB0-3A27BD2A13DD"}
{"Data":[{"PropertyValue":"Gao Bang","PropertyId":122216523,"SubId":"63","PropertyName":"Upper height","Score":1.0},{"PropertyValue":"male","PropertyId":122216608,"SubId":"1570","PropertyName":"Applicable object","Score":0.9797},{"PropertyValue":"Frenulum","PropertyId":20490,"SubId":"4371","PropertyName":"Closed mode","Score":0.9748},{"PropertyValue":"Youth","PropertyId":122216608,"SubId":"1581","PropertyName":"Applicable object","Score":0.9028},{"PropertyValue":"Round head","PropertyId":122216351,"SubId":"47","PropertyName":"Shoe toe style","Score":0.8999}],"RequestId":"E821C6CD-7871-4D53-BF81-EF5A3215C1AE"}

Original link

This article is Alibaba cloud content and cannot be reproduced without permission.

Keywords: Big Data Java SDK xml Apache

Added by carydean on Thu, 02 Jan 2020 08:26:27 +0200