44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package producer
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gocv.io/x/gocv"
|
|
)
|
|
|
|
// https://medium.com/radix-ai-blog/banishing-the-jitters-stabilizing-satellite-imagery-with-opencvs-phase-correlation-3ba2dc6ac096
|
|
|
|
// tackle the brightness and contrast problem
|
|
// by performing phase correlation on detected
|
|
// edges instead of the raw image
|
|
|
|
// SKIP: 多光谱各个波段的边缘检测结果不佳
|
|
func CV_Canny(img0 gocv.Mat) gocv.Mat {
|
|
fmt.Println(img0.Cols(), img0.Rows(), img0.Type().String())
|
|
dst8 := gocv.NewMatWithSize(img0.Rows(), img0.Cols(), gocv.MatTypeCV8U)
|
|
defer dst8.Close()
|
|
gocv.Normalize(img0, &dst8, 0, 255, gocv.NormMinMax)
|
|
dst8.ConvertTo(&dst8, gocv.MatTypeCV8U)
|
|
dstEdge := gocv.NewMat()
|
|
gocv.Canny(dst8, &dstEdge, 10, 100)
|
|
dstEdge.ConvertTo(&dstEdge, gocv.MatTypeCV16U)
|
|
return dstEdge
|
|
}
|
|
|
|
func CV_Sobel(img0 gocv.Mat) gocv.Mat {
|
|
// x 方向
|
|
sobelX := gocv.NewMat()
|
|
gocv.Sobel(img0, &sobelX, gocv.MatTypeCV32F, 1, 0, 5, 1.5, 0, gocv.BorderDefault)
|
|
sobelX.ConvertTo(&sobelX, gocv.MatTypeCV16U)
|
|
// y 方向
|
|
sobelY := gocv.NewMat()
|
|
gocv.Sobel(img0, &sobelY, gocv.MatTypeCV32F, 0, 1, 5, 1.5, 0, gocv.BorderIsolated)
|
|
sobelY.ConvertTo(&sobelY, gocv.MatTypeCV16U)
|
|
// 合并
|
|
sobelXY := gocv.NewMat()
|
|
gocv.Sobel(img0, &sobelXY, gocv.MatTypeCV32F, 1, 1, 5, 1.5, 0, gocv.BorderDefault)
|
|
sobelXY.ConvertTo(&sobelXY, gocv.MatTypeCV16U)
|
|
|
|
return sobelY
|
|
}
|