From d4b5ecc0f98aa8168ca3ef13e182c688591298ae Mon Sep 17 00:00:00 2001 From: niten Date: Sat, 18 Mar 2023 18:24:59 -0700 Subject: [PATCH] Add summary, returning probs & url --- src/objectifier_client/core.clj | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/objectifier_client/core.clj b/src/objectifier_client/core.clj index f648f1c..b4a3473 100644 --- a/src/objectifier_client/core.clj +++ b/src/objectifier_client/core.clj @@ -12,14 +12,21 @@ (get-labels! [_ image-data]) (get-detections! [_ image-data]) (get-highlights! [_ image-data]) - (get-probabilities! [_ image-data])) + (get-probabilities! [_ image-data]) + (get-summary! [_ image-data])) (defn- url->string [url] (.toExternalForm url)) (defn- build-url [{:keys [scheme host port]}] (url->string (URL. scheme host port "/images"))) -(defn- send-image! [url image-bytes] +(defn- send-image! [verbose url image-bytes] + (when verbose + (println (str "sending " + (count image-bytes) + " to " + url + " for object detection"))) (let [input-stream (ByteArrayInputStream. image-bytes)] (client/post url {:multipart [{:name "image" @@ -39,12 +46,10 @@ :reason (:reason-phrase resp) :response resp}))) -(defn- pthru [o] (pprint o) o) - -(defrecord ObjectifierClient [scheme host port] +(defrecord ObjectifierClient [scheme host port verbose] IObjectifierClient (get! [self image-data] - (process-response (send-image! (build-url (pthru self)) image-data))) + (process-response (send-image! verbose (build-url self) image-data))) (get-labels! [self image-data] (-> (get! self image-data) @@ -61,10 +66,18 @@ (get-probabilities! [self image-data] (into {} (map (juxt (comp keyword :label) :confidence)) - (get-detections! self image-data)))) + (get-detections! self image-data))) + + (get-summary! [self image-data] + (let [result (get! self image-data)] + {:output (:output result) + :objects (into {} + (map (juxt (comp keyword :label) :confidence)) + (get-detections! self image-data))}))) (defn define-connection - [& {:keys [scheme host port] - :or {scheme "http" - port 80}}] - (->ObjectifierClient scheme host port)) + [& {:keys [scheme host port verbose] + :or {scheme "http" + port 80 + verbose false}}] + (->ObjectifierClient scheme host port verbose))