1 | initial version |
Your program is false. You don't have intensityin your file except for black and white image (luminance). You can have (generally) a color R,G,B or R,G,B alpha for png file.... You must check depth of your image and type before give pixel value....
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*){
if (image.channels()==3)
{
Vec3b v= image.at<Vec3b>(y,x);
cout << "x: " << x << " y: " << y << " value: " << (int)v[0] << " " << (int)v[1] << " " << (int)v[2] << " " << endl;
}
else
{
Vec4b v = image.at<Vec4b>(y, x);
cout << "x: " << x << " y: " << y << " value: " << (int)v[0] << " " << (int)v[1] << " " << (int)v[2] << " " << (int)v[3] << endl;
}
}
int main() { namedWindow(window_name, CV_WINDOW_NORMAL); image = imread("C:/Users/Public/Pictures/Sample Pictures/video.png",CV_LOAD_IMAGE_UNCHANGED); cout<<image.depth()<<" "<<image.channels()<<"\n";="" imshow(window_name,="" image);="" setmousecallback(window_name,="" onmouse,="" 0);="" waitkey(0);="" return="" 0;="" }<="" p="">
2 | No.2 Revision |
Your program is false. You don't have intensityin your file except for black and white image (luminance). You can have (generally) a color R,G,B or R,G,B alpha for png file.... You must check depth of your image and type before give pixel value....
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <highgui.h>
using namespace cv;
using namespace
3 | No.3 Revision |
Your program is false. You don't have intensityin your file except for black and white image (luminance). You can have (generally) a color R,G,B or R,G,B alpha for png file.... You must check depth of your image and type before give pixel value....value....
Something like this but you improve for black and white images....
#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*){
if (image.channels()==3)
{
Vec3b v= image.at<Vec3b>(y,x);
cout << "x: " << x << " y: " << y << " value: " << (int)v[0] << " " << (int)v[1] << " " << (int)v[2] << " " << endl;
}
else
else if(image.channels()==4)
{
Vec4b v = image.at<Vec4b>(y, x);
cout << "x: " << x << " y: " << y << " value: " << (int)v[0] << " " << (int)v[1] << " " << (int)v[2] << " " << (int)v[3] << endl;
}
}
int main() {
namedWindow(window_name, CV_WINDOW_NORMAL);
image = imread("C:/Users/Public/Pictures/Sample Pictures/video.png",CV_LOAD_IMAGE_UNCHANGED);
cout<<image.depth()<<" "<<image.channels()<<"\n";
imshow(window_name, image);
setMouseCallback(window_name, onMouse, 0);
waitKey(0);
return 0;
}
4 | No.4 Revision |
Your program is false. You don't have intensityin your file except for black and white image (luminance). You can have (generally) a color R,G,B colorB,G,R or R,G,B alpha for png file.... You must check depth of your image and type before give pixel value....
Something like this but you improve for black and white images....
#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*){
if (image.channels()==3)
{
Vec3b v= image.at<Vec3b>(y,x);
cout << "x: " << x << " y: " << y << " value: " << (int)v[0] << " " << (int)v[1] << " " << (int)v[2] << " " << endl;
}
else if(image.channels()==4)
{
Vec4b v = image.at<Vec4b>(y, x);
cout << "x: " << x << " y: " << y << " value: " << (int)v[0] << " " << (int)v[1] << " " << (int)v[2] << " " << (int)v[3] << endl;
}
}
int main() {
namedWindow(window_name, CV_WINDOW_NORMAL);
image = imread("C:/Users/Public/Pictures/Sample Pictures/video.png",CV_LOAD_IMAGE_UNCHANGED);
cout<<image.depth()<<" "<<image.channels()<<"\n";
imshow(window_name, image);
setMouseCallback(window_name, onMouse, 0);
waitKey(0);
return 0;
}