我有使用 gocv 的代码(为 opencv 提供 go 语言绑定)。 它只是在图像上绘制一些矩形并显示结果。
func main() {
resp, err := http.get("http://localhost:6060/template-match")
if err != nil {
panic(err)
}
defer resp.body.close()
body, err := ioutil.readall(resp.body)
if err != nil {
panic(err)
}
fmt.println(string(body))
var data response
err = json.unmarshal(body, &data)
if err != nil {
panic(err)
}
srcimage := gocv.imread("./images/src1.jpg", gocv.imreadcolor)
for i := 0; i < len(data.data); i++ {
gocv.rectangle(&srcimage, data.data[i], color.rgba{r: 255}, 2)
}
window := gocv.newwindow("match-result")
window.imshow(srcimage)
gocv.waitkey(0)
fmt.println(data.data, data.msg)
我收到此错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
我真的很困惑,因为这个错误并不是每次都会发生
正确答案
我没有使用过这个库,但看起来这是一个 已知问题 - 而且,由于您提到它只是有时发生,所以听起来该错误确实取决于线程上下文。那里的答案(来自库作者)指向 https://github.com/golang/go /wiki/lockosthread,所以你的主包应该实现类似的东西
func init() {
runtime.LockOSThread()
}