    :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

(defn update-gray-p-image
  [{:keys [frame-mat gray-mat output-mat b-array i-array] :as state}]
  (if frame-mat
    (let [orig-frame-mat frame-mat
          wrapped-state (-> state
                            (assoc-in [:frame-mat] gray-mat))]
      (-> wrapped-state
          (update-in [:p-image] #(cv/gray-mat->p-img gray-mat output-mat b-array i-array %))
          (assoc-in [:frame-mat] orig-frame-mat)))
    state))

(defn update-blobs [{:keys [detector p-image] :as state}]
  (.imageFindBlobs detector p-image)
  (.loadBlobsFeatures detector)
  (.findCentroids detector)
  state)

(defn update [state]

(def PIX-CNT1 (* WIDTH HEIGHT 4))
(def PIX-CNT2 (* WIDTH HEIGHT))

(def BW-THRESH 200) ; between 0-255 (gray -> BW cut-off)
(def this (atom nil))

;; bArray is the temporary byte array buffer for OpenCV cv::Mat.
;; iArray is the temporary integer array buffer for PImage pixels.
(defn setup []
  (q/frame-rate 60)
  {:b-array (byte-array PIX-CNT1)
   :i-array (int-array PIX-CNT2)
