Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
Problem:
You're trying load a Haarcascade file with opencv.LoadHaarClassifierCascade()
function in Golang, but you get this error message instead :
OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /tmp/opencv-20170224-77195-1rw28s/opencv-2.4.13.2/modules/core/src/persistence.cpp, line 5008
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20170224-77195-1rw28s/opencv-2.4.13.2/modules/core/src/persistence.cpp:5008: error: (-2) The node does not represent a user object (unknown type?) in function cvRead
package main
import (
"fmt"
"github.com/lazywei/go-opencv/opencv"
)
var faceCascade = new(opencv.HaarCascade)
var eyeCascade = new(opencv.HaarCascade)
func main() {
faceCascade = opencv.LoadHaarClassifierCascade("haarcascade_frontalface_alt.xml")
defer faceCascade.Release()
fmt.Println(faceCascade) // ---- ok
eyeCascade = opencv.LoadHaarClassifierCascade("haarcascade_eye.xml") // --- will crash.
defer eyeCascade.Release()
fmt.Println(eyeCascade)
}
What's going on and how to fix this issue?
Solution:
If you try to load the haarcascade_eye.xml
file that you've downloaded from https://github.com/opencv/opencv/tree/master/data/haarcascades, you will still encounter the same error message. What you need to do is to download the Open CV 2.4.9 version from http://opencv.org/downloads.html and retrieve the haarcascade_eye.xml
from /data/haarcascades
folder.
Pretty sure it is a bug somewhere in OpenCV code.
References:
See also : Golang : Tell color name with OpenCV example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+21.6k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+21.9k Golang : How to run Golang application such as web server in the background or as daemon?
+19.6k Golang : Archive directory with tar and gzip
+7.8k Golang : What fmt.Println() can do and println() cannot do
+6.7k Swift : substringWithRange() function example
+8.2k Golang : Implementing class(object-oriented programming style)
+5.3k Golang *File points to a file or directory ?
+19.7k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+8.8k Golang : Get SPF and DMARC from email headers to fight spam
+4.9k Golang : PGX CopyFrom to insert rows into Postgres database
+14.1k Golang : How to convert a number to words
+6.8k Golang : Gargish-English language translator