Mouse Events OpenCV Python

divshekhar profile image Divyanshu Shekhar ・1 min read

Mouse Events OpenCV Algorithm

Import Packages

 import numpy as np 

NumPy for manipulation in Color matrix.

import cv2 as cv

Computer Vision for reading and showing images and image manipulation.

from matplotlib import pyplot as plt

Matplotlib for data visualization. (Optional)

Read and Show Image for Mouse Events OpenCV

img = cv.imread(‘./img/sea.jpg’)

cv.imread() function is an OpenCV function in Python that makes it easy for the computer to read images. It takes one argument i.e the image source in the form of Absolute or Relative Path.

cv.imshow(‘image’, img)

Set Mouse Callback in OpenCV

Next Step is to setMouseCallback() function. It takes two parameters:

The Window name on which the image is being shown
A Callback function that will process the image and will return output on some mouse events.

cv.setMouseCallback(‘image’, click_event)

Read the whole post Mouse Events OpenCV python from the original Post.

Posted on by:


Editor guide