Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV使用鼠标访问像素值_Opencv - Fatal编程技术网

OpenCV使用鼠标访问像素值

OpenCV使用鼠标访问像素值,opencv,Opencv,有人能说出下面的代码有什么问题吗。当鼠标移动图像的最后一部分时,我遇到了分割错误。我只是根据鼠标位置打印R,G,B值 #include <iostream> #include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; using namespace std; Mat image; char window_name[20]="Pixel Value Demo"; static

有人能说出下面的代码有什么问题吗。当鼠标移动图像的最后一部分时,我遇到了分割错误。我只是根据鼠标位置打印R,G,B值

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

using namespace cv;
using namespace std;
 Mat image;
 char window_name[20]="Pixel Value Demo";

static void onMouse( int event, int x, int y, int f, void* ){

 Vec3b pix=image.at<Vec3b>(x,y);
 int B=pix.val[0];
 int G=pix.val[1];
 int R=pix.val[2];
 cout<<R<<endl<<G<<endl<<B<<endl;

}



int main( int argc, char** argv )
{
  namedWindow( window_name, CV_WINDOW_AUTOSIZE );
  image = imread( "src.jpg");
  imshow( window_name, image );    
  setMouseCallback( window_name, onMouse, 0 );
  waitKey(0);
  return 0;
}
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
Mat图像;
char window_name[20]=“像素值演示”;
鼠标上的静态void(int事件、int x、int y、int f、void*){
Vec3b pix=图像在(x,y)处;
intb=pix.val[0];
int G=pix.val[1];
int R=pix.val[2];
cout
Vec3b pix=image.at(x,y);
应该是:

Vec3b pix=image.at<Vec3b>(y,x);  // row,col !!
Vec3b pix=image.at(y,x);//行,列!!
Vec3b pix=image.at<Vec3b>(y,x);  // row,col !!