Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error showing values from an image in pixels with mouse callback

Hello, I want to check pixel values with this program, however the results are not convincing at all for me. I am loading an image in grayscale and the colors are of course very different as it can be seen in the image

image description

However when I pass the mouse (with the implemented mouse callback function) I receive white colors with values of 90 for example, or black colors with values of 130.

include <iostream>

include <stdio.h>

include <opencv2 opencv.hpp="">

include <highgui.h>

using namespace cv; using namespace std;

Mat image; char window_name[20]="Get coordinates";

static void onMouse( int event, int x, int y, int f, void* ){ image = imread("/home/diego/Humanoids/imageGreen0.png"); int intensity = (int)image.at<uchar>(Point(x,y));

cout << "x: "<< x << " y: " << y << " value: " << intensity << endl;

}

int main() { namedWindow( window_name, CV_WINDOW_NORMAL ); image = imread("/home/diego/Humanoids/imageGreen0.png"); imshow( window_name, image ); setMouseCallback( window_name, onMouse, 0 ); waitKey(0); return 0; }

I want to learn how to use this because I want to get rid of the bottle shadow (by the way, here I put the green value of each pixel from an RGB image into the correspondent pixel in a grayscale image --> It's a green bottle) and I thought that maybe there can be a difference between the values of the bottle and the reflection from the sun which can allow me to make a threshold.

Can anyone help me telling me what is the error here? I am trying to stop being a newbie in OpenCV and C++, but I think that there is still a long way for it. Thank you

click to hide/show revision 2
No.2 Revision

updated 2015-05-30 02:15:48 -0600

berak gravatar image

Error showing values from an image in pixels with mouse callback

Hello, I want to check pixel values with this program, however the results are not convincing at all for me. I am loading an image in grayscale and the colors are of course very different as it can be seen in the image

image description

However when I pass the mouse (with the implemented mouse callback function) I receive white colors with values of 90 for example, or black colors with values of 130.

include <iostream>

include <stdio.h>

include <opencv2 opencv.hpp="">

include <highgui.h>

#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <highgui.h>

using namespace cv;
using namespace std;

std; Mat image; char window_name[20]="Get coordinates";

coordinates"; static void onMouse( int event, int x, int y, int f, void* ){ image = imread("/home/diego/Humanoids/imageGreen0.png"); int intensity = (int)image.at<uchar>(Point(x,y));

(int)image.at<uchar>(Point(x,y));

    cout << "x: "<< x << " y: " << y << " value: " << intensity << endl;

}

} int main() { namedWindow( window_name, CV_WINDOW_NORMAL ); image = imread("/home/diego/Humanoids/imageGreen0.png"); imshow( window_name, image ); setMouseCallback( window_name, onMouse, 0 ); waitKey(0); return 0; }

}

I want to learn how to use this because I want to get rid of the bottle shadow (by the way, here I put the green value of each pixel from an RGB image into the correspondent pixel in a grayscale image --> It's a green bottle) and I thought that maybe there can be a difference between the values of the bottle and the reflection from the sun which can allow me to make a threshold.

Can anyone help me telling me what is the error here? I am trying to stop being a newbie in OpenCV and C++, but I think that there is still a long way for it. Thank you

Error showing values from an image in pixels with mouse callback

Hello, I want to check pixel values with this program, however the results are not convincing at all for me. I am loading an image in grayscale and the colors are of course very different as it can be seen in the image

image description

However when I pass the mouse (with the implemented mouse callback function) I receive white colors with values of 90 for example, or black colors with values of 130.

/*Updated algorithm. Now it doesn't show the values. the window disspaears like with an exception when the mouse is passed through the image"

#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <highgui.h>

using namespace cv;
using namespace std;

Mat image;
image, imageGreen;
char window_name[20]="Get coordinates";

static void onMouse( int event, int x, int y, int f, void* ){
    image = imread("/home/diego/Humanoids/imageGreen0.png");
    int )
{       
    uchar intensity = (int)image.at<uchar>(Point(x,y));

    imageGreen.at<uchar>(x,y);
cout << "x: "<< x << " y: " << y << endl << " value: " << intensity (int)intensity << endl;
}

int main() {
    namedWindow( window_name, CV_WINDOW_NORMAL );
    image = imread("/home/diego/Humanoids/imageGreen0.png");
    Mat imageGreen = Mat::zeros(image.size(), CV_8UC1);
    Vec3b result;

    for (int i = 0; i < image.rows ; i++)
{
    for (int j = 0; j < image.cols ; j++)
    {
        result = image.at<cv::Vec3b>(i,j);
        int value = result[1];
        imageGreen.at<uchar>(i, j) = value;
    }
}

    cout<< "Image depth: "<<imageGreen.depth()<<" # of channels: "<<imageGreen.channels()<<"\n";
    imshow( window_name, image imageGreen );
    setMouseCallback( window_name, onMouse, 0 );
    waitKey(0);
    return 0;
}

I want to learn how to use this because I want to get rid of the bottle shadow (by the way, here I put the green value of each pixel from an RGB image into the correspondent pixel in a grayscale image --> It's a green bottle) and I thought that maybe there can be a difference between the values of the bottle and the reflection from the sun which can allow me to make a threshold.

Can anyone help me telling me what is the error here? I am trying to stop being a newbie in OpenCV and C++, but I think that there is still a long way for it. Thank you

I changed the algorithm and now I'm using another image

image description