golang开源视频安全监控解决方案插件库scout的使用
Golang开源视频安全监控解决方案插件库Scout的使用
Scout是一个独立的开源软件解决方案,用于DIY视频安全监控系统。
主要特性
- 无需月费!
- 易于安装
- 运行在您的设备和网络上
- 可从源代码构建或使用Docker预构建镜像
- 使用YAML自定义配置
- 可链接多个服务器
- 无麻烦管理
- 可随时调整摄像头,无需重新配置
- 无需数据库
- 将图像和录像存储在本地文件系统
- 您拥有自己的数据
- 自动清理旧数据
- 计算机视觉
- 扩展了经过验证的运动、物体和人脸检测库
- 有助于减少误报警报
- 警报
- 通过电子邮件或短信接收警报通知
- 录像
- 检测到物体时自动录像
- 持续录像
- 支持持续录像并自动清理
使用示例
下面是一个使用Scout库的基本示例代码:
package main
import (
"log"
"github.com/jonoton/scout/monitor"
"github.com/jonoton/scout/notify"
)
func main() {
// 创建监控配置
config := monitor.Config{
Name: "Front Door",
Source: "rtsp://admin:password@192.168.1.100:554/Streaming/Channels/101",
Width: 1280,
Height: 720,
FPS: 15,
MinDetect: 3,
ObjectTypes: []string{"person", "car"},
}
// 创建通知配置
notifyConfig := notify.Config{
Email: notify.EmailConfig{
Enabled: true,
From: "scout@example.com",
To: "you@example.com",
SMTPHost: "smtp.example.com",
SMTPPort: 587,
Username: "scout@example.com",
Password: "password",
},
}
// 初始化监控器
mon, err := monitor.New(config)
if err != nil {
log.Fatalf("Failed to create monitor: %v", err)
}
// 设置通知处理器
notifier := notify.New(notifyConfig)
mon.SetNotifier(notifier)
// 启动监控
err = mon.Start()
if err != nil {
log.Fatalf("Failed to start monitor: %v", err)
}
// 等待监控结束
<-mon.Done()
log.Println("Monitor stopped")
}
Docker使用示例
您也可以使用Docker快速部署Scout:
# 拉取Scout镜像
docker pull jonotoninnovation/scout
# 运行Scout容器
docker run -d \
--name scout \
-p 8080:8080 \
-v /path/to/config:/config \
-v /path/to/recordings:/recordings \
jonotoninnovation/scout
配置示例
Scout使用YAML配置文件,下面是一个示例配置:
monitors:
- name: "Front Door"
source: "rtsp://admin:password@192.168.1.100:554/Streaming/Channels/101"
width: 1280
height: 720
fps: 15
minDetect: 3
objectTypes: ["person", "car"]
record: true
continuous: false
sensitivity: 50
notify:
email:
enabled: true
from: "scout@example.com"
to: "you@example.com"
smtpHost: "smtp.example.com"
smtpPort: 587
username: "scout@example.com"
password: "password"
移动客户端特性
- 远程访问Scout服务器
- 家庭和外出设置
- 监控实时视图
- 所有监控器的快速视图
- 支持平移和缩放的实时全屏视图
- 警报
- 浏览警报
- 支持平移和缩放的警报全屏视图
- 共享或下载警报
- 对象、人员和面部检测的平台通知
- 录像
- 浏览录像
- 渐进式加载的全屏录像视图
- 共享或下载录像
- 持续录像
- 浏览持续录像
- 渐进式加载的全屏持续录像视图
- 共享或下载持续录像
Web客户端有限特性
- 可视化验证设置
- 显示RAM使用情况
- 显示帧率
- 监控实时视图
- 所有监控器的快速视图
Scout是一个功能强大的开源视频监控解决方案,适用于需要自定义和安全监控系统的用户。
更多关于golang开源视频安全监控解决方案插件库scout的使用的实战教程也可以访问 https://www.itying.com/category-94-b0.html
1 回复
更多关于golang开源视频安全监控解决方案插件库scout的使用的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
Scout - Go语言视频安全监控解决方案插件库
Scout 是一个用 Go 语言编写的开源视频安全监控解决方案插件库,它提供了一套完整的工具和接口,用于构建视频监控和安全分析系统。
主要特性
- 支持多种视频源接入(RTSP, RTMP, HTTP-FLV等)
- 提供视频分析插件框架
- 支持人脸识别、移动检测等AI功能
- 轻量级、高性能设计
- 易于扩展的插件架构
安装
go get github.com/scout-inc/scout
基本使用示例
1. 初始化Scout
package main
import (
"log"
"github.com/scout-inc/scout"
)
func main() {
// 创建Scout实例
s, err := scout.NewScout()
if err != nil {
log.Fatalf("Failed to create Scout instance: %v", err)
}
defer s.Close()
// 配置Scout
config := scout.Config{
MaxWorkers: 4,
BufferSize: 1024,
LogLevel: "info",
PluginsPath: "./plugins",
}
err = s.Configure(config)
if err != nil {
log.Fatalf("Failed to configure Scout: %v", err)
}
}
2. 添加视频源
// 添加RTSP视频源
rtspSource := scout.VideoSource{
ID: "camera1",
Type: "rtsp",
URL: "rtsp://admin:password@192.168.1.100:554/stream1",
}
err := s.AddSource(rtspSource)
if err != nil {
log.Printf("Failed to add RTSP source: %v", err)
}
// 添加RTMP视频源
rtmpSource := scout.VideoSource{
ID: "camera2",
Type: "rtmp",
URL: "rtmp://live.example.com/app/streamkey",
}
err = s.AddSource(rtmpSource)
if err != nil {
log.Printf("Failed to add RTMP source: %v", err)
}
3. 使用分析插件
// 加载移动检测插件
motionPlugin, err := s.LoadPlugin("motion_detector", map[string]interface{}{
"sensitivity": 0.7,
"region": []int{0, 0, 100, 100}, // x1,y1,x2,y2
})
if err != nil {
log.Printf("Failed to load motion detector plugin: %v", err)
}
// 将插件绑定到视频源
err = s.BindPlugin("camera1", motionPlugin)
if err != nil {
log.Printf("Failed to bind plugin to source: %v", err)
}
// 设置事件处理回调
motionPlugin.OnEvent(func(event scout.PluginEvent) {
log.Printf("Motion detected! Confidence: %.2f, Position: %v",
event.Confidence, event.Position)
// 可以在这里触发报警或其他操作
if event.Confidence > 0.8 {
sendAlert("High confidence motion detected!")
}
})
4. 人脸识别示例
// 加载人脸识别插件
facePlugin, err := s.LoadPlugin("face_recognition", map[string]interface{}{
"model_path": "./models/face_detection.onnx",
"min_confidence": 0.6,
"known_faces_dir": "./known_faces",
})
if err != nil {
log.Printf("Failed to load face recognition plugin: %v", err)
}
// 绑定到视频源
err = s.BindPlugin("camera2", facePlugin)
if err != nil {
log.Printf("Failed to bind face plugin: %v", err)
}
// 人脸识别事件处理
facePlugin.OnEvent(func(event scout.PluginEvent) {
if event.Identified {
log.Printf("Recognized face: %s (Confidence: %.2f)",
event.Identity, event.Confidence)
} else {
log.Printf("Unknown face detected (Confidence: %.2f)",
event.Confidence)
}
})
5. 录像功能
// 配置录像
recorder := scout.RecorderConfig{
SourceID: "camera1",
OutputDir: "./recordings",
SegmentTime: 300, // 每段录像时长(秒)
Retention: 86400, // 录像保留时间(秒)
}
err = s.StartRecording(recorder)
if err != nil {
log.Printf("Failed to start recording: %v", err)
}
// 基于事件触发录像
motionPlugin.OnEvent(func(event scout.PluginEvent) {
if event.Confidence > 0.7 {
err := s.TriggerRecording("camera1", 30) // 录制30秒
if err != nil {
log.Printf("Failed to trigger recording: %v", err)
}
}
})
高级功能
自定义插件开发
Scout允许开发自定义分析插件:
package myplugin
import (
"github.com/scout-inc/scout/plugin"
)
type MyAnalyzer struct {
plugin.Base
threshold float64
}
func (a *MyAnalyzer) Init(config map[string]interface{}) error {
// 初始化配置
if val, ok := config["threshold"].(float64); ok {
a.threshold = val
} else {
a.threshold = 0.5
}
return nil
}
func (a *MyAnalyzer) Process(frame plugin.VideoFrame) ([]plugin.Event, error) {
// 在这里实现你的分析逻辑
// 返回检测到的事件列表
// 示例: 简单的亮度检测
avgBrightness := calculateBrightness(frame.Data)
if avgBrightness > a.threshold {
return []plugin.Event{
{
Type: "high_brightness",
Confidence: (avgBrightness - a.threshold) / (1 - a.threshold),
Position: []int{0, 0, frame.Width, frame.Height},
},
}, nil
}
return nil, nil
}
// 注册插件
func init() {
plugin.Register("brightness_analyzer", func() plugin.Analyzer {
return &MyAnalyzer{}
})
}
性能优化建议
- 合理设置
MaxWorkers
参数,根据CPU核心数调整 - 对于高分辨率视频,考虑在插件中进行下采样
- 使用GPU加速的插件(如带CUDA支持的OpenCV)
- 对于多路视频,考虑分布式部署
总结
Scout为Go开发者提供了一个强大的视频监控和分析框架,通过其插件系统可以轻松扩展功能。无论是构建简单的监控系统还是复杂的AI视频分析应用,Scout都能提供良好的基础架构。
更多详细用法和插件开发文档,请参考Scout的GitHub仓库:https://github.com/scout-inc/scout