{"id":20058669,"url":"https://github.com/roboflow/roboflow-computer-vision-utilities","last_synced_at":"2025-05-05T14:31:32.118Z","repository":{"id":59948656,"uuid":"538845777","full_name":"roboflow/roboflow-computer-vision-utilities","owner":"roboflow","description":"Interface with the Roboflow API and Python package for running inference (receiving predictions) and customizing result images from your Roboflow Train computer vision models.","archived":true,"fork":false,"pushed_at":"2024-05-13T13:34:13.000Z","size":5056,"stargazers_count":41,"open_issues_count":8,"forks_count":8,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-04T23:52:19.168Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roboflow.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":"2022-09-20T06:42:29.000Z","updated_at":"2025-03-04T17:45:08.000Z","dependencies_parsed_at":"2024-11-13T13:03:26.529Z","dependency_job_id":"aaf1bd21-b394-4eb3-9877-07e27f3317a5","html_url":"https://github.com/roboflow/roboflow-computer-vision-utilities","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboflow%2Froboflow-computer-vision-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboflow%2Froboflow-computer-vision-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboflow%2Froboflow-computer-vision-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboflow%2Froboflow-computer-vision-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roboflow","download_url":"https://codeload.github.com/roboflow/roboflow-computer-vision-utilities/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252514984,"owners_count":21760481,"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-13T13:03:09.887Z","updated_at":"2025-05-05T14:31:30.834Z","avatar_url":"https://github.com/roboflow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# roboflow-computer-vision-utilities\nInterface with the Roboflow API and Python SDK for running inference (receiving predictions) with AutoML and custom-trained models compatible with Roboflow Deploy.\n\n![Roboflow Logo](/figures/roboflow-cv-utilities-header.png)\n\n![Contact Us!](https://i.imgur.com/rBmXoQ1.png)\n#### [Website](https://docs.roboflow.com/python) • [Docs](https://docs.roboflow.com) • [Blog](https://blog.roboflow.com) • [Community Forum](https://discuss.roboflow.com) • [Twitter](https://twitter.com/roboflow) • [Linkedin](https://www.linkedin.com/company/roboflow-ai) • [Roboflow Universe](https://universe.roboflow.com) • [Knowledge Base](https://help.roboflow.com)\n\n## What is Roboflow?\n**Roboflow** makes managing, preprocessing, augmenting, and versioning datasets for computer vision seamless. This repo utilizes the official [Roboflow Python SDK](https://docs.roboflow.com/python) that interfaces with the [Roboflow Hosted API Inference Server](https://docs.roboflow.com/inference/hosted-api) and [REST API](https://docs.roboflow.com/rest-api).\n\nKey features of Roboflow:\n\n- Import and Export image datasets into any supported [formats](https://roboflow.com/formats)\n- [Preprocess](https://docs.roboflow.com/image-transformations/image-preprocessing)\n  and [augment](https://docs.roboflow.com/image-transformations/image-augmentation) data using Roboflow's dataset\n  management tools\n- Train computer vision models using [Roboflow Train](https://docs.roboflow.com/train) and deploy\n  to [production](https://docs.roboflow.com/inference)\n- Use [community curated projects](https://universe.roboflow.com/) to start building your own vision-powered products\n\n#### Available Plans \u0026 Features\nhttps://roboflow.com/pricing\n\nPersonal and Research Projects - Applying for Additional Account Features:\n* https://roboflow.com/community\n\nBusiness Projects and POC's - Requesting Additional Account Features:\n* https://roboflow.com/sales\n\n#### Popular Repositories and Learning Resources:\n\n• [Roboflow Python SDK](https://github.com/notebooks) • [Notebooks](https://github.com/notebooks) (Custom Model Training Tutorials) • [Learn Computer Vision](https://roboflow.com/learn) • [Supervision](https://universe.roboflow.com) • [Polygon Zone](https://universe.roboflow.com) •\n\n#### Installation (Dependencies):\nPython Version: `3.10\u003e=Python\u003e=3.7`.\nInstall from Source:\n```\ngit clone https://github.com/roboflow-ai/roboflow-computer-vision-utilities.git\ncd roboflow-computer-vision-utilities\npython3 -m venv env\nsource env/bin/activate \npip3 install -r requirements.txt\n```\n\n#### [Obtaining Your API Key](https://docs.roboflow.com/rest-api#obtaining-your-api-key) | [Workspace ID](https://docs.roboflow.com/roboflow-workspaces#workspace-id) | [Project ID](https://docs.roboflow.com/roboflow-workspaces/projects#project-id) | [Model Version Number](https://docs.roboflow.com/roboflow-workspaces/versions#version-number)\n\n## 🤖 📹 Inference Utilities:\n| **functionality** | **images** | **video** | **stream** |\n|:------------:|:-------------------------------------------------:|:---------------------------:|:---------------------------:|\n| Draw Boxes | [![GitHub](https://badges.aleen42.com/src/github.svg)](/images/draw_img.py)\u003cbr\u003e[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/13HeLzcMUII4fvEFyMyz4lQBje9R2dvM8?usp=sharing) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/video/draw_img.py) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/video/draw_vid.py) |\n| Write Text | [![GitHub](https://badges.aleen42.com/src/github.svg)](/images/writetext_img.py)\u003cbr\u003e[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](/images/roboflow_cv_utils_writetext_img.ipynb.ipynb) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/video/writetext_vid.py) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/stream/writetext_stream.py) |\n| Fill Boxes | [![GitHub](https://badges.aleen42.com/src/github.svg)](/images/fill_img.py)\u003cbr\u003e[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](/images/roboflow_cv_utils_fill_img.ipynb) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/video/fill_vid.py) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/stream/fill_stream.py) |\n| Crop Boxes | [![GitHub](https://badges.aleen42.com/src/github.svg)](/images/crop_img.py) | | |\n| Blur Boxes | [![GitHub](https://badges.aleen42.com/src/github.svg)](/images/blur_img.py) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/video/blur_video.py) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/stream/blur_stream.py) |\n| Two Stage Detection | \u003cp style=\"font-size: 5px\"\u003eObject Detection -\u003e\u003cbr\u003eCrop Bounding Box\u003c/br\u003e-\u003e Single-Label Classification\u003c/p\u003e [![GitHub](https://badges.aleen42.com/src/github.svg)](/images/twoPass.py) | | |\n| Object Counting | [![GitHub](https://badges.aleen42.com/src/github.svg)](/object_counting.py) \u003ca href=\"https://blog.roboflow.com/no-code-computer-vision-zapier/\" rel=\"\"\u003e\u003cimg src=\"https://media.roboflow.com/notebooks/template/icons/purple/roboflow-app.png?ik-sdk-version=javascript-1.4.3\u0026updatedAt=1672949746649\" width=15% alt=\"Roboflow Documentation (Object Counting)\" /\u003e\u003c/a\u003e | | |\n| Measure Object | [![GitHub](https://badges.aleen42.com/src/github.svg)](/measureObject.py) \u003ca href=\"https://blog.roboflow.com/computer-vision-measure-distance/\" rel=\"\"\u003e\u003cimg src=\"https://media.roboflow.com/notebooks/template/icons/purple/roboflow-app.png?ik-sdk-version=javascript-1.4.3\u0026updatedAt=1672949746649\" width=15% alt=\"Roboflow Blog (Measure Object)\" /\u003e\u003c/a\u003e | | |\n| Send Email | [![GitHub](https://badges.aleen42.com/src/github.svg)](/email/send_email.py) \u003ca href=\"https://blog.roboflow.com/object-detection-jetson-nano-python/\" rel=\"\"\u003e\u003cimg src=\"https://media.roboflow.com/notebooks/template/icons/purple/roboflow-app.png?ik-sdk-version=javascript-1.4.3\u0026updatedAt=1672949746649\" width=15% alt=\"Roboflow Blog (Send Email)\" /\u003e\u003c/a\u003e | | |\n| Send Text | [![GitHub](https://badges.aleen42.com/src/github.svg)](/text_message/send_text.py) \u003ca href=\"https://blog.roboflow.com/computer-vision-twilio-notifications/\" rel=\"\"\u003e\u003cimg src=\"https://media.roboflow.com/notebooks/template/icons/purple/roboflow-app.png?ik-sdk-version=javascript-1.4.3\u0026updatedAt=1672949746649\" width=15% alt=\"Roboflow Blog: Send Text\" /\u003e\u003c/a\u003e | | |\n\n#### Video Inference (Classification)\n* Model predictions for Classification models running via hosted or local deployment supported by Roboflow Deploy.\n\n[![GitHub](https://badges.aleen42.com/src/github.svg)](/video_classification.py)\n\n#### Webcam Inference (Classification)\n* Model predictions for Classification models running via hosted or local deployment supported by Roboflow Deploy.\n\n[![GitHub](https://badges.aleen42.com/src/github.svg)](/webcam_classification.py)\n\n#### Sample Video Frames\n* Extract and save video frames by a specified frames per second of video.\n\n[![GitHub](https://badges.aleen42.com/src/github.svg)](/save_vidframes.py)\n\n## 💻 🛜 API Utilities:\n#### Upload Images to a Specified Dataset Split (Train/Valid/Test)\n\n[![GitHub](https://badges.aleen42.com/src/github.svg)](/api/uploadby_split.py)\n* Upload images from a directory (folder) to a specified dataset split [(train, valid, or test set)](https://blog.roboflow.com/train-test-split/) in your Roboflow project.\n* Base functionality also includes the ability to set a specific percentage of images to upload to the dataset from the specified directory, and the option to name the uploaded [dataset batch](https://docs.roboflow.com/annotate/collaborative-workflow)\n\nMore on the Roboflow REST API: https://docs.roboflow.com/rest-api/\n\n\n## 🔁 📈 Active Learning Utilities:\nAutomate improvement of your dataset by using computer vision and conditional upload logic to determine which images should be directly uploaded to your Roboflow workspace.\n* [Active Learning](https://roboflow.com/python/active-learning) (Roboflow Documentation)\n* [Active Learning with the Roboflow Python SDK](https://blog.roboflow.com/pip-install-roboflow)\n* [Strategies for Active Learning Implementation](https://blog.roboflow.com/computer-vision-active-learning-tips/)\n* [Active Learning](https://help.roboflow.com/implementing-active-learning) (Knowledge Base guide)\n\n| **model type** | **images** | **video** |\n|:------------:|:-------------------------------------------------:|:---------------------------:|\n| Object Detection | [![GitHub](https://badges.aleen42.com/src/github.svg)](/active_learning/images.py) | [![GitHub](https://badges.aleen42.com/src/github.svg)](/active_learning/video.py) |\n\nConditionals - Source Code:\n\n* `roboflow-python/roboflow/util/active_learning_utils.py`: [![GitHub](https://badges.aleen42.com/src/github.svg)](https://github.com/roboflow/roboflow-python/blob/main/roboflow/util/active_learning_utils.py)\n* `roboflow-python/roboflow/core/workspace.py` Line 245: [![GitHub](https://badges.aleen42.com/src/github.svg)](https://github.com/roboflow/roboflow-python/blob/02b717f453e95c5cdef8a817914a46f5fd6771a8/roboflow/core/workspace.py#L245)\n```\n# set the conditionals values as necessary for your active learning needs\n# NOTE - not all conditional fields are required\nconditionals = {\n    \"required_objects_count\" : 1,\n    \"required_class_count\": 1,\n    \"target_classes\": [\"class_name\"],\n    \"minimum_size_requirement\" : float('-inf'),\n    \"maximum_size_requirement\" : float('inf'),\n    \"confidence_interval\" : [10,90],\n    \"similarity_confidence_threshold\": .3,\n    \"similarity_timeout_limit\": 3\n}\n```\n* Note: [Filtering out images for upload by similarity](https://blog.roboflow.com/roboflow-inference-server-clip/) is available for paid plans. Please [contact the Roboflow team](https://roboflow.com/sales) for access.\n\n![The Roboflow API JSON Response Object Format](/figures/ResponseObjectFormat_JSON.png)\n\n![Visualized Roboflow API JSON Response Object Format](/figures/Visualized_ResponseObjectFormat_JSON.png)\n\n`twoPass.py`: Code for running inference (model predictions) in \"two stages\" on images.\n```\n# default root save location: './inference_images'\n# also moves all images in /roboflow-computer-vision-utilities to /roboflow-computer-vision-utilities/inference_images before inferrence\ncd images\npython3 twoPass.py\n```\n  * Ex. Stage 1: object detection (find faces) --\u003e crop the detected areas and send to --\u003e Stage 2: classification (is this a real image or illustrated?)\n  * To be used after updating the `roboflow_config.json` file in the main directory with your Model Info (Workpsace ID, Model/Project ID, Private API Key and Model Version Number)\n  * Available in `roboflow-computer-vision-utilities/images`\n\n`trigger_power_automate.py`: make predictions on images, save the results, and send an email to the email specified in `roboflow_config.json`\n```\n# default confidence and overlap for predictions: confidence = 40, overlap = 30\ncd images\npython3 trigger_power_automate.py\n```\n  * To be used after updating the `roboflow_config.json` file in the main directory with your Model Info (Workpsace ID, Model/Project ID, Private API Key and Model Version Number), and email address to send the inference results to.\n\n## Streamlit App for Testing Roboflow Object Detection Models\n\nThis app allows you to upload an image to be inferenced by an Object Detection model trained with [Roboflow Train](https://docs.roboflow.com/train)\n* [Inference: Hosted API](https://docs.roboflow.com/inference/hosted-api)\n* [Response Object Format](https://docs.roboflow.com/inference/hosted-api#response-object-format)\n* [Roboflow Python Package](https://docs.roboflow.com/python)\n\nThe app example app can be [found here](https://mo-traor3-ai-streamlit-roboflow-model-test-streamlit-app-j8lako.streamlitapp.com/):\n* https://mo-traor3-ai-streamlit-roboflow-model-test-streamlit-app-j8lako.streamlitapp.com/\n* The code for the app is available in the `streamlit` directory of this repo, in the `streamlit_app.py` file\n* The original repo is hosted here: https://github.com/mo-traor3-ai/streamlit-roboflow-model-testing\n* [Creating a Basic Streamlit App for Roboflow Inference](https://blog.roboflow.com/how-to-use-roboflow-and-streamlit-to-visualize-object-detection-output/) | [Roboflow Live Video Inference: Streamlit Tutorial](https://www.youtube.com/watch?v=w4fgZg-jb28)\n\nThe app will work as-is for inference on individual image files (png, jpeg, jpg formats). If you want to build your own model, you'll need your own API key. [Create a Roboflow account](https://app.roboflow.com) to get your own API key.\n\nThe app was created using [Roboflow](https://roboflow.com) and [Streamlit](https://streamlit.io/).\n\n## Example Code Snippets\n#### Receive model predictions from a single image file:\n```\nimg_path = 'INSERT_PATH_TO_IMG' # .jpg, .jpeg, .png\nimg = cv2.imread(img_path)\n\n# perform inference on the selected image\npredictions = model.predict(img_path, confidence=40,\n    overlap=30)\n```\n#### Receive model predictions from images contained in a folder (directory):\n```\nraw_data_location = \"INSERT_PATH_TO_DIRECTORY\"\n\nfor raw_data_extension in ['.jpg', '.jpeg', 'png']:\n## using the following line for raw_data_externsion results in inference on\n## specified file types only\n  raw_data_extension = \".jpg\" # e.g jpg, jpeg, png\n  globbed_files = glob.glob(raw_data_location + '/*' + raw_data_extension)\n  for img_path in globbed_files:\n      img = cv2.imread(img_path)\n      predictions = model.predict(img_path, confidence=40, overlap=30)\n```\n#### Drawing Bounding Boxes\n```\n# main bounding box coordinates from JSON response object\n# https://docs.roboflow.com/inference/hosted-api#response-object-format\nx0 = bounding_box['x'] - bounding_box['width'] / 2\nx1 = bounding_box['x'] + bounding_box['width'] / 2\ny0 = bounding_box['y'] - bounding_box['height'] / 2\ny1 = bounding_box['y'] + bounding_box['height'] / 2\n\n# position coordinates: start = (x0, y0), end = (x1, y1)\n# color = RGB-value for bounding box color, (0,0,0) is \"black\"\n# thickness = stroke width/thickness of bounding box\n# draw and place bounding boxes\nstart_point = (int(x0), int(y0))\nend_point = (int(x1), int(y1))\n\ncv2.rectangle(img, start_point, end_point, color=(0,0,0), thickness=2)\n```\n#### Writing and Placing Text:\n```\n# write and place text\ncv2.putText(\n    img, # PIL.Image object to place text on\n    'placeholder text',#text to place on image\n    (12, 12),#location of text in pixels\n    fontFace = cv2.FONT_HERSHEY_SIMPLEX, #text font\n    fontScale = 0.6,#font scale\n    color = (255, 255, 255),#text color in RGB\n    thickness=2#thickness/\"weight\" of text\n    )\n```\n#### Drawing \"Filled\" Bounding Boxes:\n```\n# main bounding box coordinates from JSON response object\n# https://docs.roboflow.com/inference/hosted-api#response-object-format\nx0 = bounding_box['x'] - bounding_box['width'] / 2\nx1 = bounding_box['x'] + bounding_box['width'] / 2\ny0 = bounding_box['y'] - bounding_box['height'] / 2\ny1 = bounding_box['y'] + bounding_box['height'] / 2\n\n# position coordinates: start = (x0, y0), end = (x1, y1)\n# color = RGB-value for bounding box color, (0,0,0) is \"black\"\n# thickness = stroke width/thickness of bounding box\n# draw and place bounding boxes\nstart_point = (int(x0), int(y0))\nend_point = (int(x1), int(y1))\n\n# setting thickness to -1 --\u003e filled bounding box with the specified color\ncv2.rectangle(img, start_point, end_point, color=(0,0,0), thickness=-1)\n```\n#### Blurring the Contents of Bounding Boxes:\n```\n# rip bounding box coordinates from current detection\n# note: infer returns center points of box as (x,y) and width, height\n# ----- but pillow crop requires the top left and bottom right points to crop\nx0 = prediction['x'] - prediction['width'] / 2\nx1 = prediction['x'] + prediction['width'] / 2\ny0 = prediction['y'] - prediction['height'] / 2\ny1 = prediction['y'] + prediction['height'] / 2\nbox = [(x0, y0), (x1, y1)]\nblur_x = int(prediction['x'] - prediction['width'] / 2)\nblur_y = int(prediction['y'] - prediction['height'] / 2)\nblur_width = int(prediction['width'])\nblur_height = int(prediction['height'])\n\n# region of interest (ROI), or area to blur\nroi = img[blur_y:blur_y+blur_height, blur_x:blur_x+blur_width]\n\n# ADD BLURRED BBOXES\n# set blur to (31,31) or (51,51) based on amount of blur desired\nblur_image = cv2.GaussianBlur(roi,(51,51),0)\nimg[blur_y:blur_y+blur_height, blur_x:blur_x+blur_width] = blur_image\n```\n#### Cropping the Contents of Bounding Boxes:\n```\nfor bounding_box in predictions:\n  # defining crop area [height_of_cropArea:width_of_cropArea]\n  # croppedArea = img[start_row:end_row, start_col:end_col]\n  x0 = bounding_box['x'] - bounding_box['width'] / 2#start_column\n  x1 = bounding_box['x'] + bounding_box['width'] / 2#end_column\n  y0 = bounding_box['y'] - bounding_box['height'] / 2#start row\n  y1 = bounding_box['y'] + bounding_box['height'] / 2#end_row\n  class_name = bounding_box['class']\n  croppedArea = img[int(y0):int(y1), int(x0):int(x1)]\n\n  # position coordinates: start = (x0, y0), end = (x1, y1)\n  # color = RGB-value for bounding box color, (0,0,0) is \"black\"\n  # thickness = stroke width/thickness of the box, -1 = fill box\n  cv2.rectangle(croppedArea,\n    (int(10), int(10)), (int(80), int(40)), color=(0,0,0),\n    thickness=-1)\n\n  # write class name on image, and print class name\n  cv2.putText(\n      croppedArea, # cv2 image object to place text on\n      class_name,# text to place on image\n      (20, 20),# location of text in pixels\n      fontFace = cv2.FONT_HERSHEY_SIMPLEX,# text font\n      fontScale = 0.4,# font scale\n      color = (255, 255, 255),#text color in RGB\n      thickness=2# thickness/\"weight\" of text\n      )\n\n  # SAVE CROPPED IMAGES\n  cv2.imwrite(f'crop{i}_' + os.path.basename(img_path), croppedArea)\n  i+=1\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froboflow%2Froboflow-computer-vision-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froboflow%2Froboflow-computer-vision-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froboflow%2Froboflow-computer-vision-utilities/lists"}