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

Predictive Analytics Project for Working Capital Optimization
In this Predictive Analytics Project, you will build a model to accurately forecast the timing of customer and supplier payments for optimizing working capital.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

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

Credit Card Default Prediction using Machine learning techniques
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Loan Eligibility Prediction Project using Machine learning on GCP
Loan Eligibility Prediction Project - Use SQL and Python to build a predictive model on GCP to determine whether an application requesting loan is eligible or not.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.

Create Your First Chatbot with RASA NLU Model and Python
Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.