{"id":14977931,"url":"https://github.com/lemariva/rpifocus","last_synced_at":"2025-10-28T07:30:37.937Z","repository":{"id":109048859,"uuid":"309182159","full_name":"lemariva/rPIFocus","owner":"lemariva","description":"Add autofocus to the 16 mm Telephoto Lens mounted on the Raspberry Pi HQ Camera (Raspberry Pi Microservice Application)","archived":false,"fork":false,"pushed_at":"2021-01-23T21:47:20.000Z","size":1378,"stargazers_count":28,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-01T12:44:09.509Z","etag":null,"topics":["microservices-application","raspberry-pi","raspberry-pi-camera","raspberry-pi-hq-camera"],"latest_commit_sha":null,"homepage":"https://lemariva.com/blog/2020/12/raspberry-pi-hq-camera-autofocus-telephoto-lens","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lemariva.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-01T20:28:04.000Z","updated_at":"2024-05-20T08:05:05.000Z","dependencies_parsed_at":"2023-03-27T08:46:30.187Z","dependency_job_id":null,"html_url":"https://github.com/lemariva/rPIFocus","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"8878f38150a94d14f34348daca1d4646be425fa1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemariva%2FrPIFocus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemariva%2FrPIFocus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemariva%2FrPIFocus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemariva%2FrPIFocus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemariva","download_url":"https://codeload.github.com/lemariva/rPIFocus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238608354,"owners_count":19500365,"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":["microservices-application","raspberry-pi","raspberry-pi-camera","raspberry-pi-hq-camera"],"created_at":"2024-09-24T13:56:34.042Z","updated_at":"2025-10-28T07:30:37.223Z","avatar_url":"https://github.com/lemariva.png","language":"Python","readme":"# Autofocus for the 16mm telephoto lens mounted on a Raspberry Pi HQ Camera.\nAs you may have already noticed, the Raspberry Pi HQ Camera lenses don't have any autofocus functionality. This project includes the hardware design, firmware and software to add autofocus functionality to those lenses. In this case, I use the 16mm telephoto lens.\nThe project is divided into two repositories. This repository includes the code of the Microservice application, whereas [lemariva/uPyFocus](https://github.com/lemariva/uPyFocus) includes the firmware for the M5Stack that controls the motors to rotate the Lens focus and aperture.\n\nA detailed article about the application can be found on [Raspberry Pi HQ Camera: Autofocus for the Telephoto Lens (JiJi)](https://lemariva.com/blog/2020/12/raspberry-pi-hq-camera-autofocus-telephoto-lens).\n\n## Video\n[![Autofocus for the Raspberry HQ Camera](https://img.youtube.com/vi/PrbyPmq_Z7Q/0.jpg)](https://www.youtube.com/watch?v=PrbyPmq_Z7Q)\n\n## Photo examples\n|          |          |          |          |\n|:--------:|:--------:|:--------:|:--------:|\n|\u003cimg src=\"https://lemariva.com/storage/app/uploads/public/5fe/c63/443/5fec63443a76c981023585.jpg\" alt=\"Focus Type: Box - Background focused\" width=\"300px\"\u003e|\u003cimg src=\"https://lemariva.com/storage/app/uploads/public/5fe/c63/392/5fec6339224b0320000410.jpg\" alt=\"Focus Type: Box - Nanoblock bird focused\" width=\"300px\"\u003e|\u003cimg src=\"https://lemariva.com/storage/app/uploads/public/5fe/c63/4ab/5fec634ab3092068212455.jpg\" alt=\"Focus Type: Box - Nanoblock bird focused. Diff. illum \u0026 cam. aperture\" width=\"300px\"\u003e|\u003cimg src=\"https://lemariva.com/storage/app/uploads/public/5fe/c63/3cd/5fec633cda6af591369087.jpg\" alt=\"Focus Type: Object detector - Teddy bear focused\" width=\"300px\"\u003e|\n|Focus Type: Box \u003cbr/\u003e Background focused (\u003ca href=\"https://lemariva.com/storage/app/media/blog_imgs/hqcamera/hq_camera_background_focused.jpg\"\u003edownload\u003c/a\u003e)|Focus Type: Box \u003cbr/\u003eNanoblock bird focused (\u003ca href=\"https://lemariva.com/storage/app/media/blog_imgs/hqcamera/hq_camera_nanoblock_bird_focused.jpg\"\u003edownload\u003c/a\u003e)|Focus Type: Box \u003cbr/\u003eNanoblock bird focused. \u003cbr/\u003e Diff. illum \u0026 cam. aperture (\u003ca href=\"https://lemariva.com/storage/app/media/blog_imgs/hqcamera/hq_camera_nanoblock_bird_focused_2.jpg\"\u003edownload\u003c/a\u003e)|Focus Type: Object detector  \u003cbr/\u003eTeddy bear focused (\u003ca href=\"https://lemariva.com/storage/app/media/blog_imgs/hqcamera/hq_camera_teddy_bear_focused.jpg\"\u003edownload\u003c/a\u003e)|\n\n## Simple PCB schematic\nInside the folder `pcb`, you'll find the board design and schematic files (Eagle), to order the PCB. I added also the Gerber files that I used by \u003ca rel=\"noopener noreferrer\" href=\"https://jlcpcb.com/\"\u003ejlcpcb\u003c/a\u003e.\n\n|          |\n|:--------:|\n|\u003cimg src=\"https://lemariva.com/storage/temp/public/625/29e/b52/5feca3f70da50778861950__899.jpg\" alt=\"Simple PCB schematic.\" width=\"400px\"\u003e|\n|Simple PCB schematic.|\n\n## Start the Microservices Application\nThe application that runs on the Raspberry Pi is a Microservices application. That means different services are orchestrated to offer an application. The orchestration is performed by docker-compose and the services are containerized using Docker.\n\nTo install Docker and `docker-compose` on the Raspberry Pi, type the following on a Terminal:\n```\n# Docker\ncurl -sSL https://get.docker.com | sh\nsudo usermod -aG docker pi\n\n# docker-compose\nsudo pip3 -v install docker-compose\n\n# usually you need these dependencies\nsudo apt-get install -y libffi-dev libssl-dev\nsudo apt-get install -y python3 python3-pip\nsudo apt-get remove python-configparser\n```\n\nThe services of the microservices application are the following:\n* **webapp**: it provides the frontend application (webserver). It is programmed in Angular.\n* **backend**: it communicates with the frontend via a RestAPI (Flask server), controls the camera, sends the signals to the M5Stack to control the motors, sends the signals and data to the other services to identify objects and take photos. Basically, it is the core service. It is programmed in Python.\n* **obj-detector**: it receives an image over UDP and identifies the object on it and returns a JSON message. It is programmed in Python. It uses TensorFlow and connects to the Coral USB Accelerator to process the data in real-time.\n* **photo-service**: it receives a signal via RestAPI (Flask server) to take photos and it processes them to create HDR photos. It is programmed in Python and it uses Celery for multitasking/non-blocking response to the RestAPI.\n* **redis**: Celery uses this service to schedule the tasks.\n\nTo start the Microservices application, follow these steps:\n1. Download the `docker-compose.yml` file or just clone the complete [lemariva/rPIFocus](https://github.com/lemariva/rPIFocus) repository:\n    ```sh\n    git clone https://github.com/lemariva/rPIFocus.git\n    ```\n2. Open the `docker-compose.yml` file and change the `HOST_M5STACK=\u003cip-address\u003e` with the IP of your M5Stack.\n3. Start the application by typing inside the `rPiFocus` folder:\n    ```sh\n    docker-compose up -d\n    ```\n4. Open a browser and visit the URL address: `http://\u003cip-raspberrypi\u003e:4200`, you'll see an interface like in the figure below. ( shhh... I've just noticed that I wrote Raspberry HD camera and not HQ camera... :( )\n5. To stop the application, type:\n    ```sh\n    docker-compose down\n    ```\n\n|           |\n|:---------:|\n|\u003cimg src=\"https://lemariva.com/storage/app/uploads/public/5fe/c60/ad0/5fec60ad052fc228241834.jpg\" alt=\"Webservice Microservices Application\"\u003e|\n|Webservice Microservices Application|\n\n\n## Build containers\nThe Docker images can be built by typing e.g.:\n```sh\ndocker build -t \u003cyour-docker-hub-name\u003e/rpifocus-webapp:1.0.0 webapp\n```\nThen, if you are logged in into Docker Hub, you can push the image by typing:\n```sh\ndocker push \u003cyour-docker-hub-name\u003e/webapp\n# read this tutorial: https://docs.docker.com/docker-hub/access-tokens/#create-an-access-token for login\n```\n\nThen, you need to edit the image names inside the `docker-compose.yml` and start the microservices application again (`docker-compose down` and then `docker-compose up -d`).\n\nAdditionally, I included a `cloudbuild.yaml` file inside each folder. This can be used to build those images using Google Cloud Build. In this article: [M5Stack: Fresh air checker can help you to stay safe from #COVID-19](https://lemariva.com/blog/2020/11/m5stack-fresh-air-helps-stay-safe-from-covid-19), you can find an example of how to do that!\n\n## License\n* GNU General Public License v3.0","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemariva%2Frpifocus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemariva%2Frpifocus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemariva%2Frpifocus/lists"}