Summary
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.
test
1. Service opening
2. Service call
- 2.1 pom.xml
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>[4.4.2,5.0.0)</version> </dependency>
- 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; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; public class Demo1 { //The parameters of DefaultProfile.getProfile are region, access_key_id, access_key_secret https://yq.aliyun.com/articles/693979 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 = "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1577683988&di=940085ab7a77bbbe2f796bd2ad8e3ba2&src=http://image.biaobaiju.com/uploads/20180803/20/1533300579-gnUBlQZPbt.jpg"; String vehiclePicUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1577695567568&di=0db0a43cf0579e8050a451cdb5a5bbee&imgtype=0&src=http%3A%2F%2Fimg.kutoo8.com%2Fupload%2Fimage%2F36015894%2F1367481408093666_960x540.jpg"; String plantPicUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1577695588307&di=0ecab47da106889bed43dfc75065b619&imgtype=0&src=http%3A%2F%2Fpro.user.img32.51sole.com%2FproductImages3%2F20140405%2F1292497_20140405225052.jpg"; 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 = "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=21055346,2142400964&fm=26&gp=0.jpg"; String prodcategoryPicUrl = "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=21055346,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(); request.setMethod(MethodType.POST); request.setDomain("visionai.cn-beijing.aliyuncs.com"); request.setVersion("2019-10-24"); request.setAction(Action); request.setRegionId("cn-beijing"); 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) { e.printStackTrace(); } System.out.println(response.getData()); } /** * 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.setRequestMethod("GET"); 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( (len=inStream.read(buffer)) != -1 ){ outStream.write(buffer, 0, len); } inStream.close(); 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"}
This article is Alibaba cloud content and cannot be reproduced without permission.