Skip to content

Commit

Permalink
Starter utility for manipulating pixel colors
Browse files Browse the repository at this point in the history
  • Loading branch information
mpsdantas committed Mar 11, 2020
1 parent 22aa153 commit c3ef6cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cvutils.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/mpsdantas/cvutils

go 1.13

require gocv.io/x/gocv v0.22.0
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gocv.io/x/gocv v0.22.0/go.mod h1:7Ju5KbPo+R85evmlhhKPVMwXtgDRNX/PtfVfbToSrLU=

0 comments on commit c3ef6cc

Please sign in to comment.