{"id":19288354,"url":"https://github.com/techascent/tech.opencv","last_synced_at":"2025-12-12T01:07:16.569Z","repository":{"id":62435413,"uuid":"151292266","full_name":"techascent/tech.opencv","owner":"techascent","description":"Opencv bindings via the tech.datatype library and javacpp","archived":false,"fork":false,"pushed_at":"2020-06-15T16:33:52.000Z","size":402,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-07-13T04:46:57.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techascent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-02T17:07:05.000Z","updated_at":"2023-11-09T04:23:34.000Z","dependencies_parsed_at":"2022-11-01T21:02:37.636Z","dependency_job_id":null,"html_url":"https://github.com/techascent/tech.opencv","commit_stats":null,"previous_names":["tech-ascent/tech.opencv"],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.opencv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.opencv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.opencv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.opencv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techascent","download_url":"https://codeload.github.com/techascent/tech.opencv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223888368,"owners_count":17220083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T22:08:46.958Z","updated_at":"2025-12-12T01:07:11.546Z","avatar_url":"https://github.com/techascent.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tech.opencv\n\n[![Clojars Project](https://clojars.org/techascent/tech.opencv/latest-version.svg)](https://clojars.org/techascent/tech.opencv)\n\nOpenCV bindings via javacpp.\n\nYou can read a bit more about it [here](http://techascent.com/blog/opencv-love.html).\n\n## Usage\n\n\n### Basic\n\nLoad/save, resize, clone.  Becase opencv matrixes need to be released and thus aren't garbage collected they are bound to a think.resource.core/resource-context which unwinds in a way similar to C++ RAII or with-open.\n\nBindings to clojure.core.matrix and tech.datatype allow you to get into the properties of\na loaded matrix.\n\n```clojure\n(require '[tech.opencv :as opencv])\n(require '[tech.v2.datatype :as dtype])\n(require '[tech.v2.datatype.functional :as dfn])\n\n      (let [src-img (opencv/load \"test/data/test.jpg\")\n          dest-img (opencv/clone src-img)\n          num-elems (dtype/ecount src-img)\n          ;;Save as jpg and spend an hour scratching head...\n          test-fname \"darken.png\"\n          convert-fn (fn [input]\n                       (float (Math/floor (* 0.5 input))))]\n      ;;darken img.  Float data is range 0-255\n      (delete-test-file! test-fname)\n      (-\u003e (unary-op/unary-reader :int16 (unchecked-short (quot x 2)) src-img)\n          (dtype/copy! dest-img)\n          (opencv/save test-fname))\n      (let [result (opencv/load test-fname)\n            result-data (float-array num-elems)]\n        (dtype/copy! result result-data)\n        (is (dfn/equals (take 10 result-data)\n                        (map convert-fn (take 10 (dtype/-\u003ereader src-img)))))))\n```\n\n![darker image](images/darken.png)\n\n\n### Datatype Tensors\n\nIntegrated with the tech.v2.tensor math system:\n\n```clojure\n(require '[tech.v2.tensor :as dtt])\n    (let [test-image (opencv/load \"test/data/test.jpg\")\n          ;;Select is in-place so this did not change the image at all.\n          bgr-image (dtt/select test-image :all :all [2 1 0])\n\t\t  ;;Copy src dest\n          dest-image (dtype/copy! bgr-image (dtype/from-prototype test-image))]\n      ;;The datatype library has the convention that the thing that is mutated\n\t  ;;is returned from the function.\n      (opencv/save dest-image \"bgr.jpg\"))\n```\n\n![bgr image](images/bgr.jpg)\n\n\nA bit more involved example:\n\n\n```clojure\n   (let [test-image (opencv/load \"test/data/test.jpg\")\n         result\n         (-\u003e test-image\n             (dtt/select :all :all [2 1 0])\n             (dfn/+ 50)\n             ;;Clamp top end to 0-255\n             (dfn/min 255)\n             (dtype/copy! (dtype/from-prototype test-image)))]\n\n      (opencv/save result \"bgr-lighten.jpg\"))\n```\n\n![lightened bgr](images/bgr-lighten.jpg)\n\n\n\n### Further Reference\n\n\nPlease refer to the [tests](test/tech/opencv_test.clj),\n[tensor tests](test/tech/opencv_compute_test.clj),\nand [opencv.clj](src/tech/opencv.clj).\n\n\n## License\n\nCopyright © 2019 [Tech Ascent, LLC](https://github.com/tech-ascent).\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechascent%2Ftech.opencv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechascent%2Ftech.opencv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechascent%2Ftech.opencv/lists"}