Refactored FindCountours to pass all parameters needed
This commit is contained in:
parent
02da2d4700
commit
f812503e45
3 changed files with 6 additions and 17 deletions
|
|
@ -661,12 +661,6 @@ type Graph C.CvGraph
|
||||||
type Chain C.CvChain
|
type Chain C.CvChain
|
||||||
type Contour C.CvContour
|
type Contour C.CvContour
|
||||||
|
|
||||||
type ContourType struct {
|
|
||||||
mode C.int
|
|
||||||
method C.int
|
|
||||||
offset Point
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CV_RETR_EXTERNAL = C.CV_RETR_EXTERNAL
|
CV_RETR_EXTERNAL = C.CV_RETR_EXTERNAL
|
||||||
CV_RETR_LIST = C.CV_RETR_LIST
|
CV_RETR_LIST = C.CV_RETR_LIST
|
||||||
|
|
|
||||||
|
|
@ -53,13 +53,9 @@ func Crop(src *IplImage, x, y, width, height int) *IplImage {
|
||||||
return dest
|
return dest
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateContourType() *ContourType {
|
/* Returns a Seq of countours in an image, detected according to the parameters.
|
||||||
return &ContourType{mode: CV_RETR_EXTERNAL, method: CV_CHAIN_APPROX_SIMPLE, offset: Point{0, 0}}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns a Seq of countours in an image, detected according to the parameters in ContourType.
|
|
||||||
Caller must Release() the Seq returned */
|
Caller must Release() the Seq returned */
|
||||||
func (this *ContourType) FindContours(image *IplImage) *Seq {
|
func (image *IplImage) FindContours(mode, method int, offset Point) *Seq {
|
||||||
storage := C.cvCreateMemStorage(0)
|
storage := C.cvCreateMemStorage(0)
|
||||||
header_size := (C.size_t)(unsafe.Sizeof(C.CvContour{}))
|
header_size := (C.size_t)(unsafe.Sizeof(C.CvContour{}))
|
||||||
var seq *C.CvSeq
|
var seq *C.CvSeq
|
||||||
|
|
@ -68,9 +64,9 @@ func (this *ContourType) FindContours(image *IplImage) *Seq {
|
||||||
storage,
|
storage,
|
||||||
&seq,
|
&seq,
|
||||||
C.int(header_size),
|
C.int(header_size),
|
||||||
this.mode,
|
C.int(mode),
|
||||||
this.method,
|
C.int(method),
|
||||||
C.cvPoint(C.int(this.offset.X), C.int(this.offset.Y)))
|
C.cvPoint(C.int(offset.X), C.int(offset.Y)))
|
||||||
|
|
||||||
return (*Seq)(seq)
|
return (*Seq)(seq)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,7 @@ func TestFindContours(t *testing.T) {
|
||||||
defer edges.Release()
|
defer edges.Release()
|
||||||
Canny(grayscale, edges, 50, 200, 3)
|
Canny(grayscale, edges, 50, 200, 3)
|
||||||
|
|
||||||
contourType := CreateContourType()
|
seq := edges.FindContours(CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point{0, 0})
|
||||||
seq := contourType.FindContours(edges)
|
|
||||||
defer seq.Release()
|
defer seq.Release()
|
||||||
|
|
||||||
contours := CreateImage(grayscale.Width(), grayscale.Height(), grayscale.Depth(), grayscale.Channels())
|
contours := CreateImage(grayscale.Width(), grayscale.Height(), grayscale.Depth(), grayscale.Channels())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue