hybridgroup / gocv

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, OpenCV Contrib, and OpenVINO.
https://gocv.io
Other
6.65k stars 864 forks source link

AdaptiveThreshold, FindContours runtime error #451

Closed ii64 closed 4 years ago

ii64 commented 5 years ago

Runtime Error

Hi, I just build opencv 4.0.1 then i tried to compile the program, and it's success but when the application run AdaptiveThreshold, FindContours it got runtime error. I wonder is there any mistake?

This is the sample code

package main
import (
    "fmt"
    _ "image"
    cv2 "gocv.io/x/gocv"
)
func main() {
    path := "yuuki_tatsuya_b.jpg"
    window := cv2.NewWindow("testing")
    img := cv2.IMRead(path, cv2.IMReadColor)
    if img.Empty() {
        fmt.Println("cant read image")
        fmt.Println("end.")
        return
    }
    imgray := cv2.NewMat()
    cv2.CvtColor(img, &imgray, cv2.ColorBGRToGray)
    //th1 := cv2.NewMat() // got error
    //cv2.AdaptiveThreshold(img, &th1, 255.0, cv2.AdaptiveThresholdGaussian, cv2.ThresholdBinary, 1023, 0.0)
    th2 := cv2.NewMat()
    cv2.Threshold(img, &th2, 8.0, 255.0, cv2.ThresholdBinary)

    contours := cv2.FindContours(img, cv2.RetrievalExternal, cv2.ChainApproxSimple) // got error too
    fmt.Printf("%+v\n", contours)

    cv2.IMWrite("testing.jpg", imgray)
    cv2.IMWrite("testing2.jpg", th2)

    for { 
        window.IMShow(img)
        if window.WaitKey(1) >= 0 {
            break
        }
    }
}

And got error: image

deadprogram commented 4 years ago

Closing due to age, please reopen if needed. Thank you.