71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
import axios from 'axios'
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api',
|
|
timeout: 30000
|
|
})
|
|
|
|
const dockerApi = axios.create({
|
|
baseURL: '/docker-api',
|
|
timeout: 120000
|
|
})
|
|
|
|
// 视频检测专用,超时更长
|
|
const videoApi = axios.create({
|
|
baseURL: '/api',
|
|
timeout: 300000
|
|
})
|
|
|
|
export const detectionApi = {
|
|
getModels() {
|
|
return api.get('/models')
|
|
},
|
|
|
|
getAlgorithmConfig() {
|
|
return api.get('/algorithms/config')
|
|
},
|
|
|
|
detectImage(formData, modelId, confidence, iou, algorithmConfig = null, regionPolygon = null) {
|
|
const params = {
|
|
model_id: modelId,
|
|
confidence,
|
|
iou
|
|
}
|
|
if (algorithmConfig) {
|
|
params.algorithm_config = JSON.stringify(algorithmConfig)
|
|
}
|
|
if (regionPolygon) {
|
|
params.region_polygon = JSON.stringify(regionPolygon)
|
|
}
|
|
|
|
return api.post('/detect/image', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data'
|
|
},
|
|
params
|
|
})
|
|
},
|
|
|
|
detectVideo(formData) {
|
|
return dockerApi.post('/api/fight_detect', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data'
|
|
}
|
|
})
|
|
},
|
|
|
|
// 本地 YOLO 视频检测(打架斗殴检测等)
|
|
detectLocalVideo(formData, modelId = 'fight_detection', confidence = 0.5, iou = 0.45) {
|
|
return videoApi.post('/detect/video', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data'
|
|
},
|
|
params: {
|
|
model_id: modelId,
|
|
confidence,
|
|
iou
|
|
}
|
|
})
|
|
}
|
|
}
|