Skip to content

count_region.py

Matha Goram edited this page Nov 11, 2024 · 3 revisions

NAME

count_regions.py - run a YOLO11 example in the spirit of the classic Hello World example

SYNOPSIS

python count_regions.py

DESCRIPTION

This Python script performs the following steps:

  • Imports the Ultralytics YOLO package
  • Defines the pretrained model for object inference
  • Specifies the input data for object inference
  • Returns the results after processing by YOLO11

ENVIRONMENT

A list of all environment variables that affect the program or function and how they affect it.

FILES

A list of the files the program or function uses, such as configuration files, startup files, and files the program directly operates on.

STANDARDS

A description of any standards or conventions that relate to the function or command. Commonly just a list of standards.

HISTORY

Adapted from the Ultralytics website.

NOTES

User Interactions

  • Mouse left-click will draw points between successive selections
  • Mouse right-click will delete all drawn points

VideoWriter_fourcc

A FourCC code is a 4-byte code used to specify the video codec. It's a crucial parameter when initializing a VideoWriter object in OpenCV.

Purpose
  • Codec Selection: The FourCC code determines the codec used to compress and encode the video frames.
  • Compatibility: Different codecs have varying levels of compression, quality, and compatibility with different video players and devices.

Syntax

C++

VideoWriter_fourcc(char c1, char c2, char c3, char c4)

Parameters

c1, c2, c3, c4: The four characters that form the FourCC code

Example Usage

C++
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
    // Create a VideoWriter object with MJPEG codec
    VideoWriter video("output.avi", VideoWriter::fourcc('M', 'J', 'P', 'G'), 30, Size(640, 480));
    // ... (rest of your code)
}

Common FourCC Codes

  • MJPG: Motion JPEG, a lossy codec that is widely supported
  • XVID: MPEG-4 codec, offering good compression and quality
  • DIVX: Another MPEG-4 codec, known for its high compression ratio
  • H264: A high-efficiency video coding standard, offering excellent compression and quality
  • FFMPEG: A versatile codec that supports a wide range of formats
Choosing the Right Codec:

The best codec for your application depends on several factors, including:

  • Desired Video Quality: Higher quality often requires larger file sizes.
  • Required Compression Ratio: A higher compression ratio results in smaller file sizes but may impact quality
  • Compatibility: Ensure the chosen codec is supported by your target devices and platforms
  • Real-time Requirements: Some codecs are more computationally intensive than others

2D Distance Calculation

Since the bounding boxes are limited to 2D space, this method cannot calculate the accurate distance between the detected objects owing to the absence of data in the third dimension real-world space.

CAVEATS

n/a

BUGS

n/a

EXAMPLES

$ python count_region.py

AUTHORS

armw

SEE ALSO

Model Prediction with Ultralytics YOLO

OPTIONS

A description of the command-line options accepted by a program and how they change its behavior.

EXIT STATUS

This script uses a recorded video file. If a real-time video source is used then minor modifications to the script will be necessary to permit a graceful exit from processing.

LIBRARY

  • Python package:
  • Ultralytics - solutions
  • Python interpreter - 3.11 or later

ERRORS

The scrpt will not proceed to the calculation of the distance if the input video source file is inaccessible.

VERSIONS

There are no explicit versions of this script. The repository contains trackable commits, pushes and merges.