-2
我使用以下代碼閱讀一個圖象並在屏幕上顯示的像素值像素值不能被讀爲更小的圖像,但可以讀取圖片放大
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("C:\\cat.jpg", CV_LOAD_IMAGE_COLOR); //open and read the image
if (img.empty())
{
cout << "Image cannot be loaded..!!" << endl;
return -1;
}
cvtColor(img, img, CV_BGR2GRAY); //change the color image to grayscale image
int rows = img.rows;
int cols =img.cols;
cv::Size s = img.size();
rows = s.height;
cols = s.width;
// this loop is to get all the pixel values
uchar val;
for(int r=0;r<rows;r++)
{
for(int c=0;c<cols;c++)
{
val = img.at<uchar>(r,c);
cout << (int)val <<" ";
}
cout<<endl;
}
// to get a single value of pixelu need a variable
val = img.at<uchar>(40,50);
cout << (int)val << endl;
imshow("showImg",img);
cvWaitKey(0);
return 1;
waitKey(0); //wait for key press
destroyAllWindows(); //destroy all open windows
return 0;
}
//正常工作放大圖像,但是當我使用8x8 .jpg或.tiff圖像顯示/ /圖像,而不是像素值,並給出錯誤
//「opencvconfig.exe中的0x75c7c41f(KernelBase.dll)未處理的異常:Microsoft C++ // exception: cv ::內存位置0x0030f354處的異常..「
// th是顯示錯誤可以在任何1,請幫助,我希望儘快posssible
可能由'img.at(40,50)'訪問boondocks中的某處引起。 –
Bull