mirror of
https://github.com/jehiah/TrafficSpeed.git
synced 2025-10-06 00:37:12 +08:00
minor updates
This commit is contained in:
@@ -52,6 +52,18 @@ var black = image.NewUniform(color.Gray{})
|
||||
|
||||
type Masks []Mask
|
||||
|
||||
func (m Masks) Uniq() Masks {
|
||||
var o Masks
|
||||
data := make(map[Mask]bool)
|
||||
for _, mm := range m {
|
||||
data[mm] = true
|
||||
}
|
||||
for mm, _ := range data {
|
||||
o = append(o, mm)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func (m Masks) Apply(i image.Image) {
|
||||
var ii draw.Image
|
||||
var ok bool
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package project
|
||||
|
||||
// #cgo LDFLAGS="-L/usr/local/Cellar/ffmpeg/3.3/lib"
|
||||
// #cgo CGO_CFLAGS="-I/usr/local/Cellar/ffmpeg/3.3/include"
|
||||
// #cgo LDFLAGS="-L/usr/local/Cellar/ffmpeg/4.2.2_2/lib"
|
||||
// #cgo CGO_CFLAGS="-I/usr/local/Cellar/ffmpeg/4.2.2_2/include"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -180,6 +180,7 @@ func (p *Project) Load(req *http.Request) error {
|
||||
break
|
||||
}
|
||||
}
|
||||
p.Masks = p.Masks.Uniq()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -353,6 +354,29 @@ func (p *Project) Run() (Response, error) {
|
||||
if err = iterator.Error(); err != nil {
|
||||
return results, err
|
||||
}
|
||||
if p.Step >= 5 && bgavg == nil {
|
||||
if len(bg.Images) > 0 {
|
||||
log.Printf("calculating background from %d frames", len(bg.Images))
|
||||
bgavg = bg.Image()
|
||||
analyzer.Background = bgavg
|
||||
results.BackgroundImg = dataImg(bgavg, "")
|
||||
|
||||
if p.Step == 6 {
|
||||
log.Printf("extracting vehicle position from %d pending frames", len(pendingAnalysis))
|
||||
for _, pf := range pendingAnalysis {
|
||||
if pf.Frame%50 == 0 && pf.Frame > 0 {
|
||||
log.Printf("... frame %d", pf.Frame)
|
||||
}
|
||||
positions := analyzer.Positions(pf.Image)
|
||||
if len(positions) > 0 {
|
||||
framePositions = append(framePositions, FramePosition{pf.Frame, pf.Time, positions})
|
||||
}
|
||||
}
|
||||
pendingAnalysis = nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if p.Step == 6 {
|
||||
results.VehiclePositions = TrackVehicles(framePositions)
|
||||
|
@@ -57,7 +57,7 @@ func NewIterator(filename string) (iter *Iterator, err error) {
|
||||
// astream := stream.(av.AudioCodecData)
|
||||
// fmt.Println(astream.Type(), astream.SampleRate(), astream.SampleFormat(), astream.ChannelLayout())
|
||||
// } else if stream.Type().IsVideo() {
|
||||
fmt.Printf("stream[%d] = %s\n", i, stream.Type())
|
||||
fmt.Printf("stream[%d] = %s (video:%v)\n", i, stream.Type(), stream.Type().IsVideo())
|
||||
if stream.Type().IsVideo() {
|
||||
vstream := stream.(av.VideoCodecData)
|
||||
r := image.Rect(0, 0, vstream.Width(), vstream.Height())
|
||||
@@ -138,6 +138,10 @@ func (i *Iterator) DecodeFrame() error {
|
||||
// decode
|
||||
decoder := i.decoders[i.packet.Idx]
|
||||
var err error
|
||||
if len(i.packet.Data) == 0 {
|
||||
log.Printf("no packet at frame %d", i.frame)
|
||||
return nil
|
||||
}
|
||||
i.vf, err = decoder.Decode(i.packet.Data)
|
||||
if i.vf == nil {
|
||||
log.Printf("no image at frame %d", i.frame)
|
||||
@@ -148,6 +152,11 @@ func (i *Iterator) DecodeFrame() error {
|
||||
}
|
||||
|
||||
func (i *Iterator) Image() *image.YCbCr {
|
||||
if i.frame == -1 {
|
||||
if !i.NextWithImage() {
|
||||
panic("no image")
|
||||
}
|
||||
}
|
||||
i.err = i.DecodeFrame()
|
||||
if i.vf == nil {
|
||||
return nil
|
||||
|
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/jehiah/TrafficSpeed/speed_camera/cmd"
|
||||
)
|
||||
|
||||
// #cgo LDFLAGS="-L/usr/local/Cellar/ffmpeg/3.3/lib"
|
||||
// #cgo CGO_CFLAGS="-I/usr/local/Cellar/ffmpeg/3.3/include"
|
||||
// #cgo LDFLAGS="-L/usr/local/Cellar/ffmpeg/4.2.2_2/lib"
|
||||
// #cgo CGO_CFLAGS="-I/usr/local/Cellar/ffmpeg/4.2.2_2/include"
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Llongfile)
|
||||
|
@@ -1,34 +1,7 @@
|
||||
# vision zero speed camera
|
||||
|
||||
## create a project
|
||||
|
||||
a) new project /path/to/video
|
||||
b) make a working directory for this project ymdhms_name
|
||||
c) pick all the settings (web UI)
|
||||
d) extract positions
|
||||
e) render video
|
||||
|
||||
## Video Formating
|
||||
|
||||
If the image file is not detected peroperly:
|
||||
|
||||
If it's already h264
|
||||
|
||||
```bash
|
||||
ffmpeg -i in.MOV -an -c copy out.m4a
|
||||
```
|
||||
|
||||
Or to convert to h264
|
||||
|
||||
```bash
|
||||
ffmpeg -i in.avi -an -c:v libx264 data/out.m4a
|
||||
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
|
||||
CGO_LDFLAGS="-L/usr/local/Cellar/ffmpeg/3.3/lib" CGO_CFLAGS="-I/usr/local/Cellar/ffmpeg/3.3/include" gb build
|
||||
|
||||
CGO_LDFLAGS="-L/usr/local/Cellar/ffmpeg/4.2.2_2/lib" CGO_CFLAGS="-I/usr/local/Cellar/ffmpeg/4.2.2_2/include" gb build
|
||||
|
||||
|
||||
# Image libraries
|
||||
|
Reference in New Issue
Block a user