    :bw-mat (Mat.)
    :camera (cv/camera 0)
    :p-image (q/create-image WIDTH HEIGHT :rgb)
-   :detector (Detector. @this 255)})
+   :detector (do
+               ; Applet must exist before Detector can be created
+               (Thread/sleep 1000)
+               (Detector. @this 255))})
 
 (defn gray-mat->bw-mat [gray-mat bw-mat]
-  (Imgproc/threshold gray-mat bw-mat 128 255 Imgproc/THRESH_BINARY)
+  (Imgproc/threshold gray-mat bw-mat BW-THRESH 255 Imgproc/THRESH_BINARY)
   bw-mat)
 
 (defn update-gray-mat

             40 40))

(defn draw-centroids [{:keys [detector]}]
  (q/push-style)
  (q/no-stroke)
  (q/fill 0 255 0 80)
  (if (< 0 (.getBlobsNumber detector))
    (dorun
     (map #(draw-centroid detector %)
          (range 0 (.getBlobsNumber detector)))))
  (q/pop-style))

(defn draw [state]
  (let [{:keys [p-image]} state]

  :on-close on-close
  :middleware [m/fun-mode])

(reset! this videotest)
