-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathopencv_cxcore.go
60 lines (53 loc) · 1.01 KB
/
opencv_cxcore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package opencv
/*
#cgo CFLAGS: -I./opencv110/cxcore/include
#include <cxcore.h>
*/
import "C"
import (
"image"
"image/color"
)
func (p *IplImage) ColorModel() color.Model {
return color.RGBAModel
}
func (p *IplImage) Bounds() image.Rectangle {
return image.Rect(0, 0, p.GetWidth(), p.GetHeight())
}
func (p *IplImage) At(x, y int) color.Color {
if !(image.Point{x, y}.In(p.Bounds())) {
return color.RGBA{}
}
i := p.PixOffset(x, y)
d := p.GetImageData()
switch p.GetChannels() {
case 1:
return color.RGBA{
R: d[i+0],
G: d[i+0],
B: d[i+0],
A: 0xFF,
}
case 3:
return color.RGBA{
R: d[i+2],
G: d[i+1],
B: d[i+0],
A: 0xFF,
}
case 4:
return color.RGBA{
R: d[i+0],
G: d[i+1],
B: d[i+2],
A: d[i+3],
}
}
return color.RGBA{}
}
func (p *IplImage) PixOffset(x, y int) int {
return y*p.GetWidthStep() + x
}