nakkaya / vision

OpenCV wrapper for Clojure
http://nakkaya.com/vision.html
132 stars 17 forks source link

Issue opening #12

Open adamlwgriffiths opened 7 years ago

adamlwgriffiths commented 7 years ago

I'm trying to run the face_detect example, but am encountering this error when running:

$ lein run
OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /tmp/opencv-20170417-5320-58dniz/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-20170417-5320-58dniz/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

The xml came straight from homebrew and runs fine with the python bindings.

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier("/usr/local/Cellar/opencv/2.4.13.2/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml")

This is the clojure code I'm trying to run, it's the example code with a different file path for the XML.

(ns test
  (:use [vision core] :reload-all))

(let [state (ref true)]

  (defn start []
    (let [capture (capture-from-cam 0)
          cascade (load-cascade "/usr/local/Cellar/opencv/2.4.13.2/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml")]
      (dosync (ref-set state true))
      (future
       (while @state
         (let [curr (query-frame capture)
               faces (haar-detect-objects curr cascade 1.1 2 :haar-do-canny-prunning [40 40] [100 100])]

           (doseq [[x y w h] faces]
             (rectangle curr [x y] [(+ w x) (+ h y)] java.awt.Color/red 5))

           (view :cam curr)))
       (release capture))))

  (defn stop []
    (dosync (ref-set state false))))

(defn -main [& args]
  (start))

The other examples I've tried run without issue (I haven't tried them all).