-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starter utility for manipulating pixel colors
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |