NodeJs

执行(保存为IVPD.js)。

NodeJS SDK

准备工作

  1. 在安装和使用阿里云SDK前,确保您已经注册阿里云账号并生成访问密钥(AccessKey)。详情参考创建AccessKey

  2. 安装Node.js SDK核心库。阿里云Node.js SDK支持的版本为8.0及以上,您可以通过以下方式安装Node.js SDK: npm install @alicloud/pop-core -S

  3. 您也可以使用cnpm、yarn等包管理工具来安装@alicloud/pop-core。

完整代码示例

const Core = require('@alicloud/pop-core');

var client = new Core({
   accessKeyId: process.env['ACCESS_KEY_ID'],
   accessKeySecret: process.env['ACCESS_KEY_SECRET'],
   endpoint: 'https://ivpd.cn-shanghai.aliyuncs.com',
   apiVersion: '2019-06-25',
   codes: new Set([200, '0', 'OK', 'Success'])
});

function execute(action, params) {
   var requestOption = {
      method: 'POST'
   };
   console.log("");
   client.request(action, params, requestOption).then((result) => {
     console.log(action + ".Result: " + JSON.stringify(result));
    }, (ex) => {
     console.log(action + ".Error, params:" + JSON.stringify(params));
     console.log(ex);
    })  
}

function testSegmentImage() {
    var params = {
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/aliyun-doc/pop/images/segment-image-src.jpg"
    }
     execute('SegmentImage', params);    
}

function testMakeSuperResolutionImage() {
    var params = {
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/MakeSuperResolution/sup-dog.png"
    }
     execute('MakeSuperResolutionImage', params);    
}

function testChangeImageSize() {
    var params = {
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/ChangeImageSize/change-image-size-src.png",
        "Width": 1080,
        "Height": 1920
    }
     execute('ChangeImageSize', params);    
}

function testDetectImageElements() {
    var params = {
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/DetectImageElements/detect-elements-src.png"
    }
     execute('DetectImageElements', params);   
}

function testExtendImageStyle() {
    var params = {
        "MajorUrl": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/ExtendImageStyle/majorUrl.jpeg",
        "StyleUrl": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/ExtendImageStyle/styleUrl.jpeg"
    }
     execute('ExtendImageStyle', params);   
}

function testRecognizeImageColor() {
    var params = {
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecognizeImageColor/RecognizeImageColor.png"
    }
     execute('RecognizeImageColor', params);   
}

function testRecognizeImageStyle() {
    var params = {
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecognizeImageStyle/technology.png"
    }
     execute('RecognizeImageStyle', params);   
}

function testRecolorImage() {
    var paramsAuto = {
        "Mode": "AUTO",
        "ColorCount": 3,
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecolorImage/recolor-1-src.png"
    }
    var paramsRefPic = {
        "Mode": "REF_PIC",
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecolorImage/recolor-1-src.png",
        "RefUrl": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecolorImage/recolor-refurl-src.png"
    }
    var paramsRefTemplate = {
        "Mode": "TEMPLATE",
        "Url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecolorImage/recolor-1-src.png",
        "ColorTemplate": [
           {"Color": "056A6B"},
           {"Color": "FF0000"},
           {"Color": "00FF00"},
        ]
    }
    execute('RecolorImage', paramsAuto);
    execute('RecolorImage', paramsRefPic);
    execute('RecolorImage', paramsRefTemplate);
}

testSegmentImage();//图像分割/抠图
testMakeSuperResolutionImage();//超分辨率
testChangeImageSize();//尺寸变换
testDetectImageElements();//元素检测
testExtendImageStyle();//风格迁移
testRecognizeImageColor();//色板识别
testRecognizeImageStyle();//风格识别
testRecolorImage();//色彩迁移

执行(保存为IVPD.js)

node ./IVPD.js

输出结果

SegmentImage.Result: {"Data":{"Url":"http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_parser/2019-10-14/invi_parser_015710271158311033823_7sVnQw.png?Expires=1571030715&Signature=ylAAO23uKJnJ8WJmdz4dldtUQd8%3D"},"Message":"success","RequestId":"7DB95048-2258-4351-B245-FB67E4CEC6EF","Code":"0"}

MakeSuperResolutionImage.Result: {"Data":{"Url":"http://ai-gateway.oss-cn-shanghai.aliyuncs.com/upload/ai-gateway_prod/ds%3D20191014/sisrx2_157102711556307517.jpg?Expires=1571631915&Signature=ftQA6BgwteDyofY%2Bwj6hPMcEzEI%3D"},"Message":"Success.","RequestId":"7FA109DD-5112-4715-9D3C-FC9465ED6621","Code":"0"}

ChangeImageSize.Result: {"Data":{"Url":"http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_filter/2019-10-14/invi_filter_015710271161781012676_5kWkSC.png?Expires=1571030716&Signature=PhDUv%2FwxcArwzm2jNyS5EIhea8A%3D"},"Message":"success","RequestId":"AB68E125-69BD-4543-83EF-1D93BBADAC69","Code":"0"}

DetectImageElements.Result: {"Data":{"Elements":[{"Type":"majorhuman","Height":354,"Width":285,"Y":78,"Score":"0.997097373008728","X":287}]},"Message":"success","RequestId":"6F358722-AAC9-4BC1-85C4-6FCA39C70FFA","Code":"0"}

ExtendImageStyle.Result: {"Data":{"Url":"http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_/2019-10-14/invi__015710271156451012674_LbidJx.jpg?Expires=1571030715&Signature=nXZpF101BqKmIIkqycwwnktY3Ps%3D","MajorUrl":""},"Message":"success","RequestId":"EF71C2E8-1D30-4304-962E-3246E0206BC5","Code":"0"}

RecognizeImageColor.Result: {"Data":{"ColorTemplateList":[{"Percentage":"0.535937","Label":"blue","Color":"6CA2DC"},{"Percentage":"0.305331","Label":"yellow","Color":"B58D22"},{"Percentage":"0.158732","Label":"gray","Color":"323C46"}]},"Message":"success","RequestId":"60FC2287-90C2-403E-B42D-24044D8573D8","Code":"0"}

RecognizeImageStyle.Result: {"Data":{"Styles":["technology","strong"]},"Message":"success","RequestId":"45F3306C-711C-4E65-A868-4C73111B1FEA","Code":"0"}

RecolorImage.Result: {"Data":{"ImageList":["http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/RecolorImage/recolor-1-src.png"]},"Message":"success","RequestId":"82056BF7-535D-4DF7-8C5C-822FC96E4A49","Code":"0"}

RecolorImage.Result: {"Data":{"ImageList":["http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_filter/2019-10-14/invi_filter_015710271159711012675_n9Jj2U.png?Expires=1571113515&Signature=50bx2pY2Y%2FyU%2Bc3EHTymEMi%2BgNY%3D"]},"Message":"success","RequestId":"60FA107F-5B3E-48A9-B771-7F8792643421","Code":"0"}

RecolorImage.Result: {"Data":{"ImageList":["http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_filter/2019-10-14/invi_filter_015710271155631012673_oYUVdc.png?Expires=1571113515&Signature=yijcmYE%2BSQPEkpbL1rFaS%2F6Iwng%3D"]},"Message":"success","RequestId":"E664D7D5-057E-4FEE-8490-47161B6622F0","Code":"0"}
阿里云首页 智能视觉生产 相关技术圈