大家好,我正在尝试使用 C++ openCV 2.4.5 获取图像中像素的 RGB
但是当我编译时出现此错误。
它会加载图像,但是当我尝试获取像素的 RGB 时会出现异常
有人能帮帮我吗?
以下代码加载图像并在索引 25,4 处找到像素的 RGB
我的代码是:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
int x;
Mat input = imread("C:/red.jpg");
if (input.empty())
{
std::cout << "!!! Failed imread(): image not found" << std::endl;
cin>>x;
return 0;
// don't let the execution continue, else imshow() will crash.
}
imshow("input", input);
Vec3f pixel = input.at<Vec3f>(25, 40);
if( !pixel[0])
{
std::cout << "!!! Failed pixel(): image not found" << std::endl;
cin>>x;
return 0;
}
int b = pixel[0];
int g = pixel[1];
int r = pixel[2];
cout<<b;
cout <<" ";
cout<<r;
cout <<" ";
cout <<g;
cin>>b;
/*
// detect squares after filtering...
*/
return 0;
}