W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋 :用于檢測一張車輛圖片的具體車型,即對(duì)于輸入的一張圖片(可正常解碼,且長寬比適宜),輸出圖片的車輛品牌及型號(hào)、顏色及年份、位置信息。
Object object
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 |
---|---|---|---|---|
image |
String |
是 |
- |
圖像資源地址 |
top_num |
Number |
否 |
5 |
返回結(jié)果 top n,默認(rèn) 5 。 |
success |
Function |
否 |
接口調(diào)用成功的回調(diào)函數(shù) |
|
fail |
Function |
否 |
接口調(diào)用失敗的回調(diào)函數(shù) |
|
complete |
Function |
否 |
接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
參數(shù) | 類型 | 說明 |
---|---|---|
log_id |
Number |
唯一的 log id ,用于問題定位。 |
color_result |
string |
顏色 |
result |
Array |
車型識(shí)別結(jié)果數(shù)組 |
location_result |
Object |
車在圖片中的位置信息 |
參數(shù)名 | 參數(shù)類型 | 說明 |
---|---|---|
name |
String |
車型名稱,示例:寶馬 x6 。 |
score |
Number |
置信度,示例:0.5321 。 |
year |
String |
年份 |
參數(shù)名 | 參數(shù)類型 | 說明 |
---|---|---|
left |
Number |
左起像素位置 |
top |
Number |
上起像素位置 |
width |
Number |
像素寬 |
height |
Number |
像素高 |
<view class="wrap">
<view class="card-area" style="height:2.1rem">
<image mode="aspectFill" class="display-area-image" src="{{image}}"></image>
</view>
<view class="card-area" style="margin-bottom: 1.2rem;">
<view s-if="!loading" class="top-description border-bottom">識(shí)別結(jié)果</view>
<view s-if="result.length>0">
<view s-if="!loading">
<view s-for="item in result" class="list-area border-bottom">
<view class="reasult-keyword">{{item.name}}</view>
<view class="reasult-score">
<view class="score-title">置信度</view>
<view style="display:inline-block">
<view class="score-info">{{item.score}}<text class="percent">%</text></view>
<view class="score-percent">
<view class="percent-front {{item.score===100?'percent-100':''}}" style="width:{{item.score}}%;"></view>
</view>
</view>
</view>
<view class="score-title">年份</view>
<view class="root-info">{{item.year}}</view>
</view>
</view>
</view>
<view s-else>
<view s-if="!loading">
<view class="result-area">
<view class="result-area-fail">未檢測到車輛</view>
<view class="result-area-tips">請(qǐng)上傳包含車輛的清晰圖片</view>
</view>
</view>
</view>
</view>
<view class="swan-security-padding-bottom flex-button">
<button type="primary" hover-class="button-hover" disabled="{{loading}}" bindtap="carClassify">上傳車輛圖片</button>
</view>
</view>
Page({
data: {
loading: true,
isLoad: false,
image: 'https://b.bdstatic.com/miniapp/images/carClassify.png',
result: [
{score: '10.67', name: '日產(chǎn)BladeGlider', year: '無年份信息'},
{score: '9.05', name: '標(biāo)致VisionGranTurismo', year: '無年份信息'},
{score: '7.54', name: '摩根EV3', year: '2015'},
{score: '7.18', name: 'LM55', year: '無年份信息'},
{score: '6.96', name: '奔馳Vision', year: '無年份信息'}
]
},
onShow() {
if (!this.data.isLoad) {
swan.showToast({
title: '識(shí)別中...',
icon: 'loading',
duration: 1000
});
this.setData({
loading: true
});
setTimeout(() => {
this.setData({
loading: false
});
this.data.isLoad = true;
}, 1000);
}
},
carClassify() {
if (this.getData('loading')) {
return;
}
swan.showActionSheet({
itemList: ['拍照', '從手機(jī)相冊(cè)選擇'],
success: res => {
const sourceType = res.tapIndex === 0 ? 'camera' : 'album';
swan.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: [sourceType],
success: res => {
const image = res.tempFilePaths[0];
this.setData({image, loading: true});
swan.showToast({
title: '識(shí)別中...',
icon: 'loading',
duration: 20000
});
swan.ai.carClassify({
image,
top_num: 5,
success: res => {
console.log('carClassify success', res);
this.setImageData(res.result);
},
fail: err => {
console.log('carClassify fail', err);
},
complete: () => {
swan.hideToast();
this.setData('loading', false);
}
});
},
fail: err => {
console.log('chooseImage fail', err);
}
});
}
});
},
setImageData(data) {
const len = data.length - 1;
for (let i = len; i >= 0; i--) {
if (data[i].name === '非車類') {
data.splice(i, 1);
}
else {
if (data[i].score && !isNaN(data[i].score)) {
data[i].score = (data[i].score * 100).toFixed(2);
if (data[i].score > 100) {
data[i].score = 100;
}
}
else {
data[i].score = 0;
}
}
}
this.setData('result', data);
}
});
返回值示例
{
"log_id": $log_id,
"location_result": {
"width": 434,
"top": 119,
"height": 246,
"left": 110
},
"result": [
{
"score": 0.99993008375168,
"name": "寶馬X3",
"year": "2016"
},
{
"score": 0.00005255633732304,
"name": "寶馬X4",
"year": "2015-2016"
},
{
"score": 0.0000031432850846613,
"name": "SWM斯威X7",
"year": "2016-2017"
},
{
"score": 0.0000012879694395451,
"name": "寶馬X5",
"year": "2016-2017"
},
{
"score": 5.6126202707674e-7,
"name": "豐田漢蘭達(dá)",
"year": "2015-2017"
},
{
"score": 4.4069730620322e-7,
"name": "斯柯達(dá)速尊",
"year": "2014-2016"
},
{
"score": 4.0618823504701e-7,
"name": "寶馬X1",
"year": "2017"
}
],
"color_result": "白色"
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: