Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I want to ask a question: I'm using OpenCV 2.4 and I have to check the value (time by time) of a pixel addressed (X,Y) in a binary thresholded OpenCV Mat image.

I have to check if the pixel at the X,Y that I want to verify (and pass to a fuction) if is black or white (0 or 255)...what is the best method to do this thing?

I have searched and read about direct method (Get2D) or with pointers..but it isn't so clear for me...Image are binary, thresholded and eroded/dilated before...then, 1 channel not 3 channels..

can someone post me an example code of fuction that I've to use to do this thing?

Please, help me.
Posted

It is always easier if you post your own code. This is straight out of the documentation:

C++
cv::Mat img = cv::imread("lenna.png", 0);

if(img.at<uchar>(y,x) == 255)
etc


http://docs.opencv.org/doc/user_guide/ug_mat.html[^]
 
Share this answer
 
v3
Comments
Domus1919 5-Dec-13 2:12am    
I'm sorry but this solution works with grey image (or color)...I have a binary thresholded image...how can I access pixel value (white or black)?
direct memory access is lightning faster than calling some API. If you dont believe it write some test code.

I use for image manipulation and pixel access always cached off-screen bitmaps which I blitted into memory.
 
Share this answer
 
Comments
Domus1919 27-Nov-13 11:26am    
can you explain me a part of code? for Mat image?
KarstenK 28-Nov-13 4:47am    
The normal way is the "Solution "", but if you have performance problems you can use that way.

At first you need to draw your OpenCV picture on screen or a memory dc. Than you the GetDiBits API to get the pixel in binary format.

Here is a more complexexample which does that:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183402(v=vs.85).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900