Loading... # 0x0 三帧法运动检测属于帧间差分法,相关介绍在之前的文章中有介绍。<button class=" btn m-b-xs btn-success " onclick='window.open("https://rehtt.com/index.php/archives/233/","_blank")'>跳转</button> 这次使用Golang的OpenCV库:gocv <button class=" btn m-b-xs btn-success " onclick='window.open("https://gocv.io/","_blank")'>跳转</button> 来编写,是最近为了练手gocv而写的第一个demo # 0x1 ```golang package main import ( "gocv.io/x/gocv" ) func main() { c, err := gocv.VideoCaptureFile("1.mp4") if err != nil { panic(err) } mat := gocv.NewMat() aMat, bMat := gocv.NewMat(), gocv.NewMat() ab, bc := gocv.NewMat(), gocv.NewMat() f := gocv.NewMat() w, err := gocv.VideoWriterFile("test.mp4", c.CodecString(), c.Get(gocv.VideoCaptureFPS), int(c.Get(gocv.VideoCaptureFrameWidth)), int(c.Get(gocv.VideoCaptureFrameHeight)), false) for c.Read(&mat) { //灰度 gocv.CvtColor(mat, &mat, gocv.ColorBGRToGray) //二值 gocv.Threshold(mat, &mat, 25, 255, gocv.ThresholdBinary) if bMat.Empty() { if aMat.Empty() { mat.CopyTo(&aMat) } else { mat.CopyTo(&bMat) gocv.AbsDiff(aMat, bMat, &ab) } continue } gocv.AbsDiff(bMat, mat, &bc) gocv.BitwiseAnd(ab, bc, &f) w.Write(f) bc.CopyTo(&ab) bMat.CopyTo(&aMat) mat.CopyTo(&bMat) } w.Close() } ``` Last modification:August 4, 2021 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 如果觉得我的文章对你有用,请随意赞赏