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 Contour C.CvContour
|
||||
|
||||
type ContourType struct {
|
||||
mode C.int
|
||||
method C.int
|
||||
offset Point
|
||||
}
|
||||
|
||||
const (
|
||||
CV_RETR_EXTERNAL = C.CV_RETR_EXTERNAL
|
||||
CV_RETR_LIST = C.CV_RETR_LIST
|
||||
|
|
|
|||
|
|
@ -53,13 +53,9 @@ func Crop(src *IplImage, x, y, width, height int) *IplImage {
|
|||
return dest
|
||||
}
|
||||
|
||||
func CreateContourType() *ContourType {
|
||||
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.
|
||||
/* Returns a Seq of countours in an image, detected according to the parameters.
|
||||
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)
|
||||
header_size := (C.size_t)(unsafe.Sizeof(C.CvContour{}))
|
||||
var seq *C.CvSeq
|
||||
|
|
@ -68,9 +64,9 @@ func (this *ContourType) FindContours(image *IplImage) *Seq {
|
|||
storage,
|
||||
&seq,
|
||||
C.int(header_size),
|
||||
this.mode,
|
||||
this.method,
|
||||
C.cvPoint(C.int(this.offset.X), C.int(this.offset.Y)))
|
||||
C.int(mode),
|
||||
C.int(method),
|
||||
C.cvPoint(C.int(offset.X), C.int(offset.Y)))
|
||||
|
||||
return (*Seq)(seq)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,7 @@ func TestFindContours(t *testing.T) {
|
|||
defer edges.Release()
|
||||
Canny(grayscale, edges, 50, 200, 3)
|
||||
|
||||
contourType := CreateContourType()
|
||||
seq := contourType.FindContours(edges)
|
||||
seq := edges.FindContours(CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point{0, 0})
|
||||
defer seq.Release()
|
||||
|
||||
contours := CreateImage(grayscale.Width(), grayscale.Height(), grayscale.Depth(), grayscale.Channels())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue