Go / OpenCV:过滤轮廓

I'm using this library to write an OpenCV app in Golang. I'm trying to do something very basic but can't seem to make it work. I simply want to take a set of contours, remove those contours that don't have a minimum area, then return the filtered result.

This is the current state of my code:

// given *opencv.Seq and image, draw all the contours
func opencvDrawRectangles(img *opencv.IplImage, contours *opencv.Seq) {
    for c := contours; c != nil; c = c.HNext() {
        rect := opencv.BoundingRect(unsafe.Pointer(c))
        fmt.Println("Rectangle: ", rect.X(), rect.Y())
        opencv.Rectangle(img, 
            opencv.Point{ rect.X(), rect.Y() }, 
            opencv.Point{ rect.X() + rect.Width(), rect.Y() + rect.Height() },
            opencv.ScalarAll(255.0), 
            1, 1, 0)
    }
}

// return contours that meet the threshold
func opencvFindContours(img *opencv.IplImage, threshold float64) *opencv.Seq {
    defaultThresh := 10.0
    if threshold == 0.0 {
        threshold = defaultThresh
    }
    contours := img.FindContours(opencv.CV_RETR_LIST, opencv.CV_CHAIN_APPROX_SIMPLE, opencv.Point{0, 0})

    if contours == nil {
        return nil
    }

    defer contours.Release()

    threshContours := opencv.CreateSeq(opencv.CV_SEQ_ELTYPE_POINT,
                            int(unsafe.Sizeof(opencv.CvPoint{})))

    for ; contours != nil; contours = contours.HNext() {
        v := *contours
        if opencv.ContourArea(contours, opencv.WholeSeq(), 0) > threshold {
            threshContours.Push(unsafe.Pointer(&v))
        }
    }
    return threshContours
}

In opencvFindContours, I'm trying to add to a new variable only those contours that meet the area threshold. When I take those results and pass them into opencvDrawRectangles, contours is filled with nonsense data. If, on the other hand, I just return contours directly in opencvFindContours then pass that to opencvDrawRectangles, I get the rectangles I would expect based on the motion detected in the image.

Does anyone know how to properly filter the contours using this library? I'm clearly missing something about how these data structures work, just not sure what.

However it's best implemented, the main thing I'm trying to figure out here is simply how to take a sequence of contours and filter out ones that fall below a certain area.... all the c++ examples I've seen make this look pretty easy, but I'm finding it quite challenging using a Go wrapper of the C API.

You're taking the Sizeof the pointer that would be returned by CreateSeq. You probably want the Sizeof the struct opencv.CVPoint{} instead.