代码拉取完成,页面将自动刷新
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())
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。