{"id":18000171,"url":"https://github.com/elixir-vision/picam","last_synced_at":"2025-04-06T11:08:16.026Z","repository":{"id":57533334,"uuid":"93262412","full_name":"elixir-vision/picam","owner":"elixir-vision","description":"Elixir library used to capture MJPEG video on a Raspberry Pi using the camera module.","archived":false,"fork":false,"pushed_at":"2020-08-06T14:29:08.000Z","size":151,"stargazers_count":122,"open_issues_count":10,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T09:09:24.774Z","etag":null,"topics":["camera","elixir","hacktoberfest","mjpeg","nerves-project","raspberry-pi","video"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-vision.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":"2017-06-03T17:06:55.000Z","updated_at":"2025-02-04T21:04:52.000Z","dependencies_parsed_at":"2022-09-26T18:20:57.333Z","dependency_job_id":null,"html_url":"https://github.com/elixir-vision/picam","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-vision%2Fpicam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-vision%2Fpicam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-vision%2Fpicam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-vision%2Fpicam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-vision","download_url":"https://codeload.github.com/elixir-vision/picam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471519,"owners_count":20944158,"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":["camera","elixir","hacktoberfest","mjpeg","nerves-project","raspberry-pi","video"],"created_at":"2024-10-29T23:10:00.604Z","updated_at":"2025-04-06T11:08:16.009Z","avatar_url":"https://github.com/elixir-vision.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Picam\n\n[![Hex version](https://img.shields.io/hexpm/v/picam.svg \"Hex version\")](https://hex.pm/packages/picam)\n\nPicam is an Elixir library that provides a simple API for streaming MJPEG video and capturing JPEG stills using the camera module on Raspberry Pi devices running Linux.\n\nFeatures currently supported by the API:\n\n  - Set sharpness, contrast, brightness, saturation, ISO, and shutter speed values\n  - Set the exposure, sensor, metering, and white balance modes\n  - Set image and color effects\n  - Rotate and flip the image vertically and horizontally\n  - Set the exposure compensation (EV) level\n  - Change the image size\n  - Adjust JPEG fidelity through quality level, restart intervals, and region of interest\n  - Enable or disable video stabilization\n  - Adjust the video framerate\n  - Render fullscreen or windowed video preview to HDMI and CSI displays\n\nFor specifics on the above features, please consult the [Hex docs].\n\n## Requirements\n\n| Requirement |        | Notes  |\n| ----------- | ------ | ------ |\n| Host Device | Raspberry Pi 1, 2, 3, Zero/W | Zero and Zero W require a [special ribbon cable] |\n| Operating System  | Linux | Works out of the box with Raspbian and Nerves builds |\n| Camera Module | [V1], [V2] | Regular, NoIR. Note for V2 module, `gpu_mem` in `/boot/config.txt` must be set \u003e= `192` |\n| C Libraries | Broadcom VideoCore | Located in `/opt/vc` by default.  Override with `VIDEOCORE_DIR` |\n\n## Installation\n\nThe package can be installed by adding `picam` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:picam, \"~\u003e 0.4.0\"}]\nend\n```\n\n## Usage\n\n`Picam` uses a port application named `raspijpgs` that interfaces with the underlying Multi-Media Abstraction Layer (MMAL) API in VideoCore.  The port is started by the `Picam.Camera` process.\n\nFor example, to write a JPEG still using the `:sketch` image effect to `/tmp/frame.jpg`:\n\n```elixir\niex(1)\u003e Picam.Camera.start_link\n{:ok, #PID\u003c0.160.0\u003e}\n\niex(2)\u003e Picam.set_img_effect(:sketch)\n:ok\n\niex(3)\u003e Picam.set_size(640, 0) # 0 automatically calculates height\n:ok\n\niex(4)\u003e File.write!(Path.join(System.tmp_dir!, \"frame.jpg\"), Picam.next_frame)\n:ok\n\niex(5)\u003e Picam.set_img_effect(:none) # Disable the effect\n:ok\n```\n\nIf you receive an `:unexpected_exit` error immediately after starting the `Picam.Camera` process and you're using a V2 camera module, please check that you've set `gpu_mem` to a value \u003e= 192 in `/boot/config.txt`.  You can verify this has taken effect in your terminal using `vcgencmd get_mem gpu`.\n\nMore than likely you'll want to put the `Picam.Camera` process in your supervision tree rather than starting it manually:\n\n```elixir\n# lib/my_app/application.ex\n\nchildren = [\n  worker(Picam.Camera, []),\n  # ...\n]\n```\n\n## Faking the camera for development and testing\n\nIn order to facilitate running in `dev` and `test` modes on your development host, you can override the real `Picam.Camera` worker with `Picam.FakeCamera` by setting the `:camera` config option:\n\n```elixir\n# config.exs\n\n# ...\n\nimport_config \"#{Mix.Project.config[:target]}.exs\"\n```\n\n```elixir\n# config/host.exs\n\nuse Mix.Config\nconfig :picam, camera: Picam.FakeCamera\n```\n\nThis will cause `Picam` to use the `FakeCamera` back-end instead of the real `Camera` back-end, which streams a static image of the specified `size` at approximately the specified `fps` rate (using a naïve `sleep`-based delay between frames).\nIn order for this to work, you will need to make sure you are staring the matching worker for your environment:\n\n```elixir\n# lib/my_app/application.ex\n\ncamera = Application.get_env(:picam, :camera, Picam.Camera)\n\nchildren = [\n  worker(camera, []),\n  # ...\n]\n```\n\nWhen using the `FakeCamera`, all the normal `Picam` API commands will be validated but silently ignored, with the following exceptions:\n\n* `Picam.set_fps/1` will set the desired frame rate (in frames per second)\n* `Picam.set_size/2` only has static images built-in for the following resolutions:\n\n  * 1920 x 1080\n  * 1280 x 720\n  * 640 x 480\n\n  If any other resolution is specified, the static image will default back to 1280 x 720.\n  If you want to test with an image of a particular size or with specific image contents, you can specify your own image with `Picam.FakeCamera.set_image/1`, which accepts a JPEG-encoded binary.\n\n  For example:\n\n  ```elixir\n  \"image.jpg\"\n  |\u003e File.read!()\n  |\u003e Picam.FakeCamera.set_image()\n  ```\n\n## Examples\n\nThe [examples] directory is where you can find other useful demos of `Picam` in action.  More examples will be added over time.\n\n| Directory    | Demo   |\n| ------------ | ------ |\n| [picam_http] | Streaming MJPEG video using [plug] |\n\n## Limitations\n\n- Currently only one camera is supported.  If you intend to use more than one camera through an add-on compute module, please [submit an issue].\n\n## Copyright and License\n\nCopyright (c) 2013-2017, Broadcom Europe Ltd, Silvan Melchior, James Hughes, Frank Hunleth, Jeff Smith\n\nPicam source code is licensed under the [BSD 3-Clause License].\n\n[//]: #\n[special ribbon cable]: \u003chttps://www.adafruit.com/product/3157\u003e\n[V1]: \u003chttps://www.raspberrypi.org/products/camera-module/\u003e\n[V2]: \u003chttps://www.raspberrypi.org/products/camera-module-v2/\u003e\n[Hex docs]: \u003chttps://hexdocs.pm/picam\u003e\n[examples]: \u003chttps://github.com/electricshaman/picam/tree/master/examples\u003e\n[picam_http]: \u003chttps://github.com/electricshaman/picam/tree/master/examples/picam_http\u003e\n[plug]: \u003chttps://hexdocs.pm/plug\u003e\n[submit an issue]: \u003chttps://github.com/electricshaman/picam/issues/new\u003e\n[BSD 3-Clause License]: \u003chttps://github.com/electricshaman/picam/blob/master/LICENSE\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-vision%2Fpicam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-vision%2Fpicam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-vision%2Fpicam/lists"}