diff --git a/cvutils.go b/cvutils.go new file mode 100644 index 0000000..ea9c7bf --- /dev/null +++ b/cvutils.go @@ -0,0 +1,32 @@ +package cvutils + +import "gocv.io/x/gocv" + +type Image struct { + Mat gocv.Mat +} + +type Color struct { + Red uint8 + Green uint8 + Blue uint8 +} + +func (m Image) GetColor(row int, col int) Color { + ch := m.Mat.Channels() + color := Color{} + + color.Blue = m.Mat.GetUCharAt(row, col*ch+0) + color.Green = m.Mat.GetUCharAt(row, col*ch+1) + color.Red = m.Mat.GetUCharAt(row, col*ch+2) + + return color +} + +func (m Image) SetColor(row int, col int, color Color) { + ch := m.Mat.Channels() + + m.Mat.SetUCharAt(row, col*ch+0, color.Blue) + m.Mat.SetUCharAt(row, col*ch+1, color.Green) + m.Mat.SetUCharAt(row, col*ch+2, color.Red) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..059d6cd --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/mpsdantas/cvutils + +go 1.13 + +require gocv.io/x/gocv v0.22.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2b8d7c3 --- /dev/null +++ b/go.sum @@ -0,0 +1 @@ +gocv.io/x/gocv v0.22.0/go.mod h1:7Ju5KbPo+R85evmlhhKPVMwXtgDRNX/PtfVfbToSrLU=