1 Star 1 Fork 0

地球仪/gocv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
video_test.go 4.22 KB
一键复制 编辑 原始数据 按行查看 历史
Kim Eik 提交于 2019-04-15 13:07 . Added calcOpticalFlowPyrLKWithParams
package gocv
import (
"image"
"testing"
)
func TestMOG2(t *testing.T) {
img := IMRead("images/face.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in MOG2 test")
}
defer img.Close()
dst := NewMat()
defer dst.Close()
mog2 := NewBackgroundSubtractorMOG2()
defer mog2.Close()
mog2.Apply(img, &dst)
if dst.Empty() {
t.Error("Error in TestMOG2 test")
}
}
func TestMOG2WithParams(t *testing.T) {
img := IMRead("images/face.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in MOG2 test")
}
defer img.Close()
dst := NewMat()
defer dst.Close()
mog2 := NewBackgroundSubtractorMOG2WithParams(250, 8, false)
defer mog2.Close()
mog2.Apply(img, &dst)
if dst.Empty() {
t.Error("Error in TestMOG2WithParams test")
}
}
func TestKNN(t *testing.T) {
img := IMRead("images/face.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in KNN test")
}
defer img.Close()
dst := NewMat()
defer dst.Close()
knn := NewBackgroundSubtractorKNN()
defer knn.Close()
knn.Apply(img, &dst)
if dst.Empty() {
t.Error("Error in TestKNN test")
}
}
func TestKNNWithParams(t *testing.T) {
img := IMRead("images/face.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in KNN test")
}
defer img.Close()
dst := NewMat()
defer dst.Close()
knn := NewBackgroundSubtractorKNNWithParams(250, 200, false)
defer knn.Close()
knn.Apply(img, &dst)
if dst.Empty() {
t.Error("Error in TestKNNWithParams test")
}
}
func TestCalcOpticalFlowFarneback(t *testing.T) {
img1 := IMRead("images/face.jpg", IMReadColor)
if img1.Empty() {
t.Error("Invalid Mat in CalcOpticalFlowFarneback test")
}
defer img1.Close()
dest := NewMat()
defer dest.Close()
CvtColor(img1, &dest, ColorBGRAToGray)
img2 := dest.Clone()
defer img2.Close()
flow := NewMat()
defer flow.Close()
CalcOpticalFlowFarneback(dest, img2, &flow, 0.4, 1, 12, 2, 8, 1.2, 0)
if flow.Empty() {
t.Error("Error in CalcOpticalFlowFarneback test")
}
if flow.Rows() != 480 {
t.Errorf("Invalid CalcOpticalFlowFarneback test rows: %v", flow.Rows())
}
if flow.Cols() != 640 {
t.Errorf("Invalid CalcOpticalFlowFarneback test cols: %v", flow.Cols())
}
}
func TestCalcOpticalFlowPyrLK(t *testing.T) {
img1 := IMRead("images/face.jpg", IMReadColor)
if img1.Empty() {
t.Error("Invalid Mat in CalcOpticalFlowPyrLK test")
}
defer img1.Close()
dest := NewMat()
defer dest.Close()
CvtColor(img1, &dest, ColorBGRAToGray)
img2 := dest.Clone()
defer img2.Close()
prevPts := NewMat()
defer prevPts.Close()
nextPts := NewMat()
defer nextPts.Close()
status := NewMat()
defer status.Close()
err := NewMat()
defer err.Close()
corners := NewMat()
defer corners.Close()
GoodFeaturesToTrack(dest, &corners, 500, 0.01, 10)
tc := NewTermCriteria(Count|EPS, 20, 0.03)
CornerSubPix(dest, &corners, image.Pt(10, 10), image.Pt(-1, -1), tc)
CalcOpticalFlowPyrLK(dest, img2, corners, nextPts, &status, &err)
if status.Empty() {
t.Error("Error in CalcOpticalFlowPyrLK test")
}
if status.Rows() != 323 {
t.Errorf("Invalid CalcOpticalFlowPyrLK test rows: %v", status.Rows())
}
if status.Cols() != 1 {
t.Errorf("Invalid CalcOpticalFlowPyrLK test cols: %v", status.Cols())
}
}
func TestCalcOpticalFlowPyrLKWithParams(t *testing.T) {
img1 := IMRead("images/face.jpg", IMReadColor)
if img1.Empty() {
t.Error("Invalid Mat in CalcOpticalFlowPyrLK test")
}
defer img1.Close()
dest := NewMat()
defer dest.Close()
CvtColor(img1, &dest, ColorBGRAToGray)
img2 := dest.Clone()
defer img2.Close()
prevPts := NewMat()
defer prevPts.Close()
nextPts := NewMat()
defer nextPts.Close()
status := NewMat()
defer status.Close()
err := NewMat()
defer err.Close()
corners := NewMat()
defer corners.Close()
GoodFeaturesToTrack(dest, &corners, 500, 0.01, 10)
tc := NewTermCriteria(Count|EPS, 30, 0.03)
CornerSubPix(dest, &corners, image.Pt(10, 10), image.Pt(-1, -1), tc)
CalcOpticalFlowPyrLKWithParams(dest, img2, corners, nextPts, &status, &err, image.Pt(21, 21), 3, tc, 0, 0.0001)
if status.Empty() {
t.Error("Error in CalcOpticalFlowPyrLK test")
}
if status.Rows() != 323 {
t.Errorf("Invalid CalcOpticalFlowPyrLK test rows: %v", status.Rows())
}
if status.Cols() != 1 {
t.Errorf("Invalid CalcOpticalFlowPyrLK test cols: %v", status.Cols())
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/diqiuyi/gocv.git
[email protected]:diqiuyi/gocv.git
diqiuyi
gocv
gocv
dev

搜索帮助

0d507c66 1850385 C8b1a773 1850385