{"id":87781,"date":"2023-07-10T12:22:32","date_gmt":"2023-07-10T06:52:32","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=87781"},"modified":"2026-06-03T15:12:34","modified_gmt":"2026-06-03T09:42:34","slug":"displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/","title":{"rendered":"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV"},"content":{"rendered":"<p>Displaying the coordinates of points clicked on an image is a common task in computer vision and image processing applications.<\/p>\n<p>In this project, we will explore how to use OpenCV, a popular computer vision library, to display the coordinates of points clicked on an image using Python. This technique can be useful for tasks such as annotating images, selecting regions of interest, and measuring distances between points. We will cover the steps needed to load an image, display it using OpenCV&#8217;s imshow() function, capture mouse clicks using setMouseCallback(), convert the click coordinates to image coordinates and display the clicked coordinates on the image using putText().<\/p>\n<p>By the end of this project, you will have a working Python program that can display the coordinates of points clicked on any image.<\/p>\n<h3>How do we get clicked Coordinates?<\/h3>\n<p>When we click on an image in OpenCV, we get the pixel coordinates of the click which may not accurately represent the actual location of the click on the original image. This is because the image may have been resized or cropped. To accurately determine the location of the click on the original image, we need to apply a scaling factor to the pixel coordinates. This factor is calculated by dividing the dimensions of the displayed image by the dimensions of the original image.<\/p>\n<h3>Prerequisites for Displaying the coordinates of the points clicked on the image using Python\u00a0 OpenCV<\/h3>\n<p>It is important to have a solid understanding of the Python programming language and the OpenCV library. Apart from this you should have the following system requirements.<\/p>\n<ul>\n<li>Python 3.7 (64-bit) and above<\/li>\n<li>Any python editor (VS code, Pycharm)<\/li>\n<\/ul>\n<h3>Download Python OpenCV Displaying the coordinates of the points clicked on the image Project<\/h3>\n<p>Please download the source code of Python OpenCV Displaying the coordinates of the points clicked on the image Project from the following link: <a href=\"https:\/\/drive.google.com\/file\/d\/1ftwxCM38apfoD9pWf0MFKMNqHZBeboE2\/view?usp=drive_link\"><strong>Python<\/strong> <strong>OpenCV Displaying the coordinates of the points clicked on the image Project Code<\/strong><\/a><\/p>\n<h3>Installation<\/h3>\n<p>Open windows cmd as administrator<\/p>\n<p>1. To install the opencv library run the command from the cmd.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install opencv-python\r\n<\/pre>\n<h3>Let\u2019s Implement<\/h3>\n<p>1. We need to import some libraries that will be used in our implementation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2\r\n<\/pre>\n<p>2. This code creates a function that captures mouse clicks on an image using OpenCV&#8217;s setMouseCallback() function. The function takes five inputs, including the type of mouse event, the x and y coordinates of the mouse click, and any relevant flags or parameters. If the mouse event is a left button down event, the function prints the x and y coordinates of the mouse click to the console in the format (x, y) using an f-string and also prints it over the image. This function can be used to capture mouse clicks on an image and display their coordinates on the image.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def point_capture(event, x, y, flags, params):\r\n    if event == cv2.EVENT_LBUTTONDOWN:\r\n        print(f\"Coordinate of Image: ({x}, {y})\")\r\n        cv2.putText(image, f'({x}, {y})', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)\r\n        cv2.imshow('TechVidvan', image)\r\n<\/pre>\n<p>3. This line of code reads an image file called &#8220;image.jpg&#8221; from the specified file path using the OpenCV function cv2.imread().<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">image = cv2.imread(\"C:\/Users\/yoges\/OneDrive\/Desktop\/dataflair\/Displaying_the_coordinates_of_the_points_clicked_on_the_image_using_Python_OpenCV\/image.jpg\")<\/pre>\n<p>4. This line of code displays the image stored in the variable &#8220;image&#8221; using OpenCV&#8217;s imshow() function. The first argument &#8220;TechVidvan&#8221; is the name of the window that will display the image. The second argument &#8220;image&#8221; is the image data that we want to display.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cv2.imshow(\"TechVidvan\", image)\r\n<\/pre>\n<p>5. This line of code sets a function to be called when a mouse event occurs on a window called &#8220;TechVidvan&#8221;. The function is called &#8220;point_capture&#8221; and will receive information about the event, such as the type of event, the x and y coordinates of the mouse cursor, and any flags associated with the event. In this example, the function prints the x and y coordinates to the console when a left mouse button is clicked.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cv2.setMouseCallback('TechVidvan', point_capture)\r\n<\/pre>\n<p>6. cv2.waitKey(0) waits for a key event to occur and returns the ASCII code of the key pressed. Passing 0 means it waits indefinitely until a key is pressed. cv2.destroyAllWindows() is called to close all OpenCV windows when a key is pressed or when the program is terminated. This function destroys all the HighGUI windows and removes all event callbacks<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cv2.waitKey(0)\r\ncv2.destroyAllWindows()\r\n<\/pre>\n<h3>Output:<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/07\/displaying-the-coordinates-of-the-points-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-88070 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/07\/displaying-the-coordinates-of-the-points-output.webp\" alt=\"displaying the coordinates of the points output\" width=\"1920\" height=\"1052\" \/><\/a><\/p>\n<p>[Running] python -u &#8220;c:\\Users\\yoges\\OneDrive\\Desktop\\dataflair\\Displaying_the_coordinates_of_the_points_clicked_on_the_image_using_Python_OpenCV\\Displaying the coordinates of the points clicked on the image using Python-OpenCV.py&#8221;<br \/>\nCoordinate of Image: (72, 73)<br \/>\nCoordinate of Image: (105, 228)<br \/>\nCoordinate of Image: (214, 141)<br \/>\nCoordinate of Image: (554, 39)<br \/>\nCoordinate of Image: (620, 160)<br \/>\nCoordinate of Image: (316, 320)<br \/>\nCoordinate of Image: (126, 332)<br \/>\nCoordinate of Image: (57, 313)<br \/>\nCoordinate of Image: (59, 411)<br \/>\nCoordinate of Image: (504, 416)<br \/>\nCoordinate of Image: (665, 289)<br \/>\nCoordinate of Image: (411, 63)<br \/>\nCoordinate of Image: (317, 52)<br \/>\nCoordinate of Image: (260, 47)<br \/>\nCoordinate of Image: (39, 153)<\/p>\n<h3>Conclusion:-<\/h3>\n<p>OpenCV provides a powerful set of tools for working with images in Python. By using the setMouseCallback() function, we can capture mouse clicks on images and use them for a variety of applications.<\/p>\n<p>In this project, we have shown how to display the coordinates of clicked points on an image using OpenCV in Python. We also discussed the importance of converting click coordinates from pixel values to image coordinate values to accurately reflect the location of clicks on the original image. This is a useful technique for a wide range of applications, including object detection, image segmentation, and computer vision research. With OpenCV, it is easy to capture mouse clicks on images and use them to build powerful image processing and analysis applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Displaying the coordinates of points clicked on an image is a common task in computer vision and image processing applications. In this project, we will explore how to use OpenCV, a popular computer vision&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":88069,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[193],"tags":[5040,191,395,5041,481,482],"class_list":["post-87781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv-tutorials","tag-display-the-coordinates-of-points","tag-opencv-project-for-practice","tag-opencv-projects","tag-python-opencv-display-the-coordinates-of-points-clicked-on-the-image","tag-python-opencv-project-ideas","tag-python-opencv-projects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Displaying the Coordinates of Points Clicked on the Image using Python OpenCV - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn how to extract and display precise coordinates of points clicked on an image using Python and OpenCV.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn how to extract and display precise coordinates of points clicked on an image using Python and OpenCV.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T06:52:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-03T09:42:34+00:00\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV - TechVidvan","description":"Learn how to extract and display precise coordinates of points clicked on an image using Python and OpenCV.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/","og_locale":"en_US","og_type":"article","og_title":"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV - TechVidvan","og_description":"Learn how to extract and display precise coordinates of points clicked on an image using Python and OpenCV.","og_url":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-07-10T06:52:32+00:00","article_modified_time":"2026-06-03T09:42:34+00:00","author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV","datePublished":"2023-07-10T06:52:32+00:00","dateModified":"2026-06-03T09:42:34+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/"},"wordCount":879,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#primaryimage"},"thumbnailUrl":"","keywords":["display the coordinates of points","opencv project for practice","opencv projects","python opencv display the coordinates of points clicked on the image","python opencv project ideas","python opencv projects"],"articleSection":["OpenCV Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/","url":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/","name":"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#primaryimage"},"thumbnailUrl":"","datePublished":"2023-07-10T06:52:32+00:00","dateModified":"2026-06-03T09:42:34+00:00","description":"Learn how to extract and display precise coordinates of points clicked on an image using Python and OpenCV.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/displaying-the-coordinates-of-points-clicked-on-the-image-using-python-opencv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Displaying the Coordinates of Points Clicked on the Image using Python OpenCV"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=87781"}],"version-history":[{"count":1,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87781\/revisions"}],"predecessor-version":[{"id":448048,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87781\/revisions\/448048"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=87781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=87781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=87781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}