Skip to main content

Object counter using opencv2 and frame differencing

Project description

OpenCV2 Object Counter

Count objects using opencv2 in this configurable CLI utility. The module uses frame differencing to detect and count objects according to a flexible configuration scheme. This makes it a quick-and-dirty solution that can achieve good accuracy in a variety of cases and doesn't involve the computaional overhead nor complexity of convolutional neural netowrks (CNN).

Alternatively, the package can be imported to your own scripts.

Gates

Gates are the instrument used for counting. They are boxes which detect objects passing through them. A cooldown is triggered when it detects an object to avoid counting the same object many times. The right cooldown duration will depend on the counting situation. An object is counted if the gate is not on cooldown and the center point of the object and the gate is within the given distance.

Configuration

Here is an annotated example config. A default config is provided in ooc/config.json. Running ooc in cli mode requires a config. More details on some of the parameters can be found on https://docs.opencv.org/.

Note: The comments provided in this snippet are for informational purposes only and render this invalid JSON.

{
    // list of gates that will be used for counting
    "gates": [
        {
            // Starting x and y position (0,0 is top left)
            // and gate dimnensions
            "x": 350,
            "y": 320,
            "width": 100,
            "height": 100
        }
    ],
    "blur" : {
        // openCV2 kernal size
        // must be positive or odd, or 0 (in which case 
        // they are computed from sigma)
        "ksize": {
            "width": 21,
            "height": 21
        },
        // openCV2 kernal standard deviation
        "sigma_x": 0
    },
    // whether or not the video shows. press 'q' to quit
    "show": true,
    // whether or not additional video shows/logs print
    "debug": false
}

Command Line Arguments

-s, --source

  • required
  • Path to the video to analyze.
  • Usage: ooc -s /path/to/video.mp4

-t, --show

  • Displays the video if set.

-d, --debug

  • Runs in debug mode, which includes visual on the video (if -s is set) and prints logs.

-c, --config

  • Path to config file. If not set, the default config is used.
  • Usage: ooc -s /path/to/video.mp4 -c /path/to/config.json

Example Run

python ooc/cli.py -s /path/to/video.mp4 -c /path/to/config.json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencv-object-counter-0.1.12.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file opencv-object-counter-0.1.12.tar.gz.

File metadata

  • Download URL: opencv-object-counter-0.1.12.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for opencv-object-counter-0.1.12.tar.gz
Algorithm Hash digest
SHA256 918c8280c55be76dd028188565297ccf03a7551358ea74c98a9e583a15a291d4
MD5 7d5fb8b5e7dfb19947f1a027e2913563
BLAKE2b-256 ee622ff61fb5c18958e3ac784fedb13de4b06697478925b2ce0f2b035d1b85ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page