首頁  >  文章  >  後端開發  >  在 macOS 上使用 gocv 時間歇性出現 NSInternalInconsistencyException

在 macOS 上使用 gocv 時間歇性出現 NSInternalInconsistencyException

WBOY
WBOY轉載
2024-02-06 11:00:07945瀏覽

在 macOS 上使用 gocv 时间歇性出现 NSInternalInconsistencyException

問題內容

我有使用 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()
}

以上是在 macOS 上使用 gocv 時間歇性出現 NSInternalInconsistencyException的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除