OpenCV Python Tutorial For Beginners 8 – Handle Mouse Events in OpenCV

///OpenCV Python Tutorial For Beginners 8 – Handle Mouse Events in OpenCV

OpenCV Python Tutorial For Beginners 8 – Handle Mouse Events in OpenCV

FavoriteLoadingAdd to favorites

In this video on OpenCV Python Tutorial For Beginners, I am going to show How to Handle Mouse Events in OpenCV Python. OpenCV supports for detecting of mouse events. These Mouse events include mouse clicks (like left-button down, left-button up, left-button double-click etc) and movements over an attached OpenCV window. Capturing mouse click events with Python and OpenCV is easy. we just need to create a callback function and call this callback function using cv2.setMouseCallback(‘image’, click_event_callback_function) method

Gist of code I used in this video (How to Detect Mouse Clicks and Moves) –

OpenCV is an image processing library created by Intel and later supported by Willow Garage and now maintained by Itseez. opencv is available on Mac, Windows, Linux. Works in C, C++, and Python.
it is Open Source and free. opencv is easy to use and install.

Starting with an overview of what the course will be covering, we move on to discussing morphological operations and practically learn how they work on images. We will then learn contrast enhancement using equalization and contrast limiting. Finally we will learn 3 methods to subtract the background from the video and implement them using OpenCV.

At the end of this course, you will have a firm grasp of Computer Vision techniques using OpenCV libraries. This course will be your gateway to the world of data science.

Feel the real power of Python and programming! The course offers you a unique approach of learning how to code by solving real world problems.

#ProgrammingKnowledge #ComputerVision #OpenCV
My Website –
My Blog –
My Facebook Page –
Google+ –
Twitter –
Pinterest –
Text Case Converter –
——————Facebook Links —————————————-


By |2020-02-25T01:58:04+00:00February 25th, 2020|Python Video Tutorials|14 Comments


  1. M1122 February 25, 2020 at 1:58 am - Reply

    hello,sir: i am wondering that why you get the three color channels by: blue=[y,x,0] ,but not blue=[x,y,0] (i had tried,but it said "the index is out of bounds",why is that? i thought [x,y,0] make more sense.)

  2. Shashank Sharmadon February 25, 2020 at 1:58 am - Reply

    thanks bro……..

  3. vicki rock February 25, 2020 at 1:58 am - Reply

    import cv2

    events=[i for i in dir(cv2) if 'EVENT' in i]


    def click_event(event,x,y,flags,param):

    if event==cv2.EVENT_LBUTTONDOWN:






    if event==cv2.EVENT_RBUTTONDOWN:














    SystemError: <built-in function putText> returned NULL without setting an error

    I'm getting this error when i run the above code
    Please do help

  4. Joel Rivera February 25, 2020 at 1:58 am - Reply

    File "c:/Users/Joel Rivera/Documents/2019-2/Python/", line 26, in <module>


    AttributeError: module 'cv2.cv2' has no attribute 'setMouseCallBack'

  5. deepak singh February 25, 2020 at 1:58 am - Reply

    I always thought OpenCV to be very complex in understanding until I saw your videos.
    These are explained in just a perfect way.
    Please keep adding more and more ..

    Also waiting for an advanced playlist , which could cover the advanced topics in CV..

  6. Mamun rahaman February 25, 2020 at 1:58 am - Reply

    I dont get any coordinate on my image . Why? my code is same

  7. Zunair Talish February 25, 2020 at 1:58 am - Reply

    Why Did u Don't Pass Values in Function's Parameters

  8. Андреич February 25, 2020 at 1:58 am - Reply

    The whole tutorial is the most useful. One question to Mouse Event handling: is it possible to program a reverse thing: when an object is detected to generate a MousClick event and send it to another application so that that other application processed it is a normal MouseClick?

  9. Avinash Akotkar February 25, 2020 at 1:58 am - Reply

    Thanks for sharing this video. I have one concern, suppose I want to click on "File" using a program then how programme will find "File" location on desktop and get its coordinate and move the mouse to that coordinate

  10. Zephyr McIntyre February 25, 2020 at 1:58 am - Reply

    Thank you for recording these video, it's been very helpful. I have a question about the X,Y coordinates and how the function knows that the x,y variables are associated with the location of the mouse event?

  11. Tanmay S February 25, 2020 at 1:58 am - Reply

    Why it shows white color after I attach my mouse. Previously it shows correct color.

  12. Christopher Westcott February 25, 2020 at 1:58 am - Reply

    When I enter:events = (i for i in dir(cv2) if 'EVENT' in i)
    print(events)I get the following:<generator object <genexpr> at 0x08E6D2F0>Process finished with exit code 0Do you have a moment to tell me what am I missing?

  13. Tech Learn February 25, 2020 at 1:58 am - Reply

    Awesome sir thank you so much for opencv tutorial

  14. Sidhant Mourya February 25, 2020 at 1:58 am - Reply

    Do I need to know Python or can I start directly open CV tutorial ?

Leave A Comment