Use of the getTickCount and getTickFrequency functions

This recipe explains what is the use of the getTickCount and getTickFrequency functions. The getTickCount function returns the count of clock signals and The getTickFrequency function returns the number of clock signals sent in a second.

Recipe Objective: What is the use of the getTickCount() and getTickFrequency() functions?

Let us understand how to calculate the performance of OpenCV using the cv2.getTickCount() and cv2.getTickFrequency() functions

Build a Chatbot in Python from Scratch!

Step 1: Import the library

import cv2

Step 2: Calculate the perform of OpenCV

The cv2.getTickCount() function returns us the count of clock signals that was sent from the reference event to the time cv2.getTickCount() function is called. The reference event may be anything such as the moment when the computer was turned on

The cv2.getTickFrequency() function returns the number of clock signals sent in a second, which can also be called as getTickFrequency

To calculate the time a block of code takes to execute, we can calculate the number of clock signals using cv2.getTickCount() at the beginning and the end of the block of code and divide its difference by the frequency, which can be obtained using the cv2.getTickFrequency() function.

In this example, let us try to perform some basic OpenCV manipulations such as converting the image to grayscale and drawing a rectangle and find the time taken for its execution.

c1 = cv2.getTickCount()
image1=cv2.imread('project.jpg')
image_converted = cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY)
cv2.rectangle(image1,(0,0),(image1.shape[1],image1.shape[0]),255,5)
c2 = cv2.getTickCount()
time_taken = (c2 - c1)/ cv2.getTickFrequency()

Now let see how much time has the above chunk of code taken to execute

print(f'The time taken for execution is {time_taken}')

Output:

    The time taken for execution is 0.0071479

Download Materials


What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

MLOps using Azure Devops to Deploy a Classification Model
In this MLOps Azure project, you will learn how to deploy a classification machine learning model to predict the customer's license status on Azure through scalable CI/CD ML pipelines.

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Build a Multimodal RAG System using AWS Bedrock and FAISS
In this LLM RAG Project, you will learn to build a Multimodal RAG system for a restaurant aggregator app, integrating text and visuals to deliver personalized food recommendations using advanced technologies like Amazon S3, Amazon Bedrock, and FAISS.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Build and Deploy an AI Resume Analyzer with OpenAI and Azure
In this AI Resume Analyzer project, you will learn to build and deploy AI resume analyzer that helps job seekers assess how effectively their resumes match job descriptions using OpenAI's language models and Azure's cloud infrastructure.

Multilabel Classification Project for Predicting Shipment Modes
Multilabel Classification Project to build a machine learning model that predicts the appropriate mode of transport for each shipment, using a transport dataset with 2000 unique products. The project explores and compares four different approaches to multilabel classification, including naive independent models, classifier chains, natively multilabel models, and multilabel to multiclass approaches.

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .

OSZAR »