Computer Vision Best Practice

This MLHub package provides command line tools based on Microsoft's open source Computer Vision Best Practice repository available from Individual command line tools are packaged for common computer vision tasks including image classification and object detection, based on a collection of pre-built computer vision models. These command line tools aim to be used as part of a Linux pipeline of image processing commands. The package also provides an interactive demonstration as an overview of the capabilities of the repository.

Giving computers some semblance of vision (and the implied ability to process the images and identify the content) has become practical with the massive compute and training data that is available today. A number of pre-built machine learning models are freely available for this task and through this package we make them available for command line scripts.

Visit the github repository for this package for more details:

Quick Start Command Line Examples

$ ml demo cvbp
$ ml classify cvbp
$ ml classify cvbp


$ pip3 install mlhub
$ ml install   cvbp
$ ml configure cvbp

Command Line Tools

In addition to the demo presented below, the cvbp package provides useful command line tools. Below we demonstrate a number of these. Most commands take an image as a parameter which may be a url or a path to a local file.


The classify command will identify the dominant object in a photo with a level of confidence. The confidence, class, and filename are printed and can be piped on to other commands within a command line. This can allow us to add the class as a tag to the meta data of an image file.

This first example image from the Internet is classified 100% as a koala.

$ ml classify cvbp

As an example of command line processing, we could download this photo (noting its license) and add the appropriate tag to it:

$ wget -O koala.jpg
$ exiftool koala.jpg | grep -i comment
$ ml classify cvbp koala.jpg |
  cut -d, -f2 |
  xargs bash -c 'mogrify -comment $0 koala.jpg' 
$ exiftool koala.jpg | grep -i comment
Comment                         : koala

Coffee mugs seem to be fairly standard fare for image classification:

$ ml classify cvbp

Different pre-built image classification models are available. Here we use a more complex model to provide a more confident classification of the coffee mug:

$ ml classify cvbp --model=resnet152

If no image is supplied on the command line then the computer's webcam will be used to source a live feed and any objects held up to the camera will be classified. The live classification is available within the displayed live video image.

$ ml classify cvbp

If there is more than one camera on the computer then the command may not select the best one. For example, you may have an infrared camera and a webcam on your computer. If the resulting window is all green, then the infrared camera has been chosen. To choose your webcam the use of the --webcam command line option may help:

$ ml classify cvbp --webcam=1

The --webcam command line option is also supported across other commands that use the webcam, including demo.

Multiple images can be classified with one command line:

$ ml classify cvbp images/*.png

We can add a tag to photos which are classified with a confidence greater than 75%. This might allow us to later on search for photos using the photo meta-data tag.

$ ml classify cvbp images/*.png | 
  awk '$1>0.75{print}' |
  cut -d, -f2,3 | 
  tr ',' ' ' | 
  xargs -d'\n' -n1 bash -c 'mogrify -comment $0 $1'


The detect command, in addition to identifying objects, returns the bounding box for the objects found in the image, consisting of the left top and right bottom coordinates.

$ ml detect images/*.{jpg,png}

As with classify, with no argument the webcam is deployed to obtain images and to detect objects in real time.


$ ml demo cvbp


This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.

Legal Notices

Microsoft and any contributors grant you a license to the Microsoft documentation and other content in this repository under the Creative Commons Attribution 4.0 International Public License, see the LICENSE file, and grant you a license to any code in the repository under the MIT License, see the LICENSE-CODE file.

Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at

Privacy information can be found at

Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, or trademarks, whether by implication, estoppel or otherwise.