Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:13:46+00:00 2026-06-13T07:13:46+00:00

I would like to click on an object and get the pixel coordinates which

  • 0

I would like to click on an object and get the pixel coordinates which are the color that I picked before.
I found this code on the internet

import cv
tolerancia = 30
def evento_mouse(event,x,y,flags,param):
    if event==cv.CV_EVENT_LBUTTONDOWN:
        pixel=cv.Get2D(imagen,y,x) 
        print 'X =',x,'  Y =',y
        print 'R =',pixel[2],'G =',pixel[1],'B =',pixel[0]
        cv.InRangeS(imagen,(pixel[0]-tolerancia,pixel[1]-tolerancia,pixel[2]-                                               tolerancia),(pixel[0]+tolerancia,pixel[1]+tolerancia,pixel[2]+tolerancia),temporal)
        cv.ShowImage('Color',temporal)
        c = cv.Get2D(temporal,y,x) 
        print c[0],c[1],c[2] # I always get: 255, 0, 0
   imagen=cv.LoadImage('prueba2.png')
   cv.ShowImage('Prueba',imagen)
   temporal=cv.CreateImage(cv.GetSize(imagen),cv.IPL_DEPTH_8U,1)
   cv.SetMouseCallback('Prueba',evento_mouse)
   cv.WaitKey(0)

I am trying to see if the pixel is white or black. but I always get the same value: 255, 0, 0 (blue = 255)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:13:47+00:00Added an answer on June 13, 2026 at 7:13 am

    There are a couple of things you need to understand.

    You are using old ‘cv’ interface of OpenCV. In that case, to get a pixel value, you use the function ‘cv2.Get2D’ which returns you a tuple of corresponding BGR values.

    1. Why blue color, ie (255,0,0) for binary images ?

    For both color images and grayscale/binary images, same tuple of 3 elements is returned, but for grayscale images, first element is the pixel value, remaining two are irrelevant, so they are zeros. So you get values like (255,0,0) etc since you are reading pixel values of binary image(temporal).

    2. Why always (255,0,0) ?

    When you click on the original image, a corresponding binary image is created, where the region corresponding to color you clicked become white and all other region become black. If you clicked on a RED color in original image, your binary image will be such that, all red region will be white and remaining black. So obviously, the pixel you clicked is always WHITE. So if you read that pixel from binary image, you get only (255,0,0) always.

    I would like to recommend you to migrate to OpenCV new Python interface, ‘cv2’ module. It has a lot of advantages. Main advantage is the Numpy support which is a big deal. You can check this SOF for some comparison : What is different between all these OpenCV Python interfaces?

    You can also get some startup tutorials on cv2 from here : http://www.opencvpython.blogspot.com

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like links to be trigger on double click. Something simple like this:
I would like to have a tooltip that only comes up when you click
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have an image on my website. I would like when I click it,
I would like to allow the user to click within my UserControl and drag
I would like to be able to add a click event to a entity
I would like to allow a user to click on a JList and if
I would like to open a new aspx page when i click on a
I would like to create the same effect as on Pinterest when you click
$('#selector').click(function() { // here I would like to load a javascript file // let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.