{"id":25658835,"url":"https://github.com/emberfox205/fruititionator","last_synced_at":"2026-04-17T13:31:09.700Z","repository":{"id":238129735,"uuid":"780816270","full_name":"emberfox205/fruititionator","owner":"emberfox205","description":"A Python project to detect fruits using Computer Vision and return their nutrition values.","archived":false,"fork":false,"pushed_at":"2025-02-14T22:06:41.000Z","size":11010,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T13:48:19.047Z","etag":null,"topics":["adafruit-io","ai","fda-api","fruits","machine-learning","ml","mqtt-client","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emberfox205.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":"2024-04-02T08:03:28.000Z","updated_at":"2025-02-21T13:38:50.000Z","dependencies_parsed_at":"2024-05-04T14:29:25.788Z","dependency_job_id":"f68e3119-00ae-47c3-86a0-f057f442888a","html_url":"https://github.com/emberfox205/fruititionator","commit_stats":null,"previous_names":["emberfox205/fruititionator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/emberfox205/fruititionator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emberfox205%2Ffruititionator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emberfox205%2Ffruititionator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emberfox205%2Ffruititionator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emberfox205%2Ffruititionator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emberfox205","download_url":"https://codeload.github.com/emberfox205/fruititionator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emberfox205%2Ffruititionator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31931185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["adafruit-io","ai","fda-api","fruits","machine-learning","ml","mqtt-client","tensorflow"],"created_at":"2025-02-24T00:29:08.621Z","updated_at":"2026-04-17T13:31:09.684Z","avatar_url":"https://github.com/emberfox205.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fruititionator\n\n![Static Badge](https://img.shields.io/badge/Python-3.8.5-blue?style=flat\u0026logo=Python\u0026logoColor=white)\n\nFruititionator is a Python project that leverages Computer Vision to detect fruits in real-time, fetch their nutritional values, and publish this data to an Adafruit IO dashboard using MQTT.\n\n## Installation\n\nClone the repo:\n\n```bash\n$ git clone git@github.com:emberfox205/fruititionator.git\n```\n\nImport libaries (with pip):\n\n```bash\n$ pip install -r requirements.txt\n```\n\nGet your USDA FoodData Central API key [here](https://fdc.nal.usda.gov/api-key-signup.html).\n\nMake an Adafruit IO account [here](https://accounts.adafruit.com/users/sign_up) or log in [here](https://accounts.adafruit.com/users/sign_in).\n\nClick on the key icon on the top right corner of the IO tab to view your Adafruit IO (AIO) username and key.\n\n![Account Page \u003e IO tab \u003e Gold-Circle-with-Black-Key logo](https://cdn.discordapp.com/attachments/1071117548311027723/1236281850297585694/Adafruit_IO_key_scr.png?ex=663770b2\u0026is=66361f32\u0026hm=3f0853b7cca30d170020b3cd271bedf5251de2a85d230dbed278bf45caa0a2fe\u0026)\n\nIn your local repo, create a `.env` file:\n\n```\n$ code .env\n```\n\nStructure it like this:\n\n```.env\nAPI_KEY=your_usda_key\nAIO_USERNAME=your_aio_username\nAIO_KEY=your_aio_key\n```\n\nReplace `your_usda_key`, `your_aio_username`, and `your_aio_key` with your actual keys.\n\nTo track published data on your Adafruit account, create four feeds with the following names and specifications:\n\n1. Confidence Score: Feed History On\n2. Detected Object: Feed History On\n3. Captured Image: Feed History Off\n4. Nutrition Values: Feed History Off\n\nTo view them in a compact GUI, create a dashboard, then blocks of the same name as the feeds and connect them to their respective feed.\n\n\u003e [!NOTE] \n\u003e Some values are best displayed on specific block types:\n\u003e \n\u003e \"Captured Image\" -\u003e \"Image\" block.\n\u003e \n\u003e \"Nutrition Values\" -\u003e \"Multiline Text\" block.\n\n### Running the Project\n\nAfter installation, in your local repo, navigate to `mqtt_client.py` and run the project. Alternatively, execute in your terminal the following:\n\n```\n$ python mqtt_client.py\n```\n\n## Documentation\n\n### MQTT Client\n\n- The client acts as an interface between code files and the dashboard.\n- The file is run as normal without specific CLI commands.\n- It first detects with `detect_fruit()`. To conclude detection, press `esc` while the video feed is in focus (click on the video feed window to gain focus).\n- Nutritional values are fetched and published using the `api_call.py` module, while the image corresponding to the chosen detection result is published using the `image_processor.py` module.\n- The program then either prints the data or warns user if nothing is detected. User is prompted to input `e` to continue scanning or any other key to exit.\n- Upon exiting, the program prints number of successful scans (instances that a fruit is detected) and a list of detected fruits.\n\n### Image Detection\n\n- Relevant functions are in `fruit_detector.py`.\n- The `detect_fruit()` function takes 3 arguments to publish the data later. It opens the device's camera (if available and given permission) and also initiates a window showing the camera feed. The model looks for one out of the possible classes of objects, one of which being `Nothing` and the rest being types of fruits.\n- This function is also responsible for publishing to 2 Adafruit feeds: `Confidence Score` and `Detected Object`.\n\n\u003e [!NOTE]\n\u003e All the fruit classes' names can be found in `labels.txt`.\n\n- The function returns an instance of the `Detected_Object` class, which contains 3 attributes:\n  - `name` of type `str`.\n  - `score` of type `float`.\n  - `image` of type `ndarray`.\n\n### API call\n\n- All necessary functions are in `api_call.py`.\n- The script takes 3 arguments, one of which, `keyword` is then used to query USDA Central Food Database (specifically the Foundation Food and SR Legacy) using the `get_api()` function. It returns an instance of the `Fruit_Nutrition` dataclass, which contains 3 attributes:\n  - `name` of type `str`.\n  - `fdcId` of type `int`\n  - `nutrition` of type `dict`. Inside `nutrition`, a key-value pair consists of `nutrient_name` as key, an f-string `f\"{amount} {unit}\"` as value.\n\n\u003e [!NOTE]\n\u003e Info about `Detected_Object` and `Fruit_Nutrition` classes are in `custom_classes.py`.\n\n- In case the keyword is invalid, the function returns `None`.\n- `api_call.py` also handles the publishing of the nutrition to `Nutrition Values` feed on Adafruit IO.\n- Example of printing `Fruit_Nutrition` / the return value of `get_api()`:\n\n```bash\nStatus code: 200\nFruit Name: apple red delicious\nFdcId: 1750339\nNutrition: {\n    \"Magnesium, Mg\": \"4.7 MG\",\n    \"Phosphorus, P\": \"9.18 MG\",\n    \"Potassium, K\": \"95.3 MG\",\n    \"Zinc, Zn\": \"0.0196 MG\",\n    \"Copper, Cu\": \"0.0243 MG\",\n}\n```\n\n\u003e [!NOTE]\n\u003e Remember to have `.env` file in the same directory as `api_call.py`, and **DO NOT** share the API key.\n\n### Image modification and encoding\n\n- Relevant functions are in `image_processor.py`\n\n#### Functions\n\n`resize_image(image, target_size=100)`\n\n- This function takes a numpy array representing an image and a target size in kilobytes, and returns a PIL Image object that is resized such that the size of the encoded image is less than or equal to the target size.\n\n- The function converts the numpy array to a PIL Image object, and then enters a loop where it encodes the image, checks the size of the encoded image, and if the size is greater than the target size, resizes the image by a factor and repeats the process. The loop continues until the size of the encoded image is less than or equal to the target size.\n\n`encode_image(image_pil)`\n\n- This function takes a PIL Image object, encodes it in JPEG format, and then encodes the result in base64. It returns the base64-encoded image as a string.\n\n`image_publisher(client, IMAGE_FEED_ID, ndarray_image)`\n\n- This function takes a MQTT client, an image feed ID, and a numpy array representing an image. It calls resize_image to resize the image, encode_image to encode the resized image, and then publishes the encoded image to the MQTT feed specified by IMAGE_FEED_ID.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femberfox205%2Ffruititionator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femberfox205%2Ffruititionator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femberfox205%2Ffruititionator/lists"}